Skip to content

Commit

Permalink
Merge pull request #1229 from maticnetwork/v1.1.0-beta-candidate
Browse files Browse the repository at this point in the history
Merge v1.1.0 beta candidate
  • Loading branch information
Raneet10 authored Jan 29, 2025
2 parents 632feca + 32e8586 commit a59d210
Show file tree
Hide file tree
Showing 61 changed files with 4,059 additions and 1,870 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/amoy_deb_profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ jobs:
run: cp -rp packaging/templates/package_scripts/preinst.${{ env.NETWORK }} packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/DEBIAN/preinst
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: amoy
- name: Copying config for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/config/${{ env.NETWORK }}/heimdall-config.toml packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/var/lib/heimdall/config/heimdall-config.toml
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: amoy
- name: Copying config for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/config/${{ env.NETWORK }}/config.toml packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/var/lib/heimdall/config/config.toml
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: amoy
- name: Copying systemd file for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/systemd/heimdalld-amoy-validator.service packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/lib/systemd/system/heimdalld.service
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/mainnet_deb_profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ jobs:
run: cp -rp packaging/templates/package_scripts/preinst.${{ env.NETWORK }} packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/DEBIAN/preinst
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: mainnet
- name: Copying config for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/config/${{ env.NETWORK }}/heimdall-config.toml packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/var/lib/heimdall/config/heimdall-config.toml
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: mainnet
- name: Copying config for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/config/${{ env.NETWORK }}/config.toml packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/var/lib/heimdall/config/config.toml
env:
ARCH: all
NODE: sentry
NODE: validator
NETWORK: mainnet
- name: Copying the postrm for ${{ env.NODE }} on ${{ env.NETWORK }} on ${{ env.ARCH }}
run: cp -rp packaging/templates/package_scripts/postrm.profile packaging/deb/heimdall-${{ env.NETWORK }}-${{ env.NODE }}-config_${{ env.GIT_TAG }}-${{ env.ARCH }}/DEBIAN/postrm
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean:
tests:
# go test -v ./...

go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ -cover -coverprofile=cover.out -parallel 1
go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ ./gov/ -cover -coverprofile=cover.out -parallel 1

# make build
build: clean
Expand Down
10 changes: 7 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ func NewHeimdallApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
config := sdk.GetConfig()
config.Seal()

var app *HeimdallApp

