From fb0822b01d23a3aa3d3ee1c0436aa4c32d4fb4a7 Mon Sep 17 00:00:00 2001 From: Josh Dechant Date: Mon, 12 Feb 2024 17:22:03 -0500 Subject: [PATCH] sign blocks with a null key --- block/ss_manager.go | 21 +++++++++------------ node/full.go | 11 +++++------ node/node.go | 6 ------ types/state.go | 4 ---- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/block/ss_manager.go b/block/ss_manager.go index 19a975153..f8abd14a2 100644 --- a/block/ss_manager.go +++ b/block/ss_manager.go @@ -10,6 +10,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmcrypto "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/merkle" "github.com/cometbft/cometbft/proxy" cmtypes "github.com/cometbft/cometbft/types" @@ -31,7 +32,6 @@ type SSManager struct { store store.Store conf config.BlockManagerConfig genesis *cmtypes.GenesisDoc - proposerKey crypto.PrivKey executor *state.BlockExecutor logger log.Logger proxyApp proxy.AppConns @@ -39,6 +39,7 @@ type SSManager struct { // Rollkit doesn't have "validators", but // we store the sequencer in this struct for compatibility. validatorSet *cmtypes.ValidatorSet + proposerKey cmcrypto.PrivKey // for reporting metrics metrics *Metrics @@ -46,7 +47,6 @@ type SSManager struct { // NewManager creates new block Manager. func NewSSManager( - proposerKey crypto.PrivKey, conf config.BlockManagerConfig, genesis *cmtypes.GenesisDoc, store store.Store, @@ -61,16 +61,11 @@ func NewSSManager( if err != nil { return nil, err } - // genesis should have exactly one "validator", the centralized sequencer. - // this should have been validated in the above call to getInitialState. - valSet := types.GetValidatorSetFromGenesis(genesis) - proposerAddress, err := getAddress(proposerKey) - if err != nil { - return nil, err - } + nullKey := ed25519.GenPrivKeyFromSecret([]byte{0x00}) + proposer := nullKey.PubKey().Address() - exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp.Consensus(), eventBus, logger, execMetrics) + exec := state.NewBlockExecutor(proposer, genesis.ChainID, mempool, proxyApp.Consensus(), eventBus, logger, execMetrics) if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) { logger.Info("Initializing chain") res, err := exec.InitChain(genesis) @@ -84,8 +79,9 @@ func NewSSManager( } } + nullValidator := cmtypes.NewValidator(nullKey.PubKey(), 1) + agg := &SSManager{ - proposerKey: proposerKey, conf: conf, genesis: genesis, lastState: s, @@ -93,7 +89,8 @@ func NewSSManager( executor: exec, lastStateMtx: new(sync.RWMutex), logger: logger, - validatorSet: &valSet, + validatorSet: cmtypes.NewValidatorSet([]*cmtypes.Validator{nullValidator}), + proposerKey: nullKey, metrics: seqMetrics, proxyApp: proxyApp, } diff --git a/node/full.go b/node/full.go index 4eb7886b5..063d07dce 100644 --- a/node/full.go +++ b/node/full.go @@ -13,7 +13,6 @@ import ( ds "github.com/ipfs/go-datastore" ktds "github.com/ipfs/go-datastore/keytransform" - "github.com/libp2p/go-libp2p/core/crypto" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -95,8 +94,8 @@ type FullNode struct { func newFullNode( ctx context.Context, nodeConfig config.NodeConfig, - p2pKey crypto.PrivKey, - signingKey crypto.PrivKey, + // p2pKey crypto.PrivKey, + // signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *cmtypes.GenesisDoc, metricsProvider MetricsProvider, @@ -155,7 +154,7 @@ func newFullNode( mempool := initMempool(logger, proxyApp, memplMetrics) store := store.New(mainKV) - blockManager, err := initBlockManager(signingKey, nodeConfig, genesis, store, mempool, proxyApp, eventBus, logger, seqMetrics, smMetrics) + blockManager, err := initBlockManager(nodeConfig, genesis, store, mempool, proxyApp, eventBus, logger, seqMetrics, smMetrics) if err != nil { return nil, err } @@ -272,8 +271,8 @@ func initMempool(logger log.Logger, proxyApp proxy.AppConns, memplMetrics *mempo // return blockSyncService, nil // } -func initBlockManager(signingKey crypto.PrivKey, nodeConfig config.NodeConfig, genesis *cmtypes.GenesisDoc, store store.Store, mempool mempool.Mempool, proxyApp proxy.AppConns, eventBus *cmtypes.EventBus, logger log.Logger, seqMetrics *block.Metrics, execMetrics *state.Metrics) (*block.SSManager, error) { - blockManager, err := block.NewSSManager(signingKey, nodeConfig.BlockManagerConfig, genesis, store, mempool, proxyApp, eventBus, logger.With("module", "BlockManager"), seqMetrics, execMetrics) +func initBlockManager(nodeConfig config.NodeConfig, genesis *cmtypes.GenesisDoc, store store.Store, mempool mempool.Mempool, proxyApp proxy.AppConns, eventBus *cmtypes.EventBus, logger log.Logger, seqMetrics *block.Metrics, execMetrics *state.Metrics) (*block.SSManager, error) { + blockManager, err := block.NewSSManager(nodeConfig.BlockManagerConfig, genesis, store, mempool, proxyApp, eventBus, logger.With("module", "BlockManager"), seqMetrics, execMetrics) if err != nil { return nil, fmt.Errorf("error while initializing BlockManager: %w", err) } diff --git a/node/node.go b/node/node.go index 8b3555ef0..e6bdaa7cd 100644 --- a/node/node.go +++ b/node/node.go @@ -3,8 +3,6 @@ package node import ( "context" - "github.com/libp2p/go-libp2p/core/crypto" - "github.com/cometbft/cometbft/libs/log" proxy "github.com/cometbft/cometbft/proxy" rpcclient "github.com/cometbft/cometbft/rpc/client" @@ -26,8 +24,6 @@ type Node interface { func NewNode( ctx context.Context, conf config.NodeConfig, - p2pKey crypto.PrivKey, - signingKey crypto.PrivKey, appClient proxy.ClientCreator, genesis *cmtypes.GenesisDoc, metricsProvider MetricsProvider, @@ -36,8 +32,6 @@ func NewNode( return newFullNode( ctx, conf, - p2pKey, - signingKey, appClient, genesis, metricsProvider, diff --git a/types/state.go b/types/state.go index 4598b67e3..2b10d23db 100644 --- a/types/state.go +++ b/types/state.go @@ -60,10 +60,6 @@ func NewFromGenesisDoc(genDoc *types.GenesisDoc) (State, error) { return State{}, fmt.Errorf("error in genesis doc: %w", err) } - if len(genDoc.Validators) != 1 { - return State{}, fmt.Errorf("must have exactly 1 validator (the centralized sequencer)") - } - s := State{ Version: InitStateVersion, ChainID: genDoc.ChainID,