diff --git a/cmd/zetacored/parse_genesis.go b/cmd/zetacored/parse_genesis.go index 218b48191f..ff752a9ddc 100644 --- a/cmd/zetacored/parse_genesis.go +++ b/cmd/zetacored/parse_genesis.go @@ -35,6 +35,8 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) +const Max_items_for_list = 10 + var Copy = map[string]bool{ slashingtypes.ModuleName: true, govtypes.ModuleName: true, @@ -141,9 +143,9 @@ func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, 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(10, len(importedCrossChainGenState.CrossChainTxs))] - importedCrossChainGenState.InTxHashToCctxList = importedCrossChainGenState.InTxHashToCctxList[:math.Min(10, len(importedCrossChainGenState.InTxHashToCctxList))] - importedCrossChainGenState.FinalizedInbounds = importedCrossChainGenState.FinalizedInbounds[:math.Min(10, len(importedCrossChainGenState.FinalizedInbounds))] + importedCrossChainGenState.CrossChainTxs = importedCrossChainGenState.CrossChainTxs[:math.Min(Max_items_for_list, len(importedCrossChainGenState.CrossChainTxs))] + importedCrossChainGenState.InTxHashToCctxList = importedCrossChainGenState.InTxHashToCctxList[:math.Min(Max_items_for_list, len(importedCrossChainGenState.InTxHashToCctxList))] + importedCrossChainGenState.FinalizedInbounds = importedCrossChainGenState.FinalizedInbounds[:math.Min(Max_items_for_list, len(importedCrossChainGenState.FinalizedInbounds))] importedCrossChainStateBz, err := json.Marshal(importedCrossChainGenState) if err != nil { return fmt.Errorf("failed to marshal zetacrosschain genesis state: %w", err) @@ -154,8 +156,8 @@ func ModifyCrossChainState(appState map[string]json.RawMessage, importAppState m 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(10, len(importedObserverGenState.Ballots))] - importedObserverGenState.NonceToCctx = importedObserverGenState.NonceToCctx[:math.Min(10, len(importedObserverGenState.NonceToCctx))] + importedObserverGenState.Ballots = importedObserverGenState.Ballots[:math.Min(Max_items_for_list, len(importedObserverGenState.Ballots))] + importedObserverGenState.NonceToCctx = importedObserverGenState.NonceToCctx[:math.Min(Max_items_for_list, len(importedObserverGenState.NonceToCctx))] currentGenState := observertypes.GetGenesisStateFromAppState(cdc, appState) currentGenState.Ballots = importedObserverGenState.Ballots diff --git a/cmd/zetacored/parse_genesis_test.go b/cmd/zetacored/parse_genesis_test.go index 84eff883bd..3c51a2da04 100644 --- a/cmd/zetacored/parse_genesis_test.go +++ b/cmd/zetacored/parse_genesis_test.go @@ -72,8 +72,8 @@ func Test_ModifyObserverState(t *testing.T) { require.NoError(t, err) modifiedObserverAppState := observertypes.GetGenesisStateFromAppState(cdc, appState) - require.Len(t, modifiedObserverAppState.Ballots, 10) - require.Len(t, modifiedObserverAppState.NonceToCctx, 10) + require.Len(t, modifiedObserverAppState.Ballots, zetacored.Max_items_for_list) + require.Len(t, modifiedObserverAppState.NonceToCctx, zetacored.Max_items_for_list) }) t.Run("successfully modify observer state without changing data when not needed", func(t *testing.T) { @@ -104,9 +104,9 @@ func Test_ImportDataIntoFile(t *testing.T) { // Crosschain module is in Modify list crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState) - require.Len(t, crosschainStateAfterImport.CrossChainTxs, 10) - require.Len(t, crosschainStateAfterImport.InTxHashToCctxList, 10) - require.Len(t, crosschainStateAfterImport.FinalizedInbounds, 10) + require.Len(t, crosschainStateAfterImport.CrossChainTxs, zetacored.Max_items_for_list) + require.Len(t, crosschainStateAfterImport.InTxHashToCctxList, zetacored.Max_items_for_list) + require.Len(t, crosschainStateAfterImport.FinalizedInbounds, zetacored.Max_items_for_list) // Bank module is in Skip list var bankStateAfterImport banktypes.GenesisState