diff --git a/core/blockchain/nullchain/mocks/mocks.go b/core/blockchain/nullchain/mocks/mocks.go index 17b4a0999c8..3ac68ff99d3 100644 --- a/core/blockchain/nullchain/mocks/mocks.go +++ b/core/blockchain/nullchain/mocks/mocks.go @@ -132,3 +132,18 @@ func (mr *MockApplicationServiceMockRecorder) InitChain(arg0, arg1 interface{}) mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitChain", reflect.TypeOf((*MockApplicationService)(nil).InitChain), arg0, arg1) } + +// PrepareProposal mocks base method. +func (m *MockApplicationService) PrepareProposal(arg0 context.Context, arg1 *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareProposal", arg0, arg1) + ret0, _ := ret[0].(*types.ResponsePrepareProposal) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PrepareProposal indicates an expected call of PrepareProposal. +func (mr *MockApplicationServiceMockRecorder) PrepareProposal(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareProposal", reflect.TypeOf((*MockApplicationService)(nil).PrepareProposal), arg0, arg1) +} diff --git a/core/blockchain/nullchain/nullchain.go b/core/blockchain/nullchain/nullchain.go index 9dda90a4d15..2e168470521 100644 --- a/core/blockchain/nullchain/nullchain.go +++ b/core/blockchain/nullchain/nullchain.go @@ -55,6 +55,7 @@ type TimeService interface { type ApplicationService interface { InitChain(context.Context, *abci.RequestInitChain) (*abci.ResponseInitChain, error) + PrepareProposal(_ context.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) FinalizeBlock(context.Context, *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) Commit(context.Context, *abci.RequestCommit) (*abci.ResponseCommit, error) Info(context.Context, *abci.RequestInfo) (*abci.ResponseInfo, error) @@ -187,22 +188,35 @@ func (n *NullBlockchain) processBlock() { n.log.Debugf("processing block %d with %d transactions", n.blockHeight, len(n.pending)) } + // prepare it first + ctx := context.Background() + proposal, err := n.app.PrepareProposal(ctx, + &abci.RequestPrepareProposal{ + Height: n.blockHeight, + Time: n.now, + Txs: n.pending, + }) + if err != nil { + // core always returns nil so we are safe really + panic("nullchain cannot handle failure to prepare a proposal") + } + resp := &abci.ResponseFinalizeBlock{} if n.replayer != nil && n.cfg.Replay.Record { - n.replayer.startBlock(n.blockHeight, n.now.UnixNano(), n.pending) + n.replayer.startBlock(n.blockHeight, n.now.UnixNano(), proposal.Txs) defer func() { n.replayer.saveBlock(resp.AppHash) }() } - resp, _ = n.app.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{ + resp, _ = n.app.FinalizeBlock(ctx, &abci.RequestFinalizeBlock{ Height: n.blockHeight, Time: n.now, Hash: vgcrypto.Hash([]byte(strconv.FormatInt(n.blockHeight+n.now.UnixNano(), 10))), - Txs: n.pending, + Txs: proposal.Txs, }) n.pending = n.pending[:0] - n.app.Commit(context.Background(), &abci.RequestCommit{}) + n.app.Commit(ctx, &abci.RequestCommit{}) // Increment time, blockheight, ready to start a new block n.blockHeight++ diff --git a/core/blockchain/nullchain/nullchain_test.go b/core/blockchain/nullchain/nullchain_test.go index 9588b309b84..9fa4a52b133 100644 --- a/core/blockchain/nullchain/nullchain_test.go +++ b/core/blockchain/nullchain/nullchain_test.go @@ -322,6 +322,15 @@ func getTestUnstartedNullChain(t *testing.T, txnPerBlock uint64, d time.Duration n.SetABCIApp(app) require.NotNil(t, n) + app.EXPECT().PrepareProposal(gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { + ret := &abci.ResponsePrepareProposal{ + Txs: req.Txs, + } + return ret, nil + }, + ).AnyTimes() + return &testNullBlockChain{ chain: n, ctrl: ctrl, diff --git a/core/txcache/cache.go b/core/txcache/cache.go index 05834c3ffaa..179e79e3fd7 100644 --- a/core/txcache/cache.go +++ b/core/txcache/cache.go @@ -33,6 +33,7 @@ func NewTxCache(commander *nodewallets.Commander) *TxCache { return &TxCache{ commander: commander, marketToDelayRequired: map[string]bool{}, + heightToTxs: map[uint64][][]byte{}, } }