Skip to content

Commit

Permalink
fix(mempool): Initialize the mempool with the correct(current) block …
Browse files Browse the repository at this point in the history
…height (dymensionxyz#703)

Co-authored-by: danwt <[email protected]>
  • Loading branch information
zale144 and danwt authored Apr 17, 2024
1 parent 3bcda30 commit 35b9e58
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
47 changes: 38 additions & 9 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/dymensionxyz/dymint/block"
"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/da"
daregsitry "github.com/dymensionxyz/dymint/da/registry"
daregistry "github.com/dymensionxyz/dymint/da/registry"
"github.com/dymensionxyz/dymint/mempool"
mempoolv1 "github.com/dymensionxyz/dymint/mempool/v1"
"github.com/dymensionxyz/dymint/node/events"
Expand Down Expand Up @@ -117,7 +117,16 @@ 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) {
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")
}
Expand Down Expand Up @@ -150,34 +159,41 @@ func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey,

s := store.New(mainKV)

dalc := daregsitry.GetClient(conf.DALayer)
dalc := daregistry.GetClient(conf.DALayer)
if dalc == nil {
return nil, fmt.Errorf("couldn't get data availability client named '%s'", conf.DALayer)
return nil, fmt.Errorf("get data availability client named '%s'", conf.DALayer)
}
err := dalc.Init([]byte(conf.DAConfig), pubsubServer, dalcKV, logger.With("module", string(dalc.GetClientType())))
if err != nil {
return nil, fmt.Errorf("data availability layer client initialization error: %w", err)
return nil, fmt.Errorf("data availability layer client initialization %w", err)
}

// Init the settlement layer client
settlementlc := slregistry.GetClient(slregistry.Client(conf.SettlementLayer))
if settlementlc == nil {
return nil, fmt.Errorf("couldn't get settlement client named '%s'", conf.SettlementLayer)
return nil, fmt.Errorf("get settlement client: named: %s", conf.SettlementLayer)
}
if conf.SettlementLayer == "mock" {
conf.SettlementConfig.KeyringHomeDir = conf.RootDir
}
err = settlementlc.Init(conf.SettlementConfig, pubsubServer, logger.With("module", "settlement_client"))
if err != nil {
return nil, fmt.Errorf("settlement layer client initialization error: %w", err)
return nil, fmt.Errorf("settlement layer client initialization: %w", err)
}

indexerService, txIndexer, blockIndexer, err := createAndStartIndexerService(conf, indexerKV, eventBus, logger)
if err != nil {
return nil, err
}

mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), proxyApp.Mempool(), 0)
info, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
if err != nil {
return nil, fmt.Errorf("querying info: %w", err)
}

height := max(genesis.InitialHeight, info.LastBlockHeight)

mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), proxyApp.Mempool(), height)
mpIDs := nodemempool.NewMempoolIDs()

// Set p2p client and it's validators
Expand All @@ -192,7 +208,20 @@ func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey,
p2pClient.SetTxValidator(p2pValidator.TxValidator(mp, mpIDs))
p2pClient.SetBlockValidator(p2pValidator.BlockValidator())

blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, proxyApp, dalc, settlementlc, eventBus, pubsubServer, p2pClient, logger.With("module", "BlockManager"))
blockManager, err := block.NewManager(
signingKey,
conf.BlockManagerConfig,
genesis,
s,
mp,
proxyApp,
dalc,
settlementlc,
eventBus,
pubsubServer,
p2pClient,
logger.With("module", "BlockManager"),
)
if err != nil {
return nil, fmt.Errorf("BlockManager initialization error: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestMempoolDirectly(t *testing.T) {
app := &mocks.Application{}
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
app.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
app.On("Info", mock.Anything).Return(abci.ResponseInfo{})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
Expand Down
5 changes: 5 additions & 0 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestGenesisChunked(t *testing.T) {

mockApp := &mocks.Application{}
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
mockApp.On("Info", mock.Anything).Return(expectedInfo)
privKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)

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

mockApp := &mocks.Application{}
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
mockApp.On("Info", mock.Anything).Return(expectedInfo)
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, proposerPubKey, err := crypto.GenerateEd25519Key(crand.Reader)
require.NoError(err)
Expand Down Expand Up @@ -847,6 +849,7 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
t.Helper()
require := require.New(t)
app := &mocks.Application{}
app.On("Info", mock.Anything).Return(expectedInfo)
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, pubkey, err := crypto.GenerateEd25519Key(crand.Reader)
pubkeyBytes, _ := pubkey.Raw()
Expand Down Expand Up @@ -943,6 +946,8 @@ func TestMempool2Nodes(t *testing.T) {
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
app.On("CheckTx", abci.RequestCheckTx{Tx: []byte("bad")}).Return(abci.ResponseCheckTx{Code: 1})
app.On("CheckTx", abci.RequestCheckTx{Tx: []byte("good")}).Return(abci.ResponseCheckTx{Code: 0})
app.On("Info", mock.Anything).Return(expectedInfo)

key1, _, _ := crypto.GenerateEd25519Key(crand.Reader)
key2, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey1, proposerPubKey1, _ := crypto.GenerateEd25519Key(crand.Reader)
Expand Down

0 comments on commit 35b9e58

Please sign in to comment.