Skip to content

Commit

Permalink
fix: full-node panics with app hash mismatch error when syncing (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Apr 14, 2024
1 parent 3cd56c5 commit 0073faf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
26 changes: 14 additions & 12 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ func NewManager(
func (m *Manager) Start(ctx context.Context, isAggregator bool) error {
m.logger.Info("Starting the block manager")

err := m.syncBlockManager(ctx)
if err != nil {
err = fmt.Errorf("failed to sync block manager: %w", err)
return err
}

if isAggregator {
//make sure local signing key is the registered on the hub
slProposerKey := m.settlementClient.GetProposer().PublicKey.Bytes()
Expand All @@ -148,15 +142,23 @@ func (m *Manager) Start(ctx context.Context, isAggregator bool) error {
return fmt.Errorf("proposer key mismatch: settlement proposer key: %s, block manager proposer key: %s", slProposerKey, m.proposerKey.GetPublic())
}
m.logger.Info("Starting in aggregator mode")
}

// Check if InitChain flow is needed
if m.lastState.LastBlockHeight+1 == m.genesis.InitialHeight {
err := m.RunInitChain(ctx)
if err != nil {
return err
}
// Check if InitChain flow is needed
if m.lastState.LastBlockHeight+1 == m.genesis.InitialHeight {
err := m.RunInitChain(ctx)
if err != nil {
return err
}
}

err := m.syncBlockManager(ctx)
if err != nil {
err = fmt.Errorf("failed to sync block manager: %w", err)
return err
}

if isAggregator {
go m.ProduceBlockLoop(ctx)
go m.SubmitLoop(ctx)
} else {
Expand Down
8 changes: 7 additions & 1 deletion rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func TestBroadcastTxAsync(t *testing.T) {

mockApp, rpc := getRPC(t)
mockApp.On("CheckTx", abci.RequestCheckTx{Tx: expectedTx}).Return(abci.ResponseCheckTx{})
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

err := rpc.node.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -178,6 +179,7 @@ func TestBroadcastTxSync(t *testing.T) {
}

mockApp, rpc := getRPC(t)
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

err := rpc.node.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -228,7 +230,7 @@ func TestBroadcastTxCommit(t *testing.T) {
mockApp.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
mockApp.BeginBlock(abci.RequestBeginBlock{})
mockApp.On("CheckTx", abci.RequestCheckTx{Tx: expectedTx}).Return(expectedCheckResp)

mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
// in order to broadcast, the node must be started
err := rpc.node.Start()
require.NoError(err)
Expand Down Expand Up @@ -264,6 +266,7 @@ func TestGetBlock(t *testing.T) {
mockApp.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
mockApp.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{})
mockApp.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

err := rpc.node.Start()
require.NoError(err)
Expand All @@ -289,6 +292,7 @@ func TestGetCommit(t *testing.T) {
mockApp, rpc := getRPC(t)
mockApp.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
mockApp.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

blocks := []*types.Block{getRandomBlock(1, 5), getRandomBlock(2, 6), getRandomBlock(3, 8), getRandomBlock(4, 10)}

Expand Down Expand Up @@ -391,6 +395,7 @@ func TestGetBlockByHash(t *testing.T) {
mockApp.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{})
mockApp.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
mockApp.On("Info", mock.Anything).Return(abci.ResponseInfo{LastBlockHeight: 0, LastBlockAppHash: []byte{0}})
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

err := rpc.node.Start()
require.NoError(err)
Expand Down Expand Up @@ -507,6 +512,7 @@ func TestUnconfirmedTxs(t *testing.T) {
mockApp, rpc := getRPC(t)
mockApp.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
mockApp.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})

err := rpc.node.Start()
require.NoError(err)
Expand Down

0 comments on commit 0073faf

Please sign in to comment.