feat(adapters): Add SignerExtractionAdapter [ENG-1916] (#114)
* add a signer-extraction-adapter * linting * feat(adapters/mev-lane): Use the SignerExtractionAdapter in the Mev-Lane [ENG-1917] (#115) * use SignerExtractionAdapter in the Factory * feat(e2e): block sdk integration updates (#122) * cherry-pick from injective * remove transactions from app-side mempool on failed re-checktx
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
|
||||
"github.com/skip-mev/block-sdk/block"
|
||||
"github.com/skip-mev/block-sdk/block/base"
|
||||
"github.com/skip-mev/block-sdk/block/utils/mocks"
|
||||
@@ -509,6 +510,7 @@ func (s *BaseTestSuite) initLane(
|
||||
s.encodingConfig.TxConfig.TxEncoder(),
|
||||
s.encodingConfig.TxConfig.TxDecoder(),
|
||||
s.setUpAnteHandler(expectedExecution),
|
||||
signer_extraction.NewDefaultAdapter(),
|
||||
maxBlockSpace,
|
||||
)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ func NewDefaultLane(cfg base.LaneConfig) *DefaultLane {
|
||||
base.NewMempool[string](
|
||||
base.DefaultTxPriority(),
|
||||
cfg.TxEncoder,
|
||||
cfg.SignerExtractor,
|
||||
cfg.MaxTxs,
|
||||
),
|
||||
base.DefaultMatchHandler(),
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
|
||||
"github.com/skip-mev/block-sdk/block/base"
|
||||
testutils "github.com/skip-mev/block-sdk/testutils"
|
||||
)
|
||||
@@ -85,7 +86,7 @@ func (s *BaseTestSuite) TestCompareTxPriority() {
|
||||
}
|
||||
|
||||
func (s *BaseTestSuite) TestInsert() {
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3)
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), signer_extraction.NewDefaultAdapter(), 3)
|
||||
|
||||
s.Run("should be able to insert a transaction", func() {
|
||||
tx, err := testutils.CreateRandomTx(
|
||||
@@ -137,7 +138,7 @@ func (s *BaseTestSuite) TestInsert() {
|
||||
}
|
||||
|
||||
func (s *BaseTestSuite) TestRemove() {
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3)
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), signer_extraction.NewDefaultAdapter(), 3)
|
||||
|
||||
s.Run("should be able to remove a transaction", func() {
|
||||
tx, err := testutils.CreateRandomTx(
|
||||
@@ -175,7 +176,7 @@ func (s *BaseTestSuite) TestRemove() {
|
||||
|
||||
func (s *BaseTestSuite) TestSelect() {
|
||||
s.Run("should be able to select transactions in the correct order", func() {
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3)
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), signer_extraction.NewDefaultAdapter(), 3)
|
||||
|
||||
tx1, err := testutils.CreateRandomTx(
|
||||
s.encodingConfig.TxConfig,
|
||||
@@ -214,7 +215,7 @@ func (s *BaseTestSuite) TestSelect() {
|
||||
})
|
||||
|
||||
s.Run("should be able to select a single transaction", func() {
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3)
|
||||
mempool := base.NewMempool[string](base.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), signer_extraction.NewDefaultAdapter(), 3)
|
||||
|
||||
tx1, err := testutils.CreateRandomTx(
|
||||
s.encodingConfig.TxConfig,
|
||||
|
||||
@@ -33,6 +33,7 @@ func NewFreeLane(
|
||||
base.NewMempool[string](
|
||||
txPriority,
|
||||
cfg.TxEncoder,
|
||||
cfg.SignerExtractor,
|
||||
cfg.MaxTxs,
|
||||
),
|
||||
matchFn,
|
||||
|
||||
+22
-4
@@ -118,7 +118,7 @@ func (handler *CheckTxHandler) CheckTx() CheckTx {
|
||||
0,
|
||||
nil,
|
||||
false,
|
||||
), err
|
||||
), nil
|
||||
}
|
||||
|
||||
// Attempt to get the bid info of the transaction.
|
||||
@@ -135,7 +135,7 @@ func (handler *CheckTxHandler) CheckTx() CheckTx {
|
||||
0,
|
||||
nil,
|
||||
false,
|
||||
), err
|
||||
), nil
|
||||
}
|
||||
|
||||
// If this is not a bid transaction, we just execute it normally.
|
||||
@@ -162,17 +162,35 @@ func (handler *CheckTxHandler) CheckTx() CheckTx {
|
||||
handler.baseApp.Logger().Info(
|
||||
"invalid bid tx",
|
||||
"err", err,
|
||||
"tx", req.Tx,
|
||||
"removing tx from mempool", true,
|
||||
)
|
||||
|
||||
// attempt to remove the bid from the MEVLane (if it exists)
|
||||
if handler.mevLane.Contains(tx) {
|
||||
if err := handler.mevLane.Remove(tx); err != nil {
|
||||
handler.baseApp.Logger().Error(
|
||||
"failed to remove bid transaction from mev-lane",
|
||||
"err", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return sdkerrors.ResponseCheckTxWithEvents(
|
||||
fmt.Errorf("invalid bid tx: %w", err),
|
||||
gasInfo.GasWanted,
|
||||
gasInfo.GasUsed,
|
||||
nil,
|
||||
false,
|
||||
), err
|
||||
), nil
|
||||
}
|
||||
|
||||
handler.baseApp.Logger().Info(
|
||||
"valid bid tx",
|
||||
"tx", req.Tx,
|
||||
"inserting tx into mempool", true,
|
||||
)
|
||||
|
||||
// If the bid transaction is valid, we know we can insert it into the mempool for consideration in the next block.
|
||||
if err := handler.mevLane.Insert(ctx, tx); err != nil {
|
||||
handler.baseApp.Logger().Info(
|
||||
@@ -186,7 +204,7 @@ func (handler *CheckTxHandler) CheckTx() CheckTx {
|
||||
gasInfo.GasUsed,
|
||||
nil,
|
||||
false,
|
||||
), err
|
||||
), nil
|
||||
}
|
||||
|
||||
return &cometabci.ResponseCheckTx{
|
||||
|
||||
+8
-11
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||
|
||||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
|
||||
"github.com/skip-mev/block-sdk/block/base"
|
||||
"github.com/skip-mev/block-sdk/x/auction/types"
|
||||
)
|
||||
@@ -30,7 +30,8 @@ type (
|
||||
|
||||
// DefaultAuctionFactory defines a default implmentation for the auction factory interface for processing auction transactions.
|
||||
DefaultAuctionFactory struct {
|
||||
txDecoder sdk.TxDecoder
|
||||
txDecoder sdk.TxDecoder
|
||||
signerExtractor signer_extraction.Adapter
|
||||
}
|
||||
|
||||
// TxWithTimeoutHeight is used to extract timeouts from sdk.Tx transactions. In the case where,
|
||||
@@ -45,9 +46,10 @@ type (
|
||||
var _ Factory = (*DefaultAuctionFactory)(nil)
|
||||
|
||||
// NewDefaultAuctionFactory returns a default auction factory interface implementation.
|
||||
func NewDefaultAuctionFactory(txDecoder sdk.TxDecoder) Factory {
|
||||
func NewDefaultAuctionFactory(txDecoder sdk.TxDecoder, extractor signer_extraction.Adapter) Factory {
|
||||
return &DefaultAuctionFactory{
|
||||
txDecoder: txDecoder,
|
||||
txDecoder: txDecoder,
|
||||
signerExtractor: extractor,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,20 +117,15 @@ func (config *DefaultAuctionFactory) getBundleSigners(bundle [][]byte) ([]map[st
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sigTx, ok := sdkTx.(signing.SigVerifiableTx)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("transaction is not valid")
|
||||
}
|
||||
|
||||
txSigners := make(map[string]struct{})
|
||||
|
||||
signers, err := sigTx.GetSigners()
|
||||
signers, err := config.signerExtractor.GetSigners(sdkTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, signer := range signers {
|
||||
txSigners[sdk.AccAddress(signer).String()] = struct{}{}
|
||||
txSigners[signer.Signer.String()] = struct{}{}
|
||||
}
|
||||
|
||||
bundleSigners = append(bundleSigners, txSigners)
|
||||
|
||||
@@ -53,6 +53,7 @@ func NewMEVLane(
|
||||
base.NewMempool[string](
|
||||
TxPriority(factory),
|
||||
cfg.TxEncoder,
|
||||
cfg.SignerExtractor,
|
||||
cfg.MaxTxs,
|
||||
),
|
||||
factory.MatchHandler(),
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
|
||||
"github.com/skip-mev/block-sdk/lanes/mev"
|
||||
testutils "github.com/skip-mev/block-sdk/testutils"
|
||||
)
|
||||
@@ -32,7 +33,7 @@ func TestMempoolTestSuite(t *testing.T) {
|
||||
func (suite *MEVTestSuite) SetupTest() {
|
||||
// Mempool setup
|
||||
suite.encCfg = testutils.CreateTestEncodingConfig()
|
||||
suite.config = mev.NewDefaultAuctionFactory(suite.encCfg.TxConfig.TxDecoder())
|
||||
suite.config = mev.NewDefaultAuctionFactory(suite.encCfg.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter())
|
||||
suite.ctx = sdk.NewContext(nil, cmtproto.Header{}, false, log.NewTestLogger(suite.T()))
|
||||
|
||||
// Init accounts
|
||||
|
||||
Reference in New Issue
Block a user