Skip to content

Commit

Permalink
Merge branch 'develop' into fix/advanced-test-liquidity
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Apr 23, 2024
2 parents 75f1f0d + a124ffb commit 36ff4f6
Show file tree
Hide file tree
Showing 195 changed files with 7,756 additions and 876 deletions.
5 changes: 3 additions & 2 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM golang:1.20-alpine3.18
ENV GOPATH /go
ENV GOOS=linux
ENV CGO_ENABLED=1
ENV GOCACHE=/root/.cache/go-build

RUN apk --no-cache add git make build-base jq openssh libusb-dev linux-headers bash curl tmux python3 py3-pip
RUN pip install requests
Expand All @@ -14,8 +15,8 @@ COPY go.sum .
RUN go mod download
COPY . .

RUN make install
RUN make install-zetae2e
RUN --mount=type=cache,target="/root/.cache/go-build" make install
RUN --mount=type=cache,target="/root/.cache/go-build" make install-zetae2e

RUN ssh-keygen -A
WORKDIR /root
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ TEST_DIR?="./..."
TEST_BUILD_FLAGS := -tags pebbledb,ledger
HSM_BUILD_FLAGS := -tags pebbledb,ledger,hsm_test

export DOCKER_BUILDKIT := 1

clean: clean-binaries clean-dir clean-test-dir clean-coverage

clean-binaries:
Expand Down
10 changes: 5 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmlog "github.com/tendermint/tendermint/libs/log"
cctxtypes "github.com/zeta-chain/zetacore/x/crosschain/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

