Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge genesis #128

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ cat %GENESIS% | jq ".app_state[\"staking\"][\"params\"][\"bond_denom\"]=\"aphoto
cat %GENESIS% | jq ".app_state[\"crisis\"][\"constant_fee\"][\"denom\"]=\"aphoton\"" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%
cat %GENESIS% | jq ".app_state[\"gov\"][\"deposit_params\"][\"min_deposit\"][0][\"denom\"]=\"aphoton\"" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%
cat %GENESIS% | jq ".app_state[\"mint\"][\"params\"][\"mint_denom\"]=\"aphoton\"" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%
cat %GENESIS% | jq ".app_state[\"bridge\"][\"callerGroupList\"]=[{\"name\":\"caller group\",\"admin\":\"%ACCOUNT_ADDRESS%\",\"members\":[\"%ACCOUNT_ADDRESS%\"],\"creator\":\"%ACCOUNT_ADDRESS%\",}]" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%
cat %GENESIS% | jq ".app_state[\"bridge\"][\"signerGroupList\"]=[{\"name\":\"signer group\",\"admin\":\"%ACCOUNT_ADDRESS%\",\"members\":[\"%ACCOUNT_ADDRESS%\"],\"threshold\":1,\"creator\":\"%ACCOUNT_ADDRESS%\",}]" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%

rem increase block time (?)
cat %GENESIS% | jq ".consensus_params[\"block\"][\"time_iota_ms\"]=\"30000\"" > %TMPGENESIS% && move %TMPGENESIS% %GENESIS%
Expand Down
6 changes: 1 addition & 5 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ make install
ethermintd config keyring-backend $KEYRING
ethermintd config chain-id $CHAINID

# if $KEY exists it should be deleted
OUTPUT=$(ethermintd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --output json)
ACCOUNT_ADDRESS=$(echo "$OUTPUT" | jq -r '.address')
ethermintd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO

# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
ethermintd init $MONIKER --chain-id $CHAINID
Expand All @@ -33,8 +31,6 @@ jq '.app_state["staking"]["params"]["bond_denom"]="aphoton"' "$HOME"/.ethermintd
jq '.app_state["crisis"]["constant_fee"]["denom"]="aphoton"' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json
jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="aphoton"' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json
jq '.app_state["mint"]["params"]["mint_denom"]="aphoton"' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json
jq --arg ADDRESS "$ACCOUNT_ADDRESS" '.app_state["bridge"]["callerGroupList"]=[{"name":"caller group","admin":$ADDRESS,"members":[$ADDRESS],"creator":$ADDRESS}]' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json
jq --arg ADDRESS "$ACCOUNT_ADDRESS" '.app_state["bridge"]["signerGroupList"]=[{"name":"signer group","admin":$ADDRESS,"members":[$ADDRESS],"threshold":1,"creator":$ADDRESS}]' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json
# Set gas limit in genesis
jq '.consensus_params["block"]["max_gas"]="20000000"' "$HOME"/.ethermintd/config/genesis.json > "$HOME"/.ethermintd/config/tmp_genesis.json && mv "$HOME"/.ethermintd/config/tmp_genesis.json "$HOME"/.ethermintd/config/genesis.json

Expand Down
32 changes: 31 additions & 1 deletion x/bridge/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,37 @@ import (
)

// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
func InitGenesis(ctx sdk.Context, k keeper.Keeper, ak types.AccountKeeper, genState types.GenesisState) {
if len(genState.SignerGroupList) == 0 || len(genState.CallerGroupList) == 0 {
accs := ak.GetAllAccounts(ctx)
adminAddress := ""
for _, acc := range accs {
if acc.GetAccountNumber() == 0 {
adminAddress = acc.GetAddress().String()
}
}
if len(genState.SignerGroupList) == 0 {
genState.SignerGroupList = []types.SignerGroup{
{
Name: "signer group",
Admin: adminAddress,
Members: []string{adminAddress},
Threshold: 1,
Creator: adminAddress,
},
}
}
if len(genState.CallerGroupList) == 0 {
genState.CallerGroupList = []types.CallerGroup{
{
Name: "caller group",
Admin: adminAddress,
Members: []string{adminAddress},
Creator: adminAddress,
},
}
}
}
// Set all the signerGroup
for _, elem := range genState.SignerGroupList {
k.SetSignerGroup(ctx, elem)
Expand Down
2 changes: 1 addition & 1 deletion x/bridge/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestGenesis(t *testing.T) {
}

k, ctx := keepertest.BridgeKeeper(t)
bridge.InitGenesis(ctx, *k, genesisState)
bridge.InitGenesis(ctx, *k, nil, genesisState)
got := bridge.ExportGenesis(ctx, *k)
require.NotNil(t, got)

Expand Down
2 changes: 1 addition & 1 deletion x/bridge/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra
// Initialize global index to index in genesis state
cdc.MustUnmarshalJSON(gs, &genState)

InitGenesis(ctx, am.keeper, genState)
InitGenesis(ctx, am.keeper, am.accountKeeper, genState)

return []abci.ValidatorUpdate{}
}
Expand Down
1 change: 1 addition & 0 deletions x/bridge/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type GroupKeeper interface {
// AccountKeeper defines the expected account keeper used for simulations (noalias)
type AccountKeeper interface {
GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI
GetAllAccounts(ctx sdk.Context) (accounts []types.AccountI)
// Methods imported from account should be defined here
}

Expand Down
Loading