Skip to content

Commit

Permalink
add genesis and import/export logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Dec 11, 2024
1 parent 3265296 commit 2063a5a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 44 deletions.
2 changes: 2 additions & 0 deletions cmd/zetacored/parse_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func ModifyObserverState(
currentGenState := observertypes.GetGenesisStateFromAppState(cdc, appState)
currentGenState.Ballots = importedObserverGenState.Ballots
currentGenState.NonceToCctx = importedObserverGenState.NonceToCctx
// zero operational flags as they are network specific
currentGenState.OperationalFlags = observertypes.OperationalFlags{}

currentGenStateBz, err := cdc.MarshalJSON(&currentGenState)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions proto/zetachain/zetacore/observer/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "zetachain/zetacore/observer/params.proto";
import "zetachain/zetacore/observer/pending_nonces.proto";
import "zetachain/zetacore/observer/tss.proto";
import "zetachain/zetacore/observer/tss_funds_migrator.proto";
import "zetachain/zetacore/observer/operational.proto";

option go_package = "github.com/zeta-chain/node/x/observer/types";

Expand All @@ -35,4 +36,5 @@ message GenesisState {
repeated PendingNonces pending_nonces = 13 [ (gogoproto.nullable) = false ];
repeated ChainNonces chain_nonces = 14 [ (gogoproto.nullable) = false ];
repeated NonceToCctx nonce_to_cctx = 15 [ (gogoproto.nullable) = false ];
OperationalFlags operational_flags = 16 [ (gogoproto.nullable) = false ];
}
4 changes: 4 additions & 0 deletions x/observer/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.NonceToCctx {
k.SetNonceToCctx(ctx, elem)
}
k.SetOperationalFlags(ctx, genState.OperationalFlags)
}

// ExportGenesis returns the observer module's exported genesis.
Expand Down Expand Up @@ -185,6 +186,8 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
os = observers
}

of, _ := k.GetOperationalFlags(ctx)

return &types.GenesisState{
Ballots: k.GetAllBallots(ctx),
ChainParamsList: chainParams,
Expand All @@ -200,5 +203,6 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
BlameList: k.GetAllBlame(ctx),
ChainNonces: k.GetAllChainNonces(ctx),
NonceToCctx: k.GetAllNonceToCctx(ctx),
OperationalFlags: of,
}
}
9 changes: 6 additions & 3 deletions x/observer/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestGenesis(t *testing.T) {
sample.ChainNonces(1),
sample.ChainNonces(2),
},
PendingNonces: sample.PendingNoncesList(t, "sample", 20),
NonceToCctx: sample.NonceToCctxList(t, "sample", 20),
TssHistory: []types.TSS{sample.Tss()},
PendingNonces: sample.PendingNoncesList(t, "sample", 20),
NonceToCctx: sample.NonceToCctxList(t, "sample", 20),
TssHistory: []types.TSS{sample.Tss()},
OperationalFlags: sample.OperationalFlags(),
}

// Init and export
Expand Down Expand Up @@ -84,6 +85,7 @@ func TestGenesis(t *testing.T) {
Keygen: &types.Keygen{},
LastObserverCount: &types.LastObserverCount{},
NodeAccountList: []*types.NodeAccount{},
OperationalFlags: types.OperationalFlags{},
}

require.Equal(t, expectedGenesisState, *got)
Expand Down Expand Up @@ -148,6 +150,7 @@ func TestGenesis(t *testing.T) {
BlameList: k.GetAllBlame(ctx),
ChainNonces: k.GetAllChainNonces(ctx),
NonceToCctx: k.GetAllNonceToCctx(ctx),
OperationalFlags: types.OperationalFlags{},
}

require.Equal(t, expectedGenesisState, *got)
Expand Down
140 changes: 99 additions & 41 deletions x/observer/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/observer/types/operational.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2063a5a

Please sign in to comment.