Skip to content

Commit

Permalink
sign blocks with a null key
Browse files Browse the repository at this point in the history
  • Loading branch information
mycodecrafting committed Feb 12, 2024
1 parent 94aabb9 commit fb0822b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
21 changes: 9 additions & 12 deletions block/ss_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,22 +32,21 @@ type SSManager struct {
store store.Store
conf config.BlockManagerConfig
genesis *cmtypes.GenesisDoc
proposerKey crypto.PrivKey
executor *state.BlockExecutor
logger log.Logger
proxyApp proxy.AppConns

// 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
}

// NewManager creates new block Manager.
func NewSSManager(
proposerKey crypto.PrivKey,
conf config.BlockManagerConfig,
genesis *cmtypes.GenesisDoc,
store store.Store,
Expand All @@ -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)
Expand All @@ -84,16 +79,18 @@ func NewSSManager(
}
}

nullValidator := cmtypes.NewValidator(nullKey.PubKey(), 1)

agg := &SSManager{
proposerKey: proposerKey,
conf: conf,
genesis: genesis,
lastState: s,
store: store,
executor: exec,
lastStateMtx: new(sync.RWMutex),
logger: logger,
validatorSet: &valSet,
validatorSet: cmtypes.NewValidatorSet([]*cmtypes.Validator{nullValidator}),
proposerKey: nullKey,
metrics: seqMetrics,
proxyApp: proxyApp,
}
Expand Down
11 changes: 5 additions & 6 deletions node/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -36,8 +32,6 @@ func NewNode(
return newFullNode(
ctx,
conf,
p2pKey,
signingKey,
appClient,
genesis,
metricsProvider,
Expand Down
4 changes: 0 additions & 4 deletions types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fb0822b

Please sign in to comment.