Skip to content

Commit

Permalink
feat: Enforce config rollapp id to be same as genesis chain id (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Apr 17, 2024
1 parent 25afe20 commit 84e8853
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 45 deletions.
18 changes: 15 additions & 3 deletions node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/p2p"
"github.com/dymensionxyz/dymint/settlement"
"github.com/stretchr/testify/assert"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -55,6 +56,8 @@ func TestAggregatorMode(t *testing.T) {
GossipedBlocksCacheSize: 50,
}

rollappID := "rollapp_1234-1"

nodeConfig := config.NodeConfig{
RootDir: "",
DBPath: "",
Expand All @@ -65,9 +68,18 @@ func TestAggregatorMode(t *testing.T) {
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: proposerKey},
SettlementConfig: settlement.Config{ProposerPubKey: proposerKey, RollappID: rollappID},
}
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := NewNode(
context.Background(),
nodeConfig,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&types.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)

Expand Down
3 changes: 3 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type Node struct {

// NewNode creates new Dymint node.
func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger, metrics *mempool.Metrics) (*Node, error) {
if conf.SettlementConfig.RollappID != genesis.ChainID {
return nil, fmt.Errorf("rollapp ID in settlement config doesn't match chain ID in genesis")
}
proxyApp := proxy.NewAppConns(clientCreator)
proxyApp.SetLogger(logger.With("module", "proxy"))
if err := proxyApp.Start(); err != nil {
Expand Down
29 changes: 21 additions & 8 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/node/events"
"github.com/dymensionxyz/dymint/settlement"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -57,6 +58,7 @@ func TestMempoolDirectly(t *testing.T) {
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
rollappID := "rollapp_1234-1"

nodeConfig := config.NodeConfig{
RootDir: "",
Expand All @@ -71,12 +73,23 @@ func TestMempoolDirectly(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
},
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{},
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{
RollappID: rollappID,
},
}
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := NewNode(
context.Background(),
nodeConfig,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&types.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)

Expand Down
24 changes: 18 additions & 6 deletions node/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"encoding/hex"
"time"

"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"

"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
)

// TODO: should be moved to testutils
Expand All @@ -38,10 +39,21 @@ func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig
nodeConfig.BlockManagerConfig = *blockManagerConfig
nodeConfig.Aggregator = isAggregator

rollappID := "rollapp_1234-1"

// SL config
nodeConfig.SettlementConfig = settlement.Config{ProposerPubKey: hex.EncodeToString(pubkeyBytes)}
nodeConfig.SettlementConfig = settlement.Config{ProposerPubKey: hex.EncodeToString(pubkeyBytes), RollappID: rollappID}

node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := NewNode(
context.Background(),
nodeConfig,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&types.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
if err != nil {
return nil, err
}
Expand Down
106 changes: 79 additions & 27 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func TestCheckTx(t *testing.T) {

func TestGenesisChunked(t *testing.T) {
assert := assert.New(t)
rollappID := "rollapp_1234-1"

genDoc := &tmtypes.GenesisDoc{
ChainID: "test",
ChainID: rollappID,
InitialHeight: int64(1),
AppHash: []byte("test hash"),
Validators: []tmtypes.GenesisValidator{
Expand All @@ -107,13 +108,25 @@ func TestGenesisChunked(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
},
BootstrapTime: 30 * time.Second,
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{},
BootstrapTime: 30 * time.Second,
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{
RollappID: rollappID,
},
}
n, _ := node.NewNode(context.Background(), config, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger(), mempool.NopMetrics())
n, err := node.NewNode(
context.Background(),
config,
privKey,
signingKey,
proxy.NewLocalClientCreator(mockApp),
genDoc,
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(t, err)

rpc := NewClient(n)

Expand Down Expand Up @@ -436,6 +449,7 @@ func TestTx(t *testing.T) {

pubKeybytes, err := proposerPubKey.Raw()
require.NoError(err)
rollappID := "rollapp_1234-1"

node, err := node.NewNode(context.Background(), config.NodeConfig{
DALayer: "mock",
Expand All @@ -448,11 +462,14 @@ func TestTx(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(pubKeybytes)},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(pubKeybytes),
RollappID: rollappID,
},
},
key, signingKey, proxy.NewLocalClientCreator(mockApp),
&tmtypes.GenesisDoc{ChainID: "test"},
&tmtypes.GenesisDoc{ChainID: rollappID},
log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)
Expand Down Expand Up @@ -705,6 +722,7 @@ func TestValidatorSetHandling(t *testing.T) {
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Run(func(args mock.Arguments) {
waitCh <- nil
})
rollappID := "rollapp_1234-1"

nodeConfig := config.NodeConfig{
DALayer: "mock",
Expand All @@ -717,11 +735,23 @@ func TestValidatorSetHandling(t *testing.T) {
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)},
BootstrapTime: 30 * time.Second,
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes),
RollappID: rollappID,
},
}

node, err := node.NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := node.NewNode(
context.Background(),
nodeConfig,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&tmtypes.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -823,6 +853,8 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
proposerKey := hex.EncodeToString(pubkeyBytes)
require.NoError(err)

rollappID := "rollapp_1234-1"

config := config.NodeConfig{
RootDir: "",
DBPath: "",
Expand All @@ -836,13 +868,25 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
BlockBatchMaxSizeBytes: 1000,
GossipedBlocksCacheSize: 50,
},
BootstrapTime: 30 * time.Second,
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: proposerKey},
BootstrapTime: 30 * time.Second,
DALayer: "mock",
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{
ProposerPubKey: proposerKey,
RollappID: rollappID,
},
}
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := node.NewNode(
context.Background(),
config,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&tmtypes.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -913,10 +957,15 @@ func TestMempool2Nodes(t *testing.T) {
proposerPubKey2Bytes, err := proposerPubKey2.Raw()
require.NoError(err)

rollappID := "rollapp_1234-1"

node1, err := node.NewNode(context.Background(), config.NodeConfig{
DALayer: "mock",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKey1Bytes)},
DALayer: "mock",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKey1Bytes),
RollappID: rollappID,
},
BlockManagerConfig: config.BlockManagerConfig{
BlockBatchSize: 1,
BlockTime: 100 * time.Millisecond,
Expand All @@ -928,14 +977,17 @@ func TestMempool2Nodes(t *testing.T) {
P2P: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
},
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: rollappID}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node1)

node2, err := node.NewNode(context.Background(), config.NodeConfig{
DALayer: "mock",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKey2Bytes)},
DALayer: "mock",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKey2Bytes),
RollappID: rollappID,
},
BlockManagerConfig: config.BlockManagerConfig{
BlockBatchSize: 1,
BlockTime: 100 * time.Millisecond,
Expand All @@ -948,7 +1000,7 @@ func TestMempool2Nodes(t *testing.T) {
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(),
},
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: rollappID}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node1)

Expand Down
15 changes: 14 additions & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
signingKey, proposerPubKey, _ := crypto.GenerateEd25519Key(rand.Reader)
proposerPubKeyBytes, err := proposerPubKey.Raw()
require.NoError(err)

rollappID := "rollapp_1234-1"

config := config.NodeConfig{
Aggregator: true, DALayer: "mock", SettlementLayer: "mock",
BlockManagerConfig: config.BlockManagerConfig{
Expand All @@ -308,9 +311,19 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
},
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes),
RollappID: rollappID,
},
}
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
node, err := node.NewNode(
context.Background(),
config,
key,
signingKey,
proxy.NewLocalClientCreator(app),
&types.GenesisDoc{ChainID: rollappID},
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)

Expand Down

0 comments on commit 84e8853

Please sign in to comment.