-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: max_gas_wanted not working in sdk 0.50 mempool
- Loading branch information
Showing
7 changed files
with
121 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/mempool" | ||
) | ||
|
||
type customMempoolIterator struct { | ||
txs []sdk.Tx | ||
} | ||
|
||
func (i *customMempoolIterator) Next() mempool.Iterator { | ||
if len(i.txs) <= 1 { | ||
return nil | ||
} | ||
return &customMempoolIterator{ | ||
txs: i.txs[1:], | ||
} | ||
} | ||
|
||
func (i *customMempoolIterator) Tx() sdk.Tx { | ||
return i.txs[0] | ||
} | ||
|
||
type CustomMempool[C comparable] struct { | ||
*mempool.PriorityNonceMempool[C] | ||
txVerifier baseapp.ProposalTxVerifier | ||
} | ||
|
||
func NewCustomMempool[C comparable](cfg mempool.PriorityNonceMempoolConfig[C], txVerifier baseapp.ProposalTxVerifier) *CustomMempool[C] { | ||
return &CustomMempool[C]{ | ||
PriorityNonceMempool: mempool.NewPriorityMempool(cfg), | ||
txVerifier: txVerifier, | ||
} | ||
} | ||
|
||
func (mp *CustomMempool[C]) Select(_ context.Context, txs [][]byte) mempool.Iterator { | ||
sdkTxs := make([]sdk.Tx, len(txs)) | ||
for i, tx := range txs { | ||
sdkTx, err := mp.txVerifier.TxDecode(tx) | ||
if err != nil { | ||
return nil | ||
} | ||
sdkTxs[i] = sdkTx | ||
} | ||
return &customMempoolIterator{ | ||
txs: sdkTxs, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
_ baseapp.TxSelector = &ExtTxSelector{} | ||
_ baseapp.ProposalTxVerifier = &ExtProposalTxVerifier{} | ||
) | ||
|
||
// ExtTxSelector extends a baseapp.TxSelector | ||
type ExtTxSelector struct { | ||
baseapp.TxSelector | ||
} | ||
|
||
func NewExtTxSelector(parent baseapp.TxSelector) *ExtTxSelector { | ||
return &ExtTxSelector{ | ||
TxSelector: parent, | ||
} | ||
} | ||
|
||
func (ts *ExtTxSelector) SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte) bool { | ||
// don't pass `memTx` to parent selector so it don't check tx gas wanted against block gas limit, | ||
// it conflicts with the max-tx-gas-wanted logic. | ||
return ts.TxSelector.SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, nil, txBz) | ||
} | ||
|
||
// ExtProposalTxVerifier extends a baseapp.ProposalTxVerifier | ||
type ExtProposalTxVerifier struct { | ||
baseapp.ProposalTxVerifier | ||
} | ||
|
||
func NewExtProposalTxVerifier(parent baseapp.ProposalTxVerifier) *ExtProposalTxVerifier { | ||
return &ExtProposalTxVerifier{ | ||
ProposalTxVerifier: parent, | ||
} | ||
} | ||
|
||
func (tv *ExtProposalTxVerifier) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) { | ||
_, err := tv.ProposalTxVerifier.ProcessProposalVerifyTx(txBz) | ||
return nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters