Skip to content

Commit

Permalink
feat(observer): add core params list in genesis (#1087)
Browse files Browse the repository at this point in the history
* proto gen

* update genesis logic

* update genesis samples
  • Loading branch information
lumtis authored Sep 11, 2023
1 parent 1366787 commit 037dc0b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
}
},
"observer": {
"core_params_list": [],
"observers": [
{
"observer_chain": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
}
},
"observer": {
"core_params_list": [],
"observers": [
{
"observer_chain": {
Expand Down
1 change: 1 addition & 0 deletions proto/observer/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ message GenesisState {
Params params = 5;
Keygen keygen = 6;
LastObserverCount last_observer_count = 7;
CoreParamsList core_params_list = 8 [(gogoproto.nullable) = false];
}
28 changes: 28 additions & 0 deletions testutil/sample/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/observer/types"
)

Expand Down Expand Up @@ -69,3 +70,30 @@ func LastObserverCount(lastChangeHeight int64) *types.LastObserverCount {
LastChangeHeight: lastChangeHeight,
}
}

func CoreParams(chainID int64) *types.CoreParams {
r := newRandFromSeed(chainID)

return &types.CoreParams{
ChainId: chainID,
ConfirmationCount: r.Uint64(),
GasPriceTicker: r.Uint64(),
InTxTicker: r.Uint64(),
OutTxTicker: r.Uint64(),
WatchUtxoTicker: r.Uint64(),
ZetaTokenContractAddress: EthAddress().String(),
ConnectorContractAddress: EthAddress().String(),
Erc20CustodyContractAddress: EthAddress().String(),
OutboundTxScheduleInterval: r.Int63(),
OutboundTxScheduleLookahead: r.Int63(),
}
}

func CoreParamsList() (cpl types.CoreParamsList) {
chainList := common.DefaultChainsList()

for _, chain := range chainList {
cpl.CoreParams = append(cpl.CoreParams, CoreParams(chain.ChainId))
}
return
}
13 changes: 12 additions & 1 deletion x/observer/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
}
}

k.SetCoreParams(ctx, types.GetCoreParams())
// If core params are defined set them, otherwise set default
if len(genState.CoreParamsList.CoreParams) > 0 {
k.SetCoreParams(ctx, genState.CoreParamsList)
} else {
k.SetCoreParams(ctx, types.GetCoreParams())
}

// Set all the nodeAccount
for _, elem := range genState.NodeAccountList {
Expand Down Expand Up @@ -73,6 +78,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
params := k.GetParams(ctx)

coreParams, found := k.GetAllCoreParams(ctx)
if !found {
coreParams = types.CoreParamsList{}
}

// Get all node accounts
nodeAccountList := k.GetAllNodeAccount(ctx)
nodeAccounts := make([]*types.NodeAccount, len(nodeAccountList))
Expand Down Expand Up @@ -103,6 +113,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
Ballots: k.GetAllBallots(ctx),
Observers: k.GetAllObserverMappers(ctx),
CoreParamsList: coreParams,
Params: &params,
NodeAccountList: nodeAccounts,
PermissionFlags: &pf,
Expand Down
1 change: 1 addition & 0 deletions x/observer/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestGenesis(t *testing.T) {
PermissionFlags: sample.PermissionFlags(),
Keygen: sample.Keygen(t),
LastObserverCount: sample.LastObserverCount(1000),
CoreParamsList: sample.CoreParamsList(),
}

// Init and export
Expand Down
108 changes: 82 additions & 26 deletions x/observer/types/genesis.pb.go

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

0 comments on commit 037dc0b

Please sign in to comment.