Skip to content

Commit

Permalink
validate bundler txs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay committed Oct 12, 2023
1 parent 96ed47c commit e61327a
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 560 deletions.
2 changes: 1 addition & 1 deletion lanes/mev/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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
}
6 changes: 3 additions & 3 deletions tests/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(), // This means the lane has no limit on block space.
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"), // This means the lane has no limit on block space.
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0, // This means the lane has no limit on the number of transactions it can store.
}
Expand All @@ -282,7 +282,7 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0,
}
Expand All @@ -297,7 +297,7 @@ func New(
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.6"),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
MaxTxs: 0,
}
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 @@ -8,6 +8,7 @@ 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"

"github.com/skip-mev/block-sdk/tests/integration"
Expand All @@ -16,7 +17,7 @@ import (

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

0 comments on commit e61327a

Please sign in to comment.