Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auction): Adding extra check on bundler timeouts (backport #156) #157

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lanes/mev/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (handler *CheckTxHandler) CheckTx() CheckTx {
"bid_height", bidInfo.Timeout,
"bidder", bidInfo.Bidder,
"bid", bidInfo.Bid,
"removing tx from mempool", true,
"is_recheck_tx", ctx.IsReCheckTx(),
)

// attempt to remove the bid from the MEVLane (if it exists)
Expand Down
57 changes: 38 additions & 19 deletions lanes/mev/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,57 +79,76 @@ func (config *DefaultAuctionFactory) GetAuctionBidInfo(tx sdk.Tx) (*types.BidInf
return nil, fmt.Errorf("invalid bidder address (%s): %w", msg.Bidder, err)
}

timeoutTx, ok := tx.(TxWithTimeoutHeight)
if !ok {
return nil, fmt.Errorf("cannot extract timeout; transaction does not implement TxWithTimeoutHeight")
height, err := config.GetTimeoutHeight(tx)
if err != nil {
return nil, err
}

signers, err := config.getBundleSigners(msg.Transactions)
signers, timeouts, err := config.getBundleInfo(msg.Transactions)
if err != nil {
return nil, err
}

return &types.BidInfo{
Bid: msg.Bid,
Bidder: bidder,
Transactions: msg.Transactions,
Timeout: timeoutTx.GetTimeoutHeight(),
Signers: signers,
Bid: msg.Bid,
Bidder: bidder,
Transactions: msg.Transactions,
TransactionTimeouts: timeouts,
Timeout: height,
Signers: signers,
}, nil
}

// GetTimeoutHeight returns the timeout height of the transaction.
func (config *DefaultAuctionFactory) GetTimeoutHeight(tx sdk.Tx) (uint64, error) {
timeoutTx, ok := tx.(TxWithTimeoutHeight)
if !ok {
return 0, fmt.Errorf("cannot extract timeout; transaction does not implement TxWithTimeoutHeight")
}

return timeoutTx.GetTimeoutHeight(), nil
}

// MatchHandler defines a default function that checks if a transaction matches the mev lane.
func (config *DefaultAuctionFactory) MatchHandler() base.MatchHandler {
return func(ctx sdk.Context, tx sdk.Tx) bool {
bidInfo, err := config.GetAuctionBidInfo(tx)
return bidInfo != nil && err == nil
}
}

// getBundleSigners defines a default function that returns the signers of all transactions in
// a bundle. In the default case, each bundle transaction will be an sdk.Tx and the
// signers are the signers of each sdk.Msg in the transaction.
func (config *DefaultAuctionFactory) getBundleSigners(bundle [][]byte) ([]map[string]struct{}, error) {
bundleSigners := make([]map[string]struct{}, 0)
// getBundleInfo defines a default function that returns the signers of all transactions in
// a bundle as well as each bundled txs timeout. In the default case, each bundle transaction
// will be an sdk.Tx and the signers are the signers of each sdk.Msg in the transaction.
func (config *DefaultAuctionFactory) getBundleInfo(bundle [][]byte) ([]map[string]struct{}, []uint64, error) {
bundleSigners := make([]map[string]struct{}, len(bundle))
timeouts := make([]uint64, len(bundle))

for _, tx := range bundle {
for index, tx := range bundle {
sdkTx, err := config.txDecoder(tx)
if err != nil {
return nil, err
return nil, nil, err
}

txSigners := make(map[string]struct{})

signers, err := config.signerExtractor.GetSigners(sdkTx)
if err != nil {
return nil, err
return nil, nil, err
}

for _, signer := range signers {
txSigners[signer.Signer.String()] = struct{}{}
}

bundleSigners = append(bundleSigners, txSigners)
timeout, err := config.GetTimeoutHeight(sdkTx)
if err != nil {
return nil, nil, err
}

bundleSigners[index] = txSigners
timeouts[index] = timeout
}

return bundleSigners, nil
return bundleSigners, timeouts, nil
}
13 changes: 7 additions & 6 deletions tests/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"

"cosmossdk.io/depinject"
"cosmossdk.io/math"
dbm "github.com/cometbft/cometbft-db"
cometabci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -272,9 +273,9 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: sdk.ZeroDec(), // This means the lane has no limit on block space.
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0, // This means the lane has no limit on the number of transactions it can store.
MaxTxs: 1000,
}
mevLane := mev.NewMEVLane(
mevConfig,
Expand All @@ -286,9 +287,9 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: sdk.ZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0,
MaxTxs: 1000,
}
freeLane := free.NewFreeLane(
freeConfig,
Expand All @@ -301,9 +302,9 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: sdk.ZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.6"),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0,
MaxTxs: 1000,
}
defaultLane := defaultlane.NewDefaultLane(defaultConfig)

Expand Down
8 changes: 7 additions & 1 deletion tests/integration/block_sdk_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/suite"

auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

var (
// config params
numValidators = 4
numValidators = 1
numFullNodes = 0
denom = "stake"

Expand All @@ -36,6 +37,10 @@ var (
},
}

consensusParams = ictestutil.Toml{
"timeout_commit": "3500ms",
}

// interchain specification
spec = &interchaintest.ChainSpec{
ChainName: "block-sdk",
Expand Down Expand Up @@ -63,6 +68,7 @@ var (
NoHostMount: noHostMount,
UsingNewGenesisCommand: true,
ModifyGenesis: cosmos.ModifyGenesis(genesisKV),
ConfigFileOverrides: map[string]any{"config/config.toml": ictestutil.Toml{"consensus": consensusParams}},
},
}
)
Expand Down
Loading
Loading