Skip to content

Commit 89da9c2

Browse files
Ganesha UpadhyayaGanesha Upadhyaya
authored andcommitted
fix datarace due to prepare proposal
1 parent c57dec2 commit 89da9c2

7 files changed

Lines changed: 21 additions & 16 deletions

File tree

block/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
606606
block = pendingBlock
607607
} else {
608608
m.logger.Info("Creating and publishing block", "height", newHeight)
609-
block, err = m.createBlock(ctx, newHeight, lastCommit, lastHeaderHash)
609+
block, err = m.createBlock(newHeight, lastCommit, lastHeaderHash)
610610
if err != nil {
611611
return nil
612612
}
@@ -759,10 +759,10 @@ func (m *Manager) getLastBlockTime() time.Time {
759759
return m.lastState.LastBlockTime
760760
}
761761

762-
func (m *Manager) createBlock(ctx context.Context, height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash) (*types.Block, error) {
762+
func (m *Manager) createBlock(height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash) (*types.Block, error) {
763763
m.lastStateMtx.RLock()
764764
defer m.lastStateMtx.RUnlock()
765-
return m.executor.CreateBlock(ctx, height, lastCommit, lastHeaderHash, m.lastState)
765+
return m.executor.CreateBlock(height, lastCommit, lastHeaderHash, m.lastState)
766766
}
767767

768768
func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.State, *abci.ResponseFinalizeBlock, error) {

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/rollkit/rollkit
22

3-
go 1.21
3+
go 1.21.1
4+
5+
toolchain go1.21.4
46

57
require (
68
github.com/celestiaorg/go-header v0.4.1

node/full_client_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ func TestStatus(t *testing.T) {
829829

830830
app := &mocks.Application{}
831831
app.On("InitChain", mock.Anything, mock.Anything).Return(&abci.ResponseInitChain{}, nil)
832+
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(prepareProposalResponse).Maybe()
833+
app.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil)
832834
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
833835
genesisValidators, signingKey := types.GetGenesisValidatorSetWithSigner()
834836
pubKey := genesisValidators[0].PubKey
@@ -1000,10 +1002,9 @@ func TestNetInfo(t *testing.T) {
10001002
require := require.New(t)
10011003

10021004
mockApp, rpc := getRPC(t)
1003-
mockApp.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
1004-
mockApp.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
1005-
mockApp.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{})
1006-
mockApp.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
1005+
mockApp.On("FinalizeBlock", mock.Anything, mock.Anything).Return(finalizeBlockResponse)
1006+
mockApp.On("CheckTx", mock.Anything, mock.Anything).Return(&abci.ResponseCheckTx{}, nil)
1007+
mockApp.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil)
10071008

10081009
err := rpc.node.Start()
10091010
require.NoError(err)

node/full_node_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func setupMockApplication() *mocks.Application {
4444
app := &mocks.Application{}
4545
app.On("InitChain", mock.Anything, mock.Anything).Return(&abci.ResponseInitChain{}, nil)
4646
app.On("CheckTx", mock.Anything, mock.Anything).Return(&abci.ResponseCheckTx{}, nil)
47+
app.On("PrepareProposal", mock.Anything, mock.Anything).Return(prepareProposalResponse).Maybe()
48+
app.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil)
4749
return app
4850
}
4951

state/executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (e *BlockExecutor) InitChain(genesis *cmtypes.GenesisDoc) (*abci.ResponseIn
8989
}
9090

9191
// CreateBlock reaps transactions from mempool and builds a block.
92-
func (e *BlockExecutor) CreateBlock(ctx context.Context, height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash, state types.State) (*types.Block, error) {
92+
func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash, state types.State) (*types.Block, error) {
9393
maxBytes := state.ConsensusParams.Block.MaxBytes
9494
emptyMaxBytes := maxBytes == -1
9595
if emptyMaxBytes {
@@ -131,7 +131,7 @@ func (e *BlockExecutor) CreateBlock(ctx context.Context, height uint64, lastComm
131131
}
132132

133133
rpp, err := e.proxyApp.PrepareProposal(
134-
ctx,
134+
context.TODO(),
135135
&abci.RequestPrepareProposal{
136136
MaxTxBytes: maxBytes,
137137
Txs: mempoolTxs.ToSliceOfBytes(),

state/executor_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func doTestCreateBlock(t *testing.T) {
6161
state.ConsensusParams.Block.MaxGas = 100000
6262

6363
// empty block
64-
block, err := executor.CreateBlock(context.Background(), 1, &types.Commit{}, []byte{}, state)
64+
block, err := executor.CreateBlock(1, &types.Commit{}, []byte{}, state)
6565
require.NoError(err)
6666
require.NotNil(block)
6767
assert.Empty(block.Data.Txs)
@@ -70,7 +70,7 @@ func doTestCreateBlock(t *testing.T) {
7070
// one small Tx
7171
err = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{})
7272
require.NoError(err)
73-
block, err = executor.CreateBlock(context.Background(), 2, &types.Commit{}, []byte{}, state)
73+
block, err = executor.CreateBlock(2, &types.Commit{}, []byte{}, state)
7474
require.NoError(err)
7575
require.NotNil(block)
7676
assert.Equal(uint64(2), block.Height())
@@ -81,7 +81,7 @@ func doTestCreateBlock(t *testing.T) {
8181
require.NoError(err)
8282
err = mpool.CheckTx(make([]byte, 100), func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{})
8383
require.NoError(err)
84-
block, err = executor.CreateBlock(context.Background(), 3, &types.Commit{}, []byte{}, state)
84+
block, err = executor.CreateBlock(3, &types.Commit{}, []byte{}, state)
8585
require.NoError(err)
8686
require.NotNil(block)
8787
assert.Len(block.Data.Txs, 2)
@@ -164,7 +164,7 @@ func doTestApplyBlock(t *testing.T) {
164164

165165
err = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{})
166166
require.NoError(err)
167-
block, err := executor.CreateBlock(context.Background(), 1, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, state)
167+
block, err := executor.CreateBlock(1, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, state)
168168
require.NoError(err)
169169
require.NotNil(block)
170170
assert.Equal(uint64(1), block.Height())
@@ -194,7 +194,7 @@ func doTestApplyBlock(t *testing.T) {
194194
require.NoError(mpool.CheckTx([]byte{5, 6, 7, 8, 9}, func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{}))
195195
require.NoError(mpool.CheckTx([]byte{1, 2, 3, 4, 5}, func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{}))
196196
require.NoError(mpool.CheckTx(make([]byte, 90), func(r *abci.ResponseCheckTx) {}, mempool.TxInfo{}))
197-
block, err = executor.CreateBlock(context.Background(), 2, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, newState)
197+
block, err = executor.CreateBlock(2, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, newState)
198198
require.NoError(err)
199199
require.NotNil(block)
200200
assert.Equal(uint64(2), block.Height())

store/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Store interface {
2626
// SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store.
2727
SaveBlockResponses(height uint64, responses *abci.ResponseFinalizeBlock) error
2828

29-
// LoadBlockResponses returns block results at given height, or error if it's not found in Store.
29+
// GetBlockResponses returns block results at given height, or error if it's not found in Store.
3030
GetBlockResponses(height uint64) (*abci.ResponseFinalizeBlock, error)
3131

3232
// GetCommit returns commit for a block at given height, or error if it's not found in Store.

0 commit comments

Comments
 (0)