Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/zeta-chain/node into ref…
Browse files Browse the repository at this point in the history
…actor-integrate-base-observer
  • Loading branch information
ws4charlie committed Jun 21, 2024
2 parents 625e633 + f9ca2be commit df1dcbe
Show file tree
Hide file tree
Showing 123 changed files with 1,938 additions and 1,539 deletions.
5 changes: 3 additions & 2 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ RUN mkdir -p /root/.zetacored/cosmovisor/genesis/bin && \
ENV PATH /root/.zetacored/cosmovisor/current/bin/:/root/.zetaclientd/upgrades/current/:${PATH}

COPY contrib/localnet/scripts /root
COPY contrib/localnet/ssh_config /root/.ssh/config
COPY contrib/localnet/ssh_config /etc/ssh/ssh_config.d/localnet.conf
COPY contrib/localnet/zetacored /root/zetacored

RUN chmod 755 /root/*.sh
RUN chmod 755 /root/*.sh && \
chmod 644 /etc/ssh/ssh_config.d/localnet.conf

WORKDIR /usr/local/bin
EXPOSE 22
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ start-localnet-skip-build:
cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-setup-only.yml up -d

stop-localnet:
start-e2e-import-mainnet-test: zetanode
@echo "--> Starting e2e import-data test"
cd contrib/localnet/ && ./scripts/import-data.sh mainnet && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d

stop-test:
cd contrib/localnet/ && $(DOCKER) compose down --remove-orphans

###############################################################################
Expand Down
9 changes: 0 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ import (

"github.com/zeta-chain/zetacore/app/ante"
"github.com/zeta-chain/zetacore/docs/openapi"
"github.com/zeta-chain/zetacore/pkg/chains"
zetamempool "github.com/zeta-chain/zetacore/pkg/mempool"
srvflags "github.com/zeta-chain/zetacore/server/flags"
authoritymodule "github.com/zeta-chain/zetacore/x/authority"
Expand Down Expand Up @@ -598,14 +597,6 @@ func New(
app.LightclientKeeper,
)

// initializing map of cctx gateways so crosschain module can decide which one to use
// based on chain info of destination chain
cctxGateways := map[chains.CCTXGateway]crosschainkeeper.CCTXGateway{
chains.CCTXGateway_observers: crosschainkeeper.NewCCTXGatewayObservers(app.CrosschainKeeper),
chains.CCTXGateway_zevm: crosschainkeeper.NewCCTXGatewayZEVM(app.CrosschainKeeper),
}
app.CrosschainKeeper.SetCCTXGateways(cctxGateways)

// initialize ibccrosschain keeper and set it to the crosschain keeper
// there is a circular dependency between the two keepers, crosschain keeper must be initialized first

Expand Down
124 changes: 64 additions & 60 deletions changelog.md

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions cmd/zetaclientd/gen_pre_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/binance-chain/tss-lib/ecdsa/keygen"
"github.com/spf13/cobra"
)

func init() {
RootCmd.AddCommand(GenPrePramsCmd)
}

var GenPrePramsCmd = &cobra.Command{
Use: "gen-pre-params <path>",
Short: "Generate pre parameters for TSS",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
startTime := time.Now()
preParams, err := keygen.GeneratePreParams(time.Second * 300)
if err != nil {
return err
}

file, err := os.OpenFile(args[0], os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
defer file.Close()
err = json.NewEncoder(file).Encode(preParams)
if err != nil {
return err
}
fmt.Printf("Generated new pre-parameters in %v\n", time.Since(startTime))
return nil
},
}
46 changes: 34 additions & 12 deletions cmd/zetacored/parse_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ 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,
Expand All @@ -50,24 +49,37 @@ var Copy = map[string]bool{
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,
// Skipping evm this is done to reduce the size of the genesis file evm module uses the majority of the space due to smart contract data
evmtypes.ModuleName: true,
// Skipping staking as new validators would be created for the new chain
stakingtypes.ModuleName: true,
// Skipping genutil as new gentxs would be created
genutiltypes.ModuleName: true,
// Skipping auth as new accounts would be created for the new chain. This also needs to be done as we are skipping evm module
authtypes.ModuleName: true,
// Skipping bank module as it is not used when starting a new chain this is done to make sure the total supply invariant is maintained.
// This would need modification but might be possible to add in non evm based modules in the future
banktypes.ModuleName: true,
// Skipping distribution module as it is not used when starting a new chain , rewards are based on validators and delegators , and so rewards from a different chain do not hold any value
distributiontypes.ModuleName: true,
group.ModuleName: true,
// Skipping group module as it is not used when starting a new chain, new groups should be created based on the validator operator keys
group.ModuleName: true,
// Skipping authz as it is not used when starting a new chain, new grants should be created based on the validator hotkeys abd operator keys
authz.ModuleName: true,
// Skipping fungible module as new fungible tokens would be created and system contract would be deployed
fungibletypes.ModuleName: true,
// Skipping gov types as new parameters are set for the new chain
govtypes.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,
crosschaintypes.ModuleName: true,
}

func CmdParseGenesisFile() *cobra.Command {
Expand All @@ -78,6 +90,10 @@ func CmdParseGenesisFile() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec
modifyEnabled, err := cmd.Flags().GetBool("modify")
if err != nil {
return err
}
genesisFilePath := filepath.Join(app.DefaultNodeHome, "config", "genesis.json")
if len(args) == 2 {
genesisFilePath = args[1]
Expand All @@ -90,7 +106,7 @@ func CmdParseGenesisFile() *cobra.Command {
if err != nil {
return err
}
err = ImportDataIntoFile(genDoc, importData, cdc)
err = ImportDataIntoFile(genDoc, importData, cdc, modifyEnabled)
if err != nil {
return err
}
Expand All @@ -103,10 +119,16 @@ func CmdParseGenesisFile() *cobra.Command {
return nil
},
}
cmd.PersistentFlags().Bool("modify", false, "Modify the genesis file before importing")
return cmd
}

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

appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc)
if err != nil {
Expand All @@ -124,7 +146,7 @@ func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc,
if Copy[m] {
appState[m] = importAppState[m]
}
if Modify[m] {
if Modify[m] && modifyEnabled {
switch m {
case crosschaintypes.ModuleName:
err := ModifyCrosschainState(appState, importAppState, cdc)
Expand Down
103 changes: 73 additions & 30 deletions cmd/zetacored/parse_genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,43 +92,86 @@ func Test_ModifyObserverState(t *testing.T) {
}

func Test_ImportDataIntoFile(t *testing.T) {
setConfig(t)
cdc := keepertest.NewCodec()
genDoc := sample.GenDoc(t)
importGenDoc := ImportGenDoc(t, cdc, 100)
t.Run("successfully import data into file and modify data", func(t *testing.T) {
setConfig(t)
cdc := keepertest.NewCodec()
genDoc := sample.GenDoc(t)
importGenDoc := ImportGenDoc(t, cdc, 100)

err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc)
require.NoError(t, err)
err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc, true)
require.NoError(t, err)

appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc)
require.NoError(t, err)
appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc)
require.NoError(t, err)

// Crosschain module is in Modify list
crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState)
require.Len(t, crosschainStateAfterImport.CrossChainTxs, zetacored.MaxItemsForList)
require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, zetacored.MaxItemsForList)
require.Len(t, crosschainStateAfterImport.FinalizedInbounds, zetacored.MaxItemsForList)
// Crosschain module is in Modify list
crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState)
require.Len(t, crosschainStateAfterImport.CrossChainTxs, zetacored.MaxItemsForList)
require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, zetacored.MaxItemsForList)
require.Len(t, crosschainStateAfterImport.FinalizedInbounds, zetacored.MaxItemsForList)

// Bank module is in Skip list
var bankStateAfterImport banktypes.GenesisState
if appState[banktypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
// Bank module is in Skip list
var bankStateAfterImport banktypes.GenesisState
if appState[banktypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
}
}
}
// 4 balances were present in the original genesis state
require.Len(t, bankStateAfterImport.Balances, 4)
// 4 balances were present in the original genesis state
require.Len(t, bankStateAfterImport.Balances, 4)

// Emissions module is in Copy list
var emissionStateAfterImport emissionstypes.GenesisState
if appState[emissionstypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
// Emissions module is in Copy list
var emissionStateAfterImport emissionstypes.GenesisState
if appState[emissionstypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
}
}
}
require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 100)
require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 100)
})

t.Run("successfully import data into file without modifying data", func(t *testing.T) {
setConfig(t)
cdc := keepertest.NewCodec()
genDoc := sample.GenDoc(t)
importGenDoc := ImportGenDoc(t, cdc, 8)

err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc, false)
require.NoError(t, err)

appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc)
require.NoError(t, err)

// Crosschain module is in Modify list
crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState)
require.Len(t, crosschainStateAfterImport.CrossChainTxs, 0)
require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, 0)
require.Len(t, crosschainStateAfterImport.FinalizedInbounds, 0)

// Bank module is in Skip list
var bankStateAfterImport banktypes.GenesisState
if appState[banktypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
}
}
// 4 balances were present in the original genesis state
require.Len(t, bankStateAfterImport.Balances, 4)

// Emissions module is in Copy list
var emissionStateAfterImport emissionstypes.GenesisState
if appState[emissionstypes.ModuleName] != nil {
err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport)
if err != nil {
panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error()))
}
}
require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 8)

})
}

func Test_GetGenDoc(t *testing.T) {
Expand Down
32 changes: 19 additions & 13 deletions cmd/zetacored/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"os"
"testing"

"github.com/cometbft/cometbft/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestParsefileToObserverMapper(t *testing.T) {
Expand All @@ -20,31 +19,38 @@ func TestParsefileToObserverMapper(t *testing.T) {
require.NoError(t, err)
}(t, file)
app.SetConfig()
createObserverList(file)

observerAddress := sample.AccAddress()
commonGrantAddress := sample.AccAddress()
validatorAddress := sample.AccAddress()

createObserverList(file, observerAddress, commonGrantAddress, validatorAddress)
obsListReadFromFile, err := ParsefileToObserverDetails(file)
require.NoError(t, err)
for _, obs := range obsListReadFromFile {
require.Equal(
t,
obs.ObserverAddress,
observerAddress,
)
require.Equal(
t,
obs.ZetaClientGranteeAddress,
sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress"))).String(),
commonGrantAddress,
)
}
}

func createObserverList(fp string) {
func createObserverList(fp string, observerAddress, commonGrantAddress, validatorAddress string) {
var listReader []ObserverInfoReader
commonGrantAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress")))
observerAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverAddress")))
validatorAddress := sdk.ValAddress(crypto.AddressHash([]byte("ValidatorAddress")))
info := ObserverInfoReader{
ObserverAddress: observerAddress.String(),
ZetaClientGranteeAddress: commonGrantAddress.String(),
StakingGranteeAddress: commonGrantAddress.String(),
ObserverAddress: observerAddress,
ZetaClientGranteeAddress: commonGrantAddress,
StakingGranteeAddress: commonGrantAddress,
StakingMaxTokens: "100000000",
StakingValidatorAllowList: []string{validatorAddress.String()},
StakingValidatorAllowList: []string{validatorAddress},
SpendMaxTokens: "100000000",
GovGranteeAddress: commonGrantAddress.String(),
GovGranteeAddress: commonGrantAddress,
ZetaClientGranteePubKey: "zetapub1addwnpepqggtjvkmj6apcqr6ynyc5edxf2mpf5fxp2d3kwupemxtfwvg6gm7qv79fw0",
}
listReader = append(listReader, info)
Expand Down
9 changes: 1 addition & 8 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
// set account prefix to zeta
setCosmosConfig()

// wait for Genesis
// if setup is skip, we assume that the genesis is already created
if !skipSetup {
logger.Print("⏳ wait 70s for genesis")
time.Sleep(70 * time.Second)
}

zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{utils.FungibleAdminName},
Expand Down Expand Up @@ -399,7 +392,7 @@ func waitKeygenHeight(
logger *runner.Logger,
) {
// wait for keygen to be completed
keygenHeight := int64(60)
keygenHeight := int64(35)
logger.Print("⏳ wait height %v for keygen to be completed", keygenHeight)
for {
time.Sleep(2 * time.Second)
Expand Down
Loading

0 comments on commit df1dcbe

Please sign in to comment.