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

feat!: revert passing operator address on InitChain #617

Merged
merged 2 commits into from
Mar 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
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
}
2 changes: 0 additions & 2 deletions block/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,5 @@ func getManagerConfig() config.BlockManagerConfig {
BatchSubmitMaxTime: 30 * time.Minute,
NamespaceID: "0102030405060708",
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
}
}
5 changes: 0 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ type BlockManagerConfig struct {
BlockBatchMaxSizeBytes uint64 `mapstructure:"block_batch_max_size_bytes"`
// The number of messages cached by gossipsub protocol
GossipedBlocksCacheSize int `mapstructure:"gossiped_blocks_cache_size"`

// Parameters to get the sequencer's operator address
OperatorKeyringBackend string `mapstructure:"operator_keyring_backend"`
OperatorAccountName string `mapstructure:"operator_account_name"`
OperatorKeyringHomeDir string `mapstructure:"operator_keyring_home_dir"`
}

// GetViperConfig reads configuration parameters from Viper instance.
Expand Down
5 changes: 0 additions & 5 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func DefaultConfig(home, chainId string) *NodeConfig {
}
cfg.SettlementConfig = defaultSLconfig

// set operator address
cfg.OperatorKeyringBackend = defaultSLconfig.KeyringBackend
cfg.OperatorKeyringHomeDir = defaultSLconfig.KeyringHomeDir
cfg.OperatorAccountName = defaultSLconfig.DymAccountName

//Setting default params for da grpc mock
defaultDAGrpc := grpc.Config{
Host: "127.0.0.1",
Expand Down
5 changes: 0 additions & 5 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ keyring_home_dir = "{{ .SettlementConfig.KeyringHomeDir }}"
dym_account_name = "{{ .SettlementConfig.DymAccountName }}"


#keyring and key name to be used as sequencer's operator address on the rollapp
operator_keyring_backend = "{{ .BlockManagerConfig.OperatorKeyringBackend }}"
operator_keyring_home_dir = "{{ .BlockManagerConfig.OperatorKeyringHomeDir }}"
operator_account_name = "{{ .BlockManagerConfig.OperatorAccountName }}"

#######################################################
### Instrumentation Configuration Options ###
#######################################################
Expand Down
2 changes: 0 additions & 2 deletions node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ func TestAggregatorMode(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
NamespaceID: "0102030405060708",
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
}

nodeConfig := config.NodeConfig{
Expand Down
2 changes: 0 additions & 2 deletions node/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig
BatchSubmitMaxTime: 60 * time.Second,
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
}
}
nodeConfig.BlockManagerConfig = *blockManagerConfig
Expand Down
4 changes: 0 additions & 4 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ func TestTx(t *testing.T) {
BatchSubmitMaxTime: 60 * time.Second,
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(pubKeybytes)},
Expand Down Expand Up @@ -713,8 +711,6 @@ func TestValidatorSetHandling(t *testing.T) {
BatchSubmitMaxTime: 60 * time.Second,
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)},
Expand Down
2 changes: 0 additions & 2 deletions rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
BlockBatchSize: 10000,
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
OperatorKeyringBackend: "memory",
OperatorAccountName: "default",
},
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)},
Expand Down
Loading