mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 13:05:09 +00:00
Old PrepareProposal on feature/abci++ppp (#9106)
* [Rebased to v0.34.x] abci: PrepareProposal (#6544) * fixed cherry-pick * proto changes * make proto-gen * UT fixes * generate Client directive * mockery * App fixes * Disable 'modified tx' hack * mockery * Make format * Fix lint Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
@@ -91,6 +91,8 @@ func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
|
||||
// and txs from the mempool. The max bytes must be big enough to fit the commit.
|
||||
// Up to 1/10th of the block space is allcoated for maximum sized evidence.
|
||||
// The rest is given to txs, up to the max gas.
|
||||
//
|
||||
// Contract: application will not return more bytes than are sent over the wire.
|
||||
func (blockExec *BlockExecutor) CreateProposalBlock(
|
||||
height int64,
|
||||
state State, commit *types.Commit,
|
||||
@@ -107,7 +109,33 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
|
||||
|
||||
txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
|
||||
|
||||
return state.MakeBlock(height, txs, commit, evidence, proposerAddr)
|
||||
preparedProposal, err := blockExec.proxyApp.PrepareProposalSync(
|
||||
abci.RequestPrepareProposal{BlockData: txs.ToSliceOfBytes(), BlockDataSize: maxDataBytes},
|
||||
)
|
||||
if err != nil {
|
||||
// The App MUST ensure that only valid (and hence 'processable') transactions
|
||||
// enter the mempool. Hence, at this point, we can't have any non-processable
|
||||
// transaction causing an error.
|
||||
//
|
||||
// Also, the App can simply skip any transaction that could cause any kind of trouble.
|
||||
// Either way, we can not recover in a meaningful way, unless we skip proposing
|
||||
// this block, repair what caused the error and try again. Hence, we panic on
|
||||
// purpose for now.
|
||||
panic(err)
|
||||
}
|
||||
newTxs := preparedProposal.GetBlockData()
|
||||
var txSize int
|
||||
for _, tx := range newTxs {
|
||||
txSize += len(tx)
|
||||
|
||||
if maxDataBytes < int64(txSize) {
|
||||
panic("block data exceeds max amount of allowed bytes")
|
||||
}
|
||||
}
|
||||
|
||||
modifiedTxs := types.ToTxs(preparedProposal.GetBlockData())
|
||||
|
||||
return state.MakeBlock(height, modifiedTxs, commit, evidence, proposerAddr)
|
||||
}
|
||||
|
||||
// ValidateBlock validates the given block against the given state.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.12.3. DO NOT EDIT.
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -75,13 +75,13 @@ func (_m *BlockIndexer) Search(ctx context.Context, q *query.Query) ([]int64, er
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
type NewBlockIndexerT interface {
|
||||
type mockConstructorTestingTNewBlockIndexer interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewBlockIndexer creates a new instance of BlockIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewBlockIndexer(t NewBlockIndexerT) *BlockIndexer {
|
||||
func NewBlockIndexer(t mockConstructorTestingTNewBlockIndexer) *BlockIndexer {
|
||||
mock := &BlockIndexer{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package mocks
|
||||
|
||||
import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
state "github.com/tendermint/tendermint/state"
|
||||
|
||||
types "github.com/tendermint/tendermint/types"
|
||||
|
||||
@@ -4,6 +4,7 @@ package mocks
|
||||
|
||||
import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
state "github.com/tendermint/tendermint/state"
|
||||
|
||||
tendermintstate "github.com/tendermint/tendermint/proto/tendermint/state"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.12.3. DO NOT EDIT.
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
context "context"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
query "github.com/tendermint/tendermint/libs/pubsub/query"
|
||||
|
||||
txindex "github.com/tendermint/tendermint/state/txindex"
|
||||
@@ -92,13 +93,13 @@ func (_m *TxIndexer) Search(ctx context.Context, q *query.Query) ([]*types.TxRes
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
type NewTxIndexerT interface {
|
||||
type mockConstructorTestingTNewTxIndexer interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewTxIndexer creates a new instance of TxIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewTxIndexer(t NewTxIndexerT) *TxIndexer {
|
||||
func NewTxIndexer(t mockConstructorTestingTNewTxIndexer) *TxIndexer {
|
||||
mock := &TxIndexer{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user