Skip to content

Commit

Permalink
removed operator pubkey from initChain
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Mar 25, 2024
1 parent d70f556 commit 5effbd0
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions block/initchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,31 @@ package block

import (
"context"
"os"

"github.com/cosmos/cosmos-sdk/codec"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/evmos/evmos/v12/crypto/hd"
"github.com/ignite/cli/ignite/pkg/cosmosaccount"
tmtypes "github.com/tendermint/tendermint/types"
)

func (m *Manager) RunInitChain(ctx context.Context) error {

// We pass an initial val set which is actually the consensus and operator addresses of the proposer.
// This is a hack to make sure the chain can get both addresses without us needing to change comet signatures:
// The RDK will save a sequencer, and delete the extra validator after initChain, so we also delete it here
// to keep the state in sync.

//get the proposer's consensus pubkey
proposer := m.settlementClient.GetProposer()
tmPubKey, err := cryptocodec.ToTmPubKeyInterface(proposer.PublicKey)
if err != nil {
return err
}
consensusPubkey := tmtypes.NewValidator(tmPubKey, 1)

//get the operator's pubkey
pubkey, err := getOperatorPubkey(m.conf.OperatorKeyringHomeDir, m.conf.OperatorKeyringBackend, m.conf.OperatorAccountName)
if err != nil {
return err
}
tmPubKey, err = cryptocodec.ToTmPubKeyInterface(pubkey)
if err != nil {
return err
}
operatorPubkey := tmtypes.NewValidator(tmPubKey, 1)
gensisValSet := []*tmtypes.Validator{tmtypes.NewValidator(tmPubKey, 1)}

//call initChain with both addresses
res, err := m.executor.InitChain(m.genesis, []*tmtypes.Validator{consensusPubkey, operatorPubkey})
res, err := m.executor.InitChain(m.genesis, gensisValSet)
if err != nil {
return err
}

//update the state with only the consensus pubkey
m.executor.UpdateStateAfterInitChain(&m.lastState, res, []*tmtypes.Validator{consensusPubkey})
m.executor.UpdateStateAfterInitChain(&m.lastState, res, gensisValSet)
if _, err := m.store.UpdateState(m.lastState, nil); err != nil {
return err
}

return nil
}

func getOperatorPubkey(keyDir, keyringBackend, accountName string) (cryptotypes.PubKey, error) {
// open keyring
c, err := cosmosaccount.New(
cosmosaccount.WithKeyringBackend(cosmosaccount.KeyringBackend(keyringBackend)),
cosmosaccount.WithHome(keyDir),
)
if err != nil {
return nil, err
}

interfaceRegistry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(interfaceRegistry)
cdc := codec.NewProtoCodec(interfaceRegistry)

customKeyring, err := keyring.New("operatorAddr", keyringBackend, keyDir, os.Stdin, cdc, hd.EthSecp256k1Option())
if err != nil {
return nil, err
}
c.Keyring = customKeyring

// If the keyring is in memory, ensure the default account exists to be used in tests
if keyringBackend == "memory" {
err := c.EnsureDefaultAccount()
if err != nil {
return nil, err
}
}

// Get account from the keyring
account, err := c.GetByName(accountName)
if err != nil {
return nil, err
}

pubkey, err := account.Record.GetPubKey()
if err != nil {
return nil, err
}

return pubkey, nil
}

0 comments on commit 5effbd0

Please sign in to comment.