Expand Down Expand Up @@ -168,10 +168,10 @@ func IsSystemTx(tx sdk.Tx, isAuthorizedSigner func(string) bool) bool {
}
}
switch innerMsg.(type) {
case *cctxtypes.MsgVoteGasPrice,
*cctxtypes.MsgVoteOnObservedInboundTx,
*cctxtypes.MsgVoteOnObservedOutboundTx,
*cctxtypes.MsgAddToOutTxTracker,
case *crosschaintypes.MsgVoteGasPrice,
*crosschaintypes.MsgVoteOnObservedInboundTx,
*crosschaintypes.MsgVoteOnObservedOutboundTx,
*crosschaintypes.MsgAddToOutTxTracker,
*observertypes.MsgVoteBlockHeader,
*observertypes.MsgVoteTSS,
*observertypes.MsgAddBlameVote:
Expand Down
25 changes: 1 addition & 24 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,30 +591,7 @@ func New(
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
// NOTE: Cross-chain module must be initialized after observer module, as pending nonces in crosschain needs the tss pubkey from observer module
app.mm.SetOrderInitGenesis(
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
evmtypes.ModuleName,
feemarkettypes.ModuleName,
paramstypes.ModuleName,
group.ModuleName,
genutiltypes.ModuleName,
upgradetypes.ModuleName,
evidencetypes.ModuleName,
vestingtypes.ModuleName,
observertypes.ModuleName,
crosschaintypes.ModuleName,
fungibletypes.ModuleName,
emissionstypes.ModuleName,
authz.ModuleName,
authoritytypes.ModuleName,
lightclienttypes.ModuleName,
)
app.mm.SetOrderInitGenesis(InitGenesisModuleList()...)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
Expand Down
53 changes: 53 additions & 0 deletions app/init_genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package app

import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/group"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"
fungibleModuleTypes "github.com/zeta-chain/zetacore/x/fungible/types"
lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func InitGenesisModuleList() []string {
return []string{
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
evmtypes.ModuleName,
feemarkettypes.ModuleName,
paramstypes.ModuleName,
group.ModuleName,
genutiltypes.ModuleName,
upgradetypes.ModuleName,
evidencetypes.ModuleName,
vestingtypes.ModuleName,
observertypes.ModuleName,
crosschaintypes.ModuleName,
fungibleModuleTypes.ModuleName,
emissionsModuleTypes.ModuleName,
authz.ModuleName,
authoritytypes.ModuleName,
lightclienttypes.ModuleName,
}
}
2 changes: 1 addition & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const releaseVersion = "v15"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + releaseVersion)
// Updated version map to the latest consensus versions from each module
for m, mb := range app.mm.Modules {
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* [2001](https://github.com/zeta-chain/node/pull/2001) - replace broadcast mode block with sync and remove fungible params
* [1989](https://github.com/zeta-chain/node/pull/1989) - simplify `IsSendOutTxProcessed` method and add unit tests
* [2013](https://github.com/zeta-chain/node/pull/2013) - rename `GasPriceVoter` message to `VoteGasPrice`
* [2059](https://github.com/zeta-chain/node/pull/2059) - Remove unused params from all functions in zetanode

### Features

Expand All @@ -52,7 +53,11 @@
* [1942](https://github.com/zeta-chain/node/pull/1982) - support Bitcoin P2TR, P2WSH, P2SH, P2PKH addresses
* [1935](https://github.com/zeta-chain/node/pull/1935) - add an operational authority group
* [1954](https://github.com/zeta-chain/node/pull/1954) - add metric for concurrent keysigns
* [1979](https://github.com/zeta-chain/node/pull/1979) - add script to import genesis data into an existing genesis file
* [2006](https://github.com/zeta-chain/node/pull/2006) - add Amoy testnet static chain information
* [2045](https://github.com/zeta-chain/node/pull/2046) - add grpc query with outbound rate limit for zetaclient to use
* [2046](https://github.com/zeta-chain/node/pull/2046) - add state variable in crosschain for rate limiter flags
* [2034](https://github.com/zeta-chain/node/pull/2034) - add support for zEVM message passing

### Tests

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func DebugCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get-ballot-from-intx [txHash] [chainID]",
Short: "provide txHash and chainID to get the ballot status for the txHash",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
cobra.ExactArgs(2)
cfg, err := config.Load(debugArgs.zetaCoreHome)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetacored/addr_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ it always outputs three lines; the first line is the zeta1xxx address, the secon
and the third line is the ethereum address.
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
addr, err := sdk.AccAddressFromBech32(args[0])
if err == nil {
valAddr := sdk.ValAddress(addr.Bytes())
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetacored/collect_observer_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func CollectObserverInfoCmd() *cobra.Command {
Use: "collect-observer-info [folder]",
Short: "collect observer info from a folder , default path is ~/.zetacored/os_info/ \n",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
defaultHome := app.DefaultNodeHome
defaultFile := filepath.Join(defaultHome, "os_info")
if len(args) == 0 {
Expand Down
202 changes: 202 additions & 0 deletions cmd/zetacored/parse_genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package main

import (
"encoding/json"
"fmt"
"os"
"path/filepath"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/group"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
"github.com/zeta-chain/zetacore/app"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const MaxItemsForList = 10

// Copy represents a set of modules for which, the entire state is copied without any modifications
var Copy = map[string]bool{
slashingtypes.ModuleName: true,
govtypes.ModuleName: true,
crisistypes.ModuleName: true,
feemarkettypes.ModuleName: true,
paramstypes.ModuleName: true,
upgradetypes.ModuleName: true,
evidencetypes.ModuleName: true,
vestingtypes.ModuleName: true,
fungibletypes.ModuleName: true,
emissionstypes.ModuleName: true,
authz.ModuleName: true,
}

// Skip represents a set of modules for which, the entire state is skipped and nothing gets imported
var Skip = map[string]bool{
evmtypes.ModuleName: true,
stakingtypes.ModuleName: true,
genutiltypes.ModuleName: true,
authtypes.ModuleName: true,
banktypes.ModuleName: true,
distributiontypes.ModuleName: true,
group.ModuleName: true,
}

// Modify represents a set of modules for which, the state is modified before importing. Each Module should have a corresponding Modify function
var Modify = map[string]bool{
crosschaintypes.ModuleName: true,
observertypes.ModuleName: true,
}

func CmdParseGenesisFile() *cobra.Command {
cmd := &cobra.Command{
Use: "parse-genesis-file [import-genesis-file] [optional-genesis-file]",
Short: "Parse the provided genesis file and import the required data into the optionally provided genesis file",
Args: cobra.MaximumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec
genesisFilePath := filepath.Join(app.DefaultNodeHome, "config", "genesis.json")
if len(args) == 2 {
genesisFilePath = args[1]
}
genDoc, err := GetGenDoc(genesisFilePath)
if err != nil {
return err
}
importData, err := GetGenDoc(args[0])
if err != nil {
return err
}
err = ImportDataIntoFile(genDoc, importData, cdc)
if err != nil {
return err
}

err = genutil.ExportGenesisFile(genDoc, genesisFilePath)
if err != nil {
return err
}

return nil
},
}
return cmd
}

func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, cdc codec.Codec) error {

appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc)
if err != nil {
return err
}
importAppState, err := genutiltypes.GenesisStateFromGenDoc(*importFile)
if err != nil {
return err
}
moduleList := app.InitGenesisModuleList()
for _, m := range moduleList {
if Skip[m] {
continue
}
if Copy[m] {
appState[m] = importAppState[m]
}
if Modify[m] {
switch m {
case crosschaintypes.ModuleName:
err := ModifyCrosschainState(appState, importAppState, cdc)
if err != nil {
return err
}
case observertypes.ModuleName:
err := ModifyObserverState(appState, importAppState, cdc)
if err != nil {
return err
}
default:
return fmt.Errorf("modify function for %s not found", m)
}
}
}

appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
}
genDoc.AppState = appStateJSON

return nil
}

// ModifyCrosschainState modifies the crosschain state before importing
// It truncates the crosschain transactions, inbound transactions and finalized inbounds to MaxItemsForList
func ModifyCrosschainState(appState map[string]json.RawMessage, importAppState map[string]json.RawMessage, cdc codec.Codec) error {
importedCrossChainGenState := crosschaintypes.GetGenesisStateFromAppState(cdc, importAppState)
importedCrossChainGenState.CrossChainTxs = importedCrossChainGenState.CrossChainTxs[:math.Min(MaxItemsForList, len(importedCrossChainGenState.CrossChainTxs))]
importedCrossChainGenState.InTxHashToCctxList = importedCrossChainGenState.InTxHashToCctxList[:math.Min(MaxItemsForList, len(importedCrossChainGenState.InTxHashToCctxList))]
importedCrossChainGenState.FinalizedInbounds = importedCrossChainGenState.FinalizedInbounds[:math.Min(MaxItemsForList, len(importedCrossChainGenState.FinalizedInbounds))]
importedCrossChainStateBz, err := json.Marshal(importedCrossChainGenState)
if err != nil {
return fmt.Errorf("failed to marshal zetacrosschain genesis state: %w", err)
}
appState[crosschaintypes.ModuleName] = importedCrossChainStateBz
return nil
}

// ModifyObserverState modifies the observer state before importing
// It truncates the ballots and nonce to cctx list to MaxItemsForList
func ModifyObserverState(appState map[string]json.RawMessage, importAppState map[string]json.RawMessage, cdc codec.Codec) error {
importedObserverGenState := observertypes.GetGenesisStateFromAppState(cdc, importAppState)
importedObserverGenState.Ballots = importedObserverGenState.Ballots[:math.Min(MaxItemsForList, len(importedObserverGenState.Ballots))]
importedObserverGenState.NonceToCctx = importedObserverGenState.NonceToCctx[:math.Min(MaxItemsForList, len(importedObserverGenState.NonceToCctx))]

currentGenState := observertypes.GetGenesisStateFromAppState(cdc, appState)
currentGenState.Ballots = importedObserverGenState.Ballots
currentGenState.NonceToCctx = importedObserverGenState.NonceToCctx

currentGenStateBz, err := cdc.MarshalJSON(&currentGenState)
if err != nil {
return fmt.Errorf("failed to marshal observer genesis state: %w", err)
}

appState[observertypes.ModuleName] = currentGenStateBz
return nil
}

func GetGenDoc(fp string) (*types.GenesisDoc, error) {
path, err := filepath.Abs(fp)
if err != nil {
return nil, err
}
jsonBlob, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return nil, err
}
genData, err := types.GenesisDocFromJSON(jsonBlob)
if err != nil {
return nil, err
}
return genData, nil
}
Loading

0 comments on commit 36ff4f6

Please sign in to comment.