fix(Config): Simplifying config interface (#104)

This commit is contained in:
David Terpay
2023-05-04 15:33:18 -04:00
committed by GitHub
parent 07c76b8330
commit d58b36bf3d
14 changed files with 345 additions and 564 deletions
+3 -3
View File
@@ -32,7 +32,7 @@ type ABCITestSuite struct {
encodingConfig testutils.EncodingConfig
proposalHandler *abci.ProposalHandler
voteExtensionHandler *abci.VoteExtensionHandler
config mempool.Config
config mempool.AuctionFactory
txs map[string]struct{}
// auction bid setup
@@ -66,10 +66,10 @@ func (suite *ABCITestSuite) SetupTest() {
suite.random = rand.New(rand.NewSource(time.Now().Unix()))
suite.key = storetypes.NewKVStoreKey(buildertypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(suite.T(), suite.key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx
suite.ctx = testCtx.Ctx.WithBlockHeight(1)
// Mempool set up
suite.config = mempool.NewDefaultConfig(suite.encodingConfig.TxConfig.TxDecoder())
suite.config = mempool.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder())
suite.mempool = mempool.NewAuctionMempool(suite.encodingConfig.TxConfig.TxDecoder(), suite.encodingConfig.TxConfig.TxEncoder(), 0, suite.config)
suite.txs = make(map[string]struct{})
suite.auctionBidAmount = sdk.NewCoin("foo", sdk.NewInt(1000000000))
+17 -13
View File
@@ -12,6 +12,7 @@ import (
"github.com/cometbft/cometbft/libs/log"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/skip-mev/pob/mempool"
)
type (
@@ -19,10 +20,14 @@ type (
// to interact with the local mempool.
ProposalMempool interface {
sdkmempool.Mempool
// The AuctionFactory interface is utilized to retrieve, validate, and wrap bid
// information into the block proposal.
mempool.AuctionFactory
// AuctionBidSelect returns an iterator that iterates over the top bid
// transactions in the mempool.
AuctionBidSelect(ctx context.Context) sdkmempool.Iterator
GetBundledTransactions(tx sdk.Tx) ([][]byte, error)
WrapBundleTransaction(tx []byte) (sdk.Tx, error)
IsAuctionTx(tx sdk.Tx) (bool, error)
}
// ProposalHandler contains the functionality and handlers required to\
@@ -82,7 +87,7 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
bidTxSize := int64(len(bidTxBz))
if bidTxSize <= req.MaxTxBytes {
bundledTransactions, err := h.mempool.GetBundledTransactions(tmpBidTx)
bidInfo, err := h.mempool.GetAuctionBidInfo(tmpBidTx)
if err != nil {
// Some transactions in the bundle may be malformatted or invalid, so
// we remove the bid transaction and try the next top bid.
@@ -91,6 +96,7 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
}
// store the bytes of each ref tx as sdk.Tx bytes in order to build a valid proposal
bundledTransactions := bidInfo.Transactions
sdkTxBytes := make([][]byte, len(bundledTransactions))
// Ensure that the bundled transactions are valid
@@ -205,23 +211,21 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
isAuctionTx, err := h.mempool.IsAuctionTx(tx)
bidInfo, err := h.mempool.GetAuctionBidInfo(tx)
if err != nil {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
if isAuctionTx {
// Only the first transaction can be an auction bid tx
// If the transaction is an auction bid, then we need to ensure that it is
// the first transaction in the block proposal and that the order of
// transactions in the block proposal follows the order of transactions in
// the bid.
if bidInfo != nil {
if index != 0 {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
bundledTransactions, err := h.mempool.GetBundledTransactions(tx)
if err != nil {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
// The order of transactions in the block proposal must follow the order of transactions in the bid.
bundledTransactions := bidInfo.Transactions
if len(req.Txs) < len(bundledTransactions)+1 {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
+5 -10
View File
@@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/skip-mev/pob/mempool"
)
type (
@@ -16,8 +17,7 @@ type (
VoteExtensionMempool interface {
Remove(tx sdk.Tx) error
AuctionBidSelect(ctx context.Context) sdkmempool.Iterator
IsAuctionTx(tx sdk.Tx) (bool, error)
GetBundledTransactions(tx sdk.Tx) ([][]byte, error)
GetAuctionBidInfo(tx sdk.Tx) (*mempool.AuctionBidInfo, error)
WrapBundleTransaction(tx []byte) (sdk.Tx, error)
}
@@ -140,12 +140,12 @@ func (h *VoteExtensionHandler) resetCache(blockHeight int64) {
// verifyAuctionTx verifies a transaction against the application's state.
func (h *VoteExtensionHandler) verifyAuctionTx(ctx sdk.Context, bidTx sdk.Tx) error {
// Verify the vote extension is a auction transaction
isAuctionTx, err := h.mempool.IsAuctionTx(bidTx)
bidInfo, err := h.mempool.GetAuctionBidInfo(bidTx)
if err != nil {
return err
}
if !isAuctionTx {
if bidInfo == nil {
return fmt.Errorf("vote extension is not a valid auction transaction")
}
@@ -159,13 +159,8 @@ func (h *VoteExtensionHandler) verifyAuctionTx(ctx sdk.Context, bidTx sdk.Tx) er
return err
}
bundledTxs, err := h.mempool.GetBundledTransactions(bidTx)
if err != nil {
return err
}
// Verify all bundled transactions
for _, tx := range bundledTxs {
for _, tx := range bidInfo.Transactions {
wrappedTx, err := h.mempool.WrapBundleTransaction(tx)
if err != nil {
return err
+4 -25
View File
@@ -79,31 +79,6 @@ func (suite *ABCITestSuite) TestExtendVoteExtensionHandler() {
return nil
},
},
{
"mempool contains bid that has bundled txs that are invalid",
func() []byte {
params.ReserveFee = sdk.NewCoin("foo", sdk.NewInt(10))
err := suite.builderKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)
bidder := suite.accounts[0]
bid := params.ReserveFee.Sub(sdk.NewCoin("foo", sdk.NewInt(1)))
msgAuctionBid, err := testutils.CreateMsgAuctionBid(suite.encodingConfig.TxConfig, bidder, bid, 0, 0)
suite.Require().NoError(err)
msgAuctionBid.Transactions = [][]byte{[]byte("invalid tx")}
bidTx, err := testutils.CreateTx(suite.encodingConfig.TxConfig, bidder, 0, 10, []sdk.Msg{msgAuctionBid})
suite.Require().NoError(err)
suite.mempool = mempool.NewAuctionMempool(suite.encodingConfig.TxConfig.TxDecoder(), suite.encodingConfig.TxConfig.TxEncoder(), 0, suite.config)
err = suite.mempool.Insert(suite.ctx, bidTx)
suite.Require().NoError(err)
// this should return nothing since the top bid is not valid
return nil
},
},
{
"mempool contains bid that has an invalid timeout",
func() []byte {
@@ -126,6 +101,10 @@ func (suite *ABCITestSuite) TestExtendVoteExtensionHandler() {
{
"top bid is invalid but next best is valid",
func() []byte {
params.ReserveFee = sdk.NewCoin("foo", sdk.NewInt(100))
err := suite.builderKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)
bidder := suite.accounts[0]
bid := suite.auctionBidAmount.Add(suite.minBidIncrement)
signers := []testutils.Account{bidder}