Skip to content

Commit 71f98c2

Browse files
davidterpaymergify[bot]
authored andcommitted
fix(baseapp): ABCI Consensus Failure Fix (#16700)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Jeancarlo Barrios <JeancarloBarrios@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: Chill Validation <92176880+chillyvee@users.noreply.github.com> (cherry picked from commit 078e7cb) # Conflicts: # CHANGELOG.md
1 parent cd8ba48 commit 71f98c2

3 files changed

Lines changed: 119 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,34 @@ Ref: https://keepachangelog.com/en/1.0.0/
6060

6161
* (x/staking) [#16324](https://github.com/cosmos/cosmos-sdk/pull/16324) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`, and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context` and return an `error`. Notable changes:
6262
* `Validator` method now returns `types.ErrNoValidatorFound` instead of `nil` when not found.
63+
<<<<<<< HEAD
6364
* (x/auth) [#16621](https://github.com/cosmos/cosmos-sdk/pull/16621) Pass address codec to auth new keeper constructor.
65+
=======
66+
* (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`:
67+
* remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`.
68+
* (x/distribution) [#16459](https://github.com/cosmos/cosmos-sdk/pull/16459) use collections for `ValidatorCurrentRewards` state management:
69+
* remove `Keeper`: `IterateValidatorCurrentRewards`, `GetValidatorCurrentRewards`, `SetValidatorCurrentRewards`, `DeleteValidatorCurrentRewards`
70+
* (x/authz) [#16509](https://github.com/cosmos/cosmos-sdk/pull/16509) `AcceptResponse` has been moved to sdk/types/authz and the `Updated` field is now of the type `sdk.Msg` instead of `authz.Authorization`.
71+
* (x/distribution) [#16483](https://github.com/cosmos/cosmos-sdk/pull/16483) use collections for `DelegatorStartingInfo` state management:
72+
* remove `Keeper`: `IterateDelegatorStartingInfo`, `GetDelegatorStartingInfo`, `SetDelegatorStartingInfo`, `DeleteDelegatorStartingInfo`, `HasDelegatorStartingInfo`
73+
* (x/distribution) [#16571](https://github.com/cosmos/cosmos-sdk/pull/16571) use collections for `ValidatorAccumulatedCommission` state management:
74+
* remove `Keeper`: `IterateValidatorAccumulatedCommission`, `GetValidatorAccumulatedCommission`, `SetValidatorAccumulatedCommission`, `DeleteValidatorAccumulatedCommission`
75+
* (x/distribution) [#16590](https://github.com/cosmos/cosmos-sdk/pull/16590) use collections for `ValidatorOutstandingRewards` state management:
76+
* remove `Keeper`: `IterateValidatorOutstandingRewards`, `GetValidatorOutstandingRewards`, `SetValidatorOutstandingRewards`, `DeleteValidatorOutstandingRewards`
77+
* (x/distribution) [#16607](https://github.com/cosmos/cosmos-sdk/pull/16607) use collections for `ValidatorHistoricalRewards` state management:
78+
* remove `Keeper`: `IterateValidatorHistoricalRewards`, `GetValidatorHistoricalRewards`, `SetValidatorHistoricalRewards`, `DeleteValidatorHistoricalRewards`, `DeleteValidatorHistoricalReward`, `DeleteAllValidatorHistoricalRewards`
79+
* (x/auth) [#16621](https://github.com/cosmos/cosmos-sdk/pull/16621) Pass address codec to auth new keeper constructor
80+
81+
### Bug Fixes
82+
83+
* (x/auth/vesting) [#16733](https://github.com/cosmos/cosmos-sdk/pull/16733) panic on overflowing and negative EndTimes when creating a PeriodicVestingAccount
84+
* [#16547](https://github.com/cosmos/cosmos-sdk/pull/16547) Ensure a transaction's gas limit cannot exceed the block gas limit.
85+
* (x/auth/types) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
86+
* (baseapp) [#16613](https://github.com/cosmos/cosmos-sdk/pull/16613) Ensure each message in a transaction has a registered handler, otherwise `CheckTx` will fail.
87+
* (x/consensus) [#16713](https://github.com/cosmos/cosmos-sdk/pull/16713) Add missing ABCI param in MsgUpdateParams.
88+
* [#16639](https://github.com/cosmos/cosmos-sdk/pull/16639) Make sure we don't execute blocks beyond the halt height.
89+
* (baseapp) [#16700](https://github.com/cosmos/cosmos-sdk/pull/16700) Fix: Consensus Failure in returning no response to malformed transactions
90+
>>>>>>> 078e7cb4a (fix(baseapp): ABCI Consensus Failure Fix (#16700))
6491
6592
## [v0.50.0-alpha.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.0) - 2023-06-07
6693

baseapp/abci.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,24 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
723723
// vote extensions, so skip those.
724724
txResults := make([]*abci.ExecTxResult, 0, len(req.Txs))
725725
for _, rawTx := range req.Txs {
726+
var response *abci.ExecTxResult
727+
726728
if _, err := app.txDecoder(rawTx); err == nil {
727-
txResults = append(txResults, app.deliverTx(rawTx))
729+
response = app.deliverTx(rawTx)
730+
} else {
731+
// In the case where a transaction included in a block proposal is malformed,
732+
// we still want to return a default response to comet. This is because comet
733+
// expects a response for each transaction included in a block proposal.
734+
response = sdkerrors.ResponseExecTxResultWithEvents(
735+
sdkerrors.ErrTxDecode,
736+
0,
737+
0,
738+
nil,
739+
false,
740+
)
728741
}
742+
743+
txResults = append(txResults, response)
729744
}
730745

731746
if app.finalizeBlockState.ms.TracingEnabled() {

baseapp/abci_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,19 @@ func TestABCI_InvalidTransaction(t *testing.T) {
566566
Height: 1,
567567
})
568568

569+
// malformed transaction bytes
570+
{
571+
bz := []byte("example vote extension")
572+
result, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
573+
Height: 1,
574+
Txs: [][]byte{bz},
575+
})
576+
577+
require.EqualValues(t, sdkerrors.ErrTxDecode.Codespace(), result.TxResults[0].Codespace, err)
578+
require.EqualValues(t, sdkerrors.ErrTxDecode.ABCICode(), result.TxResults[0].Code, err)
579+
require.EqualValues(t, 0, result.TxResults[0].GasUsed, err)
580+
require.EqualValues(t, 0, result.TxResults[0].GasWanted, err)
581+
}
569582
// transaction with no messages
570583
{
571584
emptyTx := suite.txConfig.NewTxBuilder().GetTx()
@@ -1230,6 +1243,69 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {
12301243
// })
12311244
}
12321245

1246+
func TestABCI_Proposals_WithVE(t *testing.T) {
1247+
someVoteExtension := []byte("some-vote-extension")
1248+
1249+
setInitChainerOpt := func(bapp *baseapp.BaseApp) {
1250+
bapp.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
1251+
return &abci.ResponseInitChain{}, nil
1252+
})
1253+
}
1254+
1255+
prepareOpt := func(bapp *baseapp.BaseApp) {
1256+
bapp.SetPrepareProposal(func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
1257+
// Inject the vote extension to the beginning of the proposal
1258+
txs := make([][]byte, len(req.Txs)+1)
1259+
txs[0] = someVoteExtension
1260+
copy(txs[1:], req.Txs)
1261+
1262+
return &abci.ResponsePrepareProposal{Txs: txs}, nil
1263+
})
1264+
1265+
bapp.SetProcessProposal(func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
1266+
// Check that the vote extension is still there
1267+
require.Equal(t, someVoteExtension, req.Txs[0])
1268+
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
1269+
})
1270+
}
1271+
1272+
suite := NewBaseAppSuite(t, setInitChainerOpt, prepareOpt)
1273+
1274+
suite.baseApp.InitChain(&abci.RequestInitChain{
1275+
InitialHeight: 1,
1276+
ConsensusParams: &cmtproto.ConsensusParams{},
1277+
})
1278+
1279+
reqPrepareProposal := abci.RequestPrepareProposal{
1280+
MaxTxBytes: 100000,
1281+
Height: 1, // this value can't be 0
1282+
}
1283+
resPrepareProposal, err := suite.baseApp.PrepareProposal(&reqPrepareProposal)
1284+
require.NoError(t, err)
1285+
require.Equal(t, 1, len(resPrepareProposal.Txs))
1286+
1287+
reqProcessProposal := abci.RequestProcessProposal{
1288+
Txs: resPrepareProposal.Txs,
1289+
Height: reqPrepareProposal.Height,
1290+
}
1291+
resProcessProposal, err := suite.baseApp.ProcessProposal(&reqProcessProposal)
1292+
require.NoError(t, err)
1293+
require.Equal(t, abci.ResponseProcessProposal_ACCEPT, resProcessProposal.Status)
1294+
1295+
// Run finalize block and ensure that the vote extension is still there and that
1296+
// the proposal is accepted
1297+
result, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
1298+
Txs: resPrepareProposal.Txs,
1299+
Height: reqPrepareProposal.Height,
1300+
})
1301+
require.NoError(t, err)
1302+
require.Equal(t, 1, len(result.TxResults))
1303+
require.EqualValues(t, sdkerrors.ErrTxDecode.Codespace(), result.TxResults[0].Codespace, err)
1304+
require.EqualValues(t, sdkerrors.ErrTxDecode.ABCICode(), result.TxResults[0].Code, err)
1305+
require.EqualValues(t, 0, result.TxResults[0].GasUsed, err)
1306+
require.EqualValues(t, 0, result.TxResults[0].GasWanted, err)
1307+
}
1308+
12331309
func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) {
12341310
anteKey := []byte("ante-key")
12351311
pool := mempool.NewSenderNonceMempool()

0 commit comments

Comments
 (0)