Skip to content

Commit

Permalink
Adds separate key for aggregator signatures (cosmos#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriceLC92 authored Mar 8, 2022
1 parent 18be2cd commit 9c2c374
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### BREAKING CHANGES

- Add separate key for aggregator signatures ([#309](https://github.com/celestiaorg/optimint/pull/309)) [@mauriceLC92](https://github.com/mauriceLC92)

### FEATURES

### IMPROVEMENTS
Expand Down
5 changes: 4 additions & 1 deletion node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func TestAggregatorMode(t *testing.T) {
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{})

key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)

blockManagerConfig := config.BlockManagerConfig{
BlockTime: 1 * time.Second,
NamespaceID: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
}
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -214,6 +215,7 @@ func createNode(n int, aggregator bool, dalc da.DataAvailabilityLayerClient, key
wg.Done()
})

signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := NewNode(
context.Background(),
config.NodeConfig{
Expand All @@ -223,6 +225,7 @@ func createNode(n int, aggregator bool, dalc da.DataAvailabilityLayerClient, key
BlockManagerConfig: bmConfig,
},
keys[n],
signingKey,
proxy.NewLocalClientCreator(app),
&types.GenesisDoc{ChainID: "test"},
log.TestingLogger().With("node", n))
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Node struct {
}

// NewNode creates new Optimint node.
func NewNode(ctx context.Context, conf config.NodeConfig, nodeKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger) (*Node, error) {
func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger) (*Node, error) {
proxyApp := proxy.NewAppConns(clientCreator)
proxyApp.SetLogger(logger.With("module", "proxy"))
if err := proxyApp.Start(); err != nil {
Expand All @@ -91,7 +91,7 @@ func NewNode(ctx context.Context, conf config.NodeConfig, nodeKey crypto.PrivKey
return nil, err
}

client, err := p2p.NewClient(conf.P2P, nodeKey, genesis.ChainID, logger.With("module", "p2p"))
client, err := p2p.NewClient(conf.P2P, p2pKey, genesis.ChainID, logger.With("module", "p2p"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func NewNode(ctx context.Context, conf config.NodeConfig, nodeKey crypto.PrivKey
mp := mempool.NewCListMempool(llcfg.DefaultMempoolConfig(), proxyApp.Mempool(), 0)
mpIDs := newMempoolIDs()

blockManager, err := block.NewManager(nodeKey, conf.BlockManagerConfig, genesis, s, mp, proxyApp.Consensus(), dalc, eventBus, logger.With("module", "BlockManager"))
blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, proxyApp.Consensus(), dalc, eventBus, logger.With("module", "BlockManager"))
if err != nil {
return nil, fmt.Errorf("BlockManager initialization error: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestStartup(t *testing.T) {
app := &mocks.Application{}
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand All @@ -53,9 +54,10 @@ func TestMempoolDirectly(t *testing.T) {
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
app.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)

node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down
18 changes: 12 additions & 6 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func TestGenesisChunked(t *testing.T) {
mockApp := &mocks.Application{}
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
privKey, _, _ := crypto.GenerateEd25519Key(cryptorand.Reader)
n, _ := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger())
signingKey, _, _ := crypto.GenerateEd25519Key(cryptorand.Reader)
n, _ := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger())

rpc := NewClient(n)

Expand Down Expand Up @@ -400,13 +401,14 @@ func TestTx(t *testing.T) {
mockApp := &mocks.Application{}
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{
DALayer: "mock",
Aggregator: true,
BlockManagerConfig: config.BlockManagerConfig{
BlockTime: 200 * time.Millisecond,
}},
key, proxy.NewLocalClientCreator(mockApp),
key, signingKey, proxy.NewLocalClientCreator(mockApp),
&tmtypes.GenesisDoc{ChainID: "test"},
log.TestingLogger())
require.NoError(err)
Expand Down Expand Up @@ -634,6 +636,7 @@ func TestValidatorSetHandling(t *testing.T) {
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{})

key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)

vKeys := make([]tmcrypto.PrivKey, 4)
genesisValidators := make([]tmtypes.GenesisValidator, len(vKeys))
Expand All @@ -655,7 +658,7 @@ func TestValidatorSetHandling(t *testing.T) {
waitCh <- nil
})

node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond}}, key, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond}}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -774,7 +777,8 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
app := &mocks.Application{}
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -833,6 +837,8 @@ func TestMempool2Nodes(t *testing.T) {
app.On("CheckTx", abci.RequestCheckTx{Tx: []byte("good")}).Return(abci.ResponseCheckTx{Code: 0})
key1, _, _ := crypto.GenerateEd25519Key(crand.Reader)
key2, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey1, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey2, _, _ := crypto.GenerateEd25519Key(crand.Reader)

id1, err := peer.IDFromPrivateKey(key1)
require.NoError(err)
Expand All @@ -842,7 +848,7 @@ func TestMempool2Nodes(t *testing.T) {
P2P: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
},
}, key1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node1)

Expand All @@ -852,7 +858,7 @@ func TestMempool2Nodes(t *testing.T) {
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.Pretty(),
},
}, key2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node1)

Expand Down
3 changes: 2 additions & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
LastBlockAppHash: nil,
})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}}, key, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down

0 comments on commit 9c2c374

Please sign in to comment.