// base app
bApp := bam.NewBaseApp(AppName, logger, db, authTypes.DefaultTxDecoder(cdc), baseAppOptions...)
bApp := bam.NewBaseApp(AppName, logger, db, authTypes.DefaultMainTxDecoder(cdc, func() int64 {
return app.LastBlockHeight()
}, helper.GetDanelawHeight, helper.GetJorvikHeight), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(nil)
bApp.SetAppVersion(version.Version)

Expand All @@ -217,7 +221,7 @@ func NewHeimdallApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
tkeys := sdk.NewTransientStoreKeys(paramsTypes.TStoreKey)

// create heimdall app
var app = &HeimdallApp{
app = &HeimdallApp{
cdc: cdc,
BaseApp: bApp,
keys: keys,
Expand Down Expand Up @@ -357,7 +361,7 @@ func NewHeimdallApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
common.DefaultCodespace,
app.ChainKeeper,
app.StakingKeeper,
app.caller,
&app.caller,
)

app.ClerkKeeper = clerk.NewKeeper(
Expand Down
4 changes: 2 additions & 2 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Fees serve two purposes for an operator of the network.

Fees limit the growth of the state stored by every full node and allow for general purpose censorship of transactions of little economic value. Fees are best suited as an anti-spam mechanism where validators are disinterested in the use of the network and identities of users.

Since Heimdall doesn't support custom contract or code for any transaction, it uses fixed cost transactions. For fixed cost transactions, the validator can top up their accounts on the Ethereum chain and get tokens on Heimdall using the Topup module.
Since Heimdall doesn't support custom contracts or code for any transaction, it uses fixed cost transactions. For fixed cost transactions, the validator can top up their accounts on the Ethereum chain and get tokens on Heimdall using the Topup module.

### Types

Besides accounts (specified in State), the types exposed by the auth module are StdSignature, the combination of an optional public key and a cryptographic signature as a byte array, StdTx, a struct that implements the sdk.Tx interface using StdSignature, and StdSignDoc, a replay-prevention structure for StdTx which transaction senders must sign over.

#### StdSignature

A StdSignature is the types of a byte array.
A StdSignature is the type of a byte array.
```
// StdSignature represents a sig
type StdSignature []byte
Expand Down
35 changes: 35 additions & 0 deletions auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,41 @@ func (fee StdFee) GasPrices() sdk.DecCoins {
// Decoders
//

// DefaultMainTxDecoder logic for standard transaction decoding
func DefaultMainTxDecoder(cdc *codec.Codec, lastBlockHeight func() int64, getDanelawHeight func() int64, getJorvikHeight func() int64) sdk.TxDecoder {
return func(txBytes []byte) (sdk.Tx, sdk.Error) {
var tx = StdTx{}

if len(txBytes) == 0 {
return nil, sdk.ErrTxDecode("txBytes are empty")
}

currentHeight := lastBlockHeight() + 1
if currentHeight < getDanelawHeight() && getDanelawHeight() == getJorvikHeight() {
var hftx = StdTx{}
if err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &hftx); err != nil {
return nil, sdk.ErrTxDecode("error decoding transaction").TraceSDK(err.Error())
}

msgs := hftx.GetMsgs()
for _, msg := range msgs {
if msg.Route() == "bor" && msg.Type() == "propose-span-v2" {
return nil, sdk.ErrTxDecode("error decoding transaction")
}
}
}

// StdTx.Msg is an interface. The concrete types
// are registered by MakeTxCodec
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {
return nil, sdk.ErrTxDecode("error decoding transaction").TraceSDK(err.Error())
}

return tx, nil
}
}

// DefaultTxDecoder logic for standard transaction decoding
func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder {
return func(txBytes []byte) (sdk.Tx, sdk.Error) {
Expand Down
4 changes: 2 additions & 2 deletions bor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

## Overview

The validators on bor chain produce blocks in sprints and spans. Hence, it is imperative for the protocol to formalise the validators who will be producers in a range of blocks (`span`). The `bor` module in heimdall facilitates this by pseudo-randomly selecting validators who will producing blocks (producers) from the current validator set. The bor chain fetches and persists this information before the next span begins. `bor` module is a crucial component in heimdall since the PoS chain "liveness" depends on it.
The validators on bor chain produce blocks in sprints and spans. Hence, it is imperative for the protocol to formalise the validators who will be producers in a range of blocks (`span`). The `bor` module in heimdall facilitates this by pseudo-randomly selecting validators who will be producing blocks (producers) from the current validator set. The bor chain fetches and persists this information before the next span begins. `bor` module is a crucial component in heimdall since the PoS chain "liveness" depends on it.

## How does it work

Expand Down Expand Up @@ -162,4 +162,4 @@ curl localhost:1317/bor/next-span-seed

```
curl "localhost:1317/bor/prepare-next-span?span_id=<SPAN_ID>&start_block=<BOR_START_BLOCK>&chain_id="<BOR_CHAIN_ID>""
```
```
91 changes: 70 additions & 21 deletions bor/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/ethereum/go-ethereum/common"

"github.com/maticnetwork/heimdall/bor/types"
hmClient "github.com/maticnetwork/heimdall/client"
"github.com/maticnetwork/heimdall/helper"
Expand Down Expand Up @@ -223,14 +221,28 @@ func GetSpanList(cdc *codec.Codec) *cobra.Command {

// GetNextSpanSeed implements the next span seed.
func GetNextSpanSeed(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "next-span-seed",
Args: cobra.NoArgs,
Short: "show the next span seed",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
spanIDStr := viper.GetString(FlagSpanId)
if spanIDStr == "" {
return fmt.Errorf("span id cannot be empty")
}

spanID, err := strconv.ParseUint(spanIDStr, 10, 64)
if err != nil {
return err
}

seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {

fmt.Println("Error while fetching the span seed")
Expand All @@ -247,9 +259,17 @@ func GetNextSpanSeed(cdc *codec.Codec) *cobra.Command {

},
}

cmd.Flags().String(FlagSpanId, "", "--span-id=<span-id>")

if err := cmd.MarkFlagRequired(FlagSpanId); err != nil {
cliLogger.Error("GetNextSpanSeed | MarkFlagRequired | FlagSpanId", "Error", err)
}

return cmd
}

// PostSendProposeSpanTx send propose span transaction
// GetPreparedProposeSpan generates a propose span transaction
func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "propose-span",
Expand Down Expand Up @@ -291,6 +311,11 @@ func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {
return err
}

nodeStatus, err := helper.GetNodeStatus(cliCtx)
if err != nil {
return err
}

//
// Query data
//
Expand All @@ -309,7 +334,12 @@ func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
return err
}
Expand All @@ -318,23 +348,42 @@ func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {
return errors.New("next span seed not found")
}

var seed common.Hash
if err := jsoniter.Unmarshal(res, &seed); err != nil {
var seedResponse types.QuerySpanSeedResponse
if err := jsoniter.Unmarshal(res, &seedResponse); err != nil {
return err
}

msg := types.NewMsgProposeSpan(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seed,
)

result, err := jsoniter.Marshal(&msg)
if err != nil {
return err
var result []byte

if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
msg := types.NewMsgProposeSpan(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seedResponse.Seed,
)

result, err = jsoniter.Marshal(&msg)
if err != nil {
return err
}
} else {
msg := types.NewMsgProposeSpanV2(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seedResponse.Seed,
seedResponse.SeedAuthor,
)

result, err = jsoniter.Marshal(&msg)
if err != nil {
return err
}
}

fmt.Println(string(result))
Expand Down
47 changes: 34 additions & 13 deletions bor/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/ethereum/go-ethereum/common"

"github.com/maticnetwork/heimdall/bor/types"
hmClient "github.com/maticnetwork/heimdall/client"
"github.com/maticnetwork/heimdall/helper"
Expand Down Expand Up @@ -84,6 +82,11 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
return err
}

nodeStatus, err := helper.GetNodeStatus(cliCtx)
if err != nil {
return err
}

//
// Query data
//
Expand All @@ -102,7 +105,12 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
return err
}
Expand All @@ -111,19 +119,32 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
return errors.New("next span seed not found")
}

var seed common.Hash
if err := jsoniter.ConfigFastest.Unmarshal(res, &seed); err != nil {
var seedResponse types.QuerySpanSeedResponse
if err := jsoniter.ConfigFastest.Unmarshal(res, &seedResponse); err != nil {
return err
}

msg := types.NewMsgProposeSpan(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seed,
)
var msg sdk.Msg
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
msg = types.NewMsgProposeSpan(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seedResponse.Seed,
)
} else {
msg = types.NewMsgProposeSpanV2(
spanID,
proposer,
startBlock,
startBlock+spanDuration-1,
borChainID,
seedResponse.Seed,
seedResponse.SeedAuthor,
)
}

return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg})
},
Expand Down
Loading

0 comments on commit a59d210

Please sign in to comment.