Skip to content

Commit d10c20c

Browse files
authored
Merge branch 'release/v1.3.x' into release/v1.3.x_nil_pointer
Signed-off-by: mmsqe <mavis@crypto.com>
2 parents 180a631 + b6b7200 commit d10c20c

File tree

3 files changed

+58
-23
lines changed

3 files changed

+58
-23
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
### Bug Fixes
1616

1717
* (rpc) [#1444](https://github.com/crypto-org-chain/cronos/pull/1444) Avoid nil pointer error when query blocks before feemarket module gets enabled.
18+
* [#1439](https://github.com/crypto-org-chain/cronos/pull/1439) Add back default prepare proposal logic.
1819

1920
*May 3, 2024*
2021

app/app.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ func New(
400400
appCodec := encodingConfig.Codec
401401
cdc := encodingConfig.Amino
402402
interfaceRegistry := encodingConfig.InterfaceRegistry
403+
txDecoder := encodingConfig.TxConfig.TxDecoder()
403404

404405
var identity age.Identity
405406
{
@@ -423,14 +424,25 @@ func New(
423424

424425
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, baseAppOptions)
425426

426-
blockProposalHandler := NewProposalHandler(encodingConfig.TxConfig.TxDecoder(), identity)
427+
blockProposalHandler := NewProposalHandler(txDecoder, identity)
427428

428429
// NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
429430
// Setup Mempool and Proposal Handlers
430431
baseAppOptions = append(baseAppOptions, func(app *baseapp.BaseApp) {
431432
mempool := mempool.NoOpMempool{}
432433
app.SetMempool(mempool)
433-
app.SetPrepareProposal(blockProposalHandler.PrepareProposalHandler())
434+
435+
// Re-use the default prepare proposal handler, extend the transaction validation logic
436+
defaultProposalHandler := baseapp.NewDefaultProposalHandler(mempool, app)
437+
defaultProposalHandler.SetTxSelector(NewExtTxSelector(
438+
baseapp.NewDefaultTxSelector(),
439+
txDecoder,
440+
blockProposalHandler.ValidateTransaction,
441+
))
442+
app.SetPrepareProposal(defaultProposalHandler.PrepareProposalHandler())
443+
444+
// The default process proposal handler do nothing when the mempool is noop,
445+
// so we just implement a new one.
434446
app.SetProcessProposal(blockProposalHandler.ProcessProposalHandler())
435447
})
436448
bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)

app/proposal.go

+43-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"filippo.io/age"
1010

1111
abci "github.com/cometbft/cometbft/abci/types"
12+
"github.com/cosmos/cosmos-sdk/baseapp"
1213
sdk "github.com/cosmos/cosmos-sdk/types"
1314
"github.com/cosmos/cosmos-sdk/x/auth/signing"
1415
)
@@ -17,6 +18,41 @@ type BlockList struct {
1718
Addresses []string `mapstructure:"addresses"`
1819
}
1920

21+
var _ baseapp.TxSelector = &ExtTxSelector{}
22+
23+
// ExtTxSelector extends a baseapp.TxSelector with extra tx validation method
24+
type ExtTxSelector struct {
25+
baseapp.TxSelector
26+
TxDecoder sdk.TxDecoder
27+
ValidateTx func(sdk.Tx) error
28+
}
29+
30+
func NewExtTxSelector(parent baseapp.TxSelector, txDecoder sdk.TxDecoder, validateTx func(sdk.Tx) error) *ExtTxSelector {
31+
return &ExtTxSelector{
32+
TxSelector: parent,
33+
TxDecoder: txDecoder,
34+
ValidateTx: validateTx,
35+
}
36+
}
37+
38+
func (ts *ExtTxSelector) SelectTxForProposal(maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte) bool {
39+
var err error
40+
if memTx == nil {
41+
memTx, err = ts.TxDecoder(txBz)
42+
if err != nil {
43+
return false
44+
}
45+
}
46+
47+
if err := ts.ValidateTx(memTx); err != nil {
48+
return false
49+
}
50+
51+
// don't pass `memTx` to parent selector so it don't check tx gas wanted against block gas limit,
52+
// it conflicts with the max-tx-gas-wanted logic.
53+
return ts.TxSelector.SelectTxForProposal(maxTxBytes, maxBlockGas, nil, txBz)
54+
}
55+
2056
type ProposalHandler struct {
2157
TxDecoder sdk.TxDecoder
2258
Identity age.Identity
@@ -77,12 +113,7 @@ func (h *ProposalHandler) SetBlockList(blob []byte) error {
77113
return nil
78114
}
79115

80-
func (h *ProposalHandler) ValidateTransaction(txBz []byte) error {
81-
tx, err := h.TxDecoder(txBz)
82-
if err != nil {
83-
return err
84-
}
85-
116+
func (h *ProposalHandler) ValidateTransaction(tx sdk.Tx) error {
86117
sigTx, ok := tx.(signing.SigVerifiableTx)
87118
if !ok {
88119
return fmt.Errorf("tx of type %T does not implement SigVerifiableTx", tx)
@@ -96,24 +127,15 @@ func (h *ProposalHandler) ValidateTransaction(txBz []byte) error {
96127
return nil
97128
}
98129

99-
func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
100-
return func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
101-
txs := make([][]byte, 0, len(req.Txs))
102-
for _, txBz := range req.Txs {
103-
if err := h.ValidateTransaction(txBz); err != nil {
104-
continue
105-
}
106-
txs = append(txs, txBz)
107-
}
108-
109-
return abci.ResponsePrepareProposal{Txs: txs}
110-
}
111-
}
112-
113130
func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
114131
return func(ctx sdk.Context, req abci.RequestProcessProposal) abci.ResponseProcessProposal {
115132
for _, txBz := range req.Txs {
116-
if err := h.ValidateTransaction(txBz); err != nil {
133+
memTx, err := h.TxDecoder(txBz)
134+
if err != nil {
135+
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
136+
}
137+
138+
if err := h.ValidateTransaction(memTx); err != nil {
117139
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
118140
}
119141
}

0 commit comments

Comments
 (0)