Skip to content

Commit

Permalink
fix: retain injected tx if its removed (#735)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Johnson <[email protected]>
  • Loading branch information
technicallyty and aljo242 authored Sep 10, 2024
1 parent e3df9fe commit 6174714
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions abci/proposals/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
"vote_extensions_enabled", voteExtensionsEnabled,
)

// we save the injected tx so we can re-add it to the txs in case it is removed in a wrapped proposal handler.
var injectedTx []byte

if voteExtensionsEnabled {
// Ensure that the commit info was correctly injected into the proposal.
if len(req.Txs) < slinkyabci.NumInjectedTxs {
Expand Down Expand Up @@ -331,6 +334,7 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {

// Remove the extended commit info from the proposal if required
if !h.retainOracleDataInWrappedHandler {
injectedTx = req.Txs[slinkyabci.OracleInfoIndex]
req.Txs = req.Txs[slinkyabci.NumInjectedTxs:]
}
}
Expand All @@ -345,6 +349,11 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
}
}

if !h.retainOracleDataInWrappedHandler && injectedTx != nil {
// Re-inject the extended commit info back into the response if it was removed
req.Txs = append([][]byte{injectedTx}, req.Txs...)
}

wrappedProcessProposalLatency = time.Since(wrappedProcessProposalStartTime)
return resp, err
}
Expand Down
18 changes: 18 additions & 0 deletions abci/proposals/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
currencyPairStrategy func() currencypair.CurrencyPairStrategy
expectedError bool
expectedResp *cometabci.ResponseProcessProposal
checkTxs func(before, after [][]byte)
}{
{
name: "returns an error on nil request",
Expand Down Expand Up @@ -697,6 +698,9 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
expectedResp: &cometabci.ResponseProcessProposal{
Status: cometabci.ResponseProcessProposal_ACCEPT,
},
checkTxs: func(before, after [][]byte) {
s.Require().Equal(before, after)
},
},
{
name: "can process a block with multiple vote extensions",
Expand Down Expand Up @@ -936,6 +940,16 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
))
}

// make a copy of the txs before we run the proposal
var before [][]byte
if req != nil { // some tests use a nil request.
before = make([][]byte, len(req.Txs))
for i, tx := range req.Txs {
before[i] = make([]byte, len(tx))
copy(before[i], tx)
}
}

response, err := s.proposalHandler.ProcessProposalHandler()(s.ctx, req)

s.Require().Equal(tc.expectedResp, response)
Expand All @@ -944,6 +958,10 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
} else {
s.Require().NoError(err)
}

if tc.checkTxs != nil {
tc.checkTxs(before, req.Txs)
}
})
}
}
Expand Down

0 comments on commit 6174714

Please sign in to comment.