diff --git a/cosmos/x/evm/plugins/txpool/plugin.go b/cosmos/x/evm/plugins/txpool/plugin.go index e7c3d941e..36e76d921 100644 --- a/cosmos/x/evm/plugins/txpool/plugin.go +++ b/cosmos/x/evm/plugins/txpool/plugin.go @@ -26,11 +26,13 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gofrs/uuid" "github.com/ethereum/go-ethereum/event" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins" mempool "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/txpool/mempool" + "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core" coretypes "pkg.berachain.dev/polaris/eth/core/types" errorslib "pkg.berachain.dev/polaris/lib/errors" @@ -124,4 +126,16 @@ func (p *plugin) SendPrivTx(signedTx *coretypes.Transaction) error { return p.EthTxPool.Insert(sdk.Context{}.WithPriority(signedTx.GasPrice().Int64()), cosmosTx) } +func (p *plugin) SendBundle(txs coretypes.Transactions, blockNumber int64, uuid uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error { + /* + Serialize the transactions to SdkTx + + send the bundle to the skip auction mempool (ok what goes here?) + + gg ez? + + */ + return nil +} + func (p *plugin) IsPlugin() {} diff --git a/eth/core/chain_writer.go b/eth/core/chain_writer.go index 8f8d18a4c..bed13a3c9 100644 --- a/eth/core/chain_writer.go +++ b/eth/core/chain_writer.go @@ -24,6 +24,8 @@ import ( "context" "math/big" + "github.com/gofrs/uuid" + "github.com/ethereum/go-ethereum/core/vm" "pkg.berachain.dev/polaris/eth/common" @@ -42,6 +44,10 @@ type ChainWriter interface { Finalize(context.Context) error // SendTx sends the given transaction to the tx pool. SendTx(ctx context.Context, signedTx *types.Transaction) error + // SendPrivTx privately sends the given transaction to the tx pool. + SendPrivTx(ctx context.Context, signedPrivTx *types.Transaction) error + // SendBundle sends the given bundle to the tx pool. + SendBundle(ctx context.Context, txs types.Transactions, blockNumber int64, uuid uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error } // ========================================================================= @@ -183,3 +189,11 @@ func (bc *blockchain) Finalize(ctx context.Context) error { func (bc *blockchain) SendTx(_ context.Context, signedTx *types.Transaction) error { return bc.tp.SendTx(signedTx) } + +func (bc *blockchain) SendPrivTx(_ context.Context, signedPrivTx *types.Transaction) error { + return bc.tp.SendPrivTx(signedPrivTx) +} + +func (bc *blockchain) SendBundle(_ context.Context, txs types.Transactions, blockNumber int64, uuid uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error { + return bc.tp.SendBundle(txs, blockNumber, uuid, signingAddress, minTimestamp, maxTimestamp, revertingTxHashes) +} diff --git a/eth/core/host.go b/eth/core/host.go index 5ef8572f9..426dc862e 100644 --- a/eth/core/host.go +++ b/eth/core/host.go @@ -23,6 +23,8 @@ package core import ( "math/big" + "github.com/gofrs/uuid" + "github.com/ethereum/go-ethereum/event" "pkg.berachain.dev/polaris/eth/common" @@ -129,6 +131,10 @@ type ( TxPoolPlugin interface { // SendTx submits the tx to the transaction pool. SendTx(tx *types.Transaction) error + // SendPrivTx sends a private transaction to the transaction pool. + SendPrivTx(tx *types.Transaction) error + // SendBundle sends a bundle of transactions to the transaction pool. + SendBundle(txs types.Transactions, blockNumber int64, uuid uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error // Pending returns all pending transactions in the transaction pool. Pending(bool) map[common.Address]types.Transactions // Get returns the transaction from the pool with the given hash. diff --git a/eth/core/mock/txpool_plugin.mock.go b/eth/core/mock/txpool_plugin.mock.go index dc35e7deb..29bd4b45b 100644 --- a/eth/core/mock/txpool_plugin.mock.go +++ b/eth/core/mock/txpool_plugin.mock.go @@ -8,6 +8,7 @@ import ( ethereumcore "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/gofrs/uuid" ethcore "pkg.berachain.dev/polaris/eth/core" "sync" ) @@ -37,6 +38,12 @@ var _ ethcore.TxPoolPlugin = &TxPoolPluginMock{} // PendingFunc: func(b bool) map[common.Address]types.Transactions { // panic("mock out the Pending method") // }, +// SendBundleFunc: func(txs types.Transactions, blockNumber int64, uuidMoqParam uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error { +// panic("mock out the SendBundle method") +// }, +// SendPrivTxFunc: func(tx *types.Transaction) error { +// panic("mock out the SendPrivTx method") +// }, // SendTxFunc: func(tx *types.Transaction) error { // panic("mock out the SendTx method") // }, @@ -68,6 +75,12 @@ type TxPoolPluginMock struct { // PendingFunc mocks the Pending method. PendingFunc func(b bool) map[common.Address]types.Transactions + // SendBundleFunc mocks the SendBundle method. + SendBundleFunc func(txs types.Transactions, blockNumber int64, uuidMoqParam uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error + + // SendPrivTxFunc mocks the SendPrivTx method. + SendPrivTxFunc func(tx *types.Transaction) error + // SendTxFunc mocks the SendTx method. SendTxFunc func(tx *types.Transaction) error @@ -102,6 +115,28 @@ type TxPoolPluginMock struct { // B is the b argument value. B bool } + // SendBundle holds details about calls to the SendBundle method. + SendBundle []struct { + // Txs is the txs argument value. + Txs types.Transactions + // BlockNumber is the blockNumber argument value. + BlockNumber int64 + // UuidMoqParam is the uuidMoqParam argument value. + UuidMoqParam uuid.UUID + // SigningAddress is the signingAddress argument value. + SigningAddress common.Address + // MinTimestamp is the minTimestamp argument value. + MinTimestamp uint64 + // MaxTimestamp is the maxTimestamp argument value. + MaxTimestamp uint64 + // RevertingTxHashes is the revertingTxHashes argument value. + RevertingTxHashes []common.Hash + } + // SendPrivTx holds details about calls to the SendPrivTx method. + SendPrivTx []struct { + // Tx is the tx argument value. + Tx *types.Transaction + } // SendTx holds details about calls to the SendTx method. SendTx []struct { // Tx is the tx argument value. @@ -121,6 +156,8 @@ type TxPoolPluginMock struct { lockGet sync.RWMutex lockNonce sync.RWMutex lockPending sync.RWMutex + lockSendBundle sync.RWMutex + lockSendPrivTx sync.RWMutex lockSendTx sync.RWMutex lockStats sync.RWMutex lockSubscribeNewTxsEvent sync.RWMutex @@ -281,6 +318,94 @@ func (mock *TxPoolPluginMock) PendingCalls() []struct { return calls } +// SendBundle calls SendBundleFunc. +func (mock *TxPoolPluginMock) SendBundle(txs types.Transactions, blockNumber int64, uuidMoqParam uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error { + if mock.SendBundleFunc == nil { + panic("TxPoolPluginMock.SendBundleFunc: method is nil but TxPoolPlugin.SendBundle was just called") + } + callInfo := struct { + Txs types.Transactions + BlockNumber int64 + UuidMoqParam uuid.UUID + SigningAddress common.Address + MinTimestamp uint64 + MaxTimestamp uint64 + RevertingTxHashes []common.Hash + }{ + Txs: txs, + BlockNumber: blockNumber, + UuidMoqParam: uuidMoqParam, + SigningAddress: signingAddress, + MinTimestamp: minTimestamp, + MaxTimestamp: maxTimestamp, + RevertingTxHashes: revertingTxHashes, + } + mock.lockSendBundle.Lock() + mock.calls.SendBundle = append(mock.calls.SendBundle, callInfo) + mock.lockSendBundle.Unlock() + return mock.SendBundleFunc(txs, blockNumber, uuidMoqParam, signingAddress, minTimestamp, maxTimestamp, revertingTxHashes) +} + +// SendBundleCalls gets all the calls that were made to SendBundle. +// Check the length with: +// +// len(mockedTxPoolPlugin.SendBundleCalls()) +func (mock *TxPoolPluginMock) SendBundleCalls() []struct { + Txs types.Transactions + BlockNumber int64 + UuidMoqParam uuid.UUID + SigningAddress common.Address + MinTimestamp uint64 + MaxTimestamp uint64 + RevertingTxHashes []common.Hash +} { + var calls []struct { + Txs types.Transactions + BlockNumber int64 + UuidMoqParam uuid.UUID + SigningAddress common.Address + MinTimestamp uint64 + MaxTimestamp uint64 + RevertingTxHashes []common.Hash + } + mock.lockSendBundle.RLock() + calls = mock.calls.SendBundle + mock.lockSendBundle.RUnlock() + return calls +} + +// SendPrivTx calls SendPrivTxFunc. +func (mock *TxPoolPluginMock) SendPrivTx(tx *types.Transaction) error { + if mock.SendPrivTxFunc == nil { + panic("TxPoolPluginMock.SendPrivTxFunc: method is nil but TxPoolPlugin.SendPrivTx was just called") + } + callInfo := struct { + Tx *types.Transaction + }{ + Tx: tx, + } + mock.lockSendPrivTx.Lock() + mock.calls.SendPrivTx = append(mock.calls.SendPrivTx, callInfo) + mock.lockSendPrivTx.Unlock() + return mock.SendPrivTxFunc(tx) +} + +// SendPrivTxCalls gets all the calls that were made to SendPrivTx. +// Check the length with: +// +// len(mockedTxPoolPlugin.SendPrivTxCalls()) +func (mock *TxPoolPluginMock) SendPrivTxCalls() []struct { + Tx *types.Transaction +} { + var calls []struct { + Tx *types.Transaction + } + mock.lockSendPrivTx.RLock() + calls = mock.calls.SendPrivTx + mock.lockSendPrivTx.RUnlock() + return calls +} + // SendTx calls SendTxFunc. func (mock *TxPoolPluginMock) SendTx(tx *types.Transaction) error { if mock.SendTxFunc == nil { diff --git a/eth/go.mod b/eth/go.mod index bf0209889..4e622d4f4 100644 --- a/eth/go.mod +++ b/eth/go.mod @@ -8,6 +8,7 @@ replace github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0. require ( github.com/BurntSushi/toml v1.2.1 github.com/ethereum/go-ethereum v1.11.4 + github.com/gofrs/uuid v3.3.0+incompatible github.com/onsi/ginkgo/v2 v2.9.5 github.com/onsi/gomega v1.27.6 golang.org/x/text v0.9.0 diff --git a/eth/go.sum b/eth/go.sum index e48d01784..b714556c9 100644 --- a/eth/go.sum +++ b/eth/go.sum @@ -165,6 +165,7 @@ github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6Wezm github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= +github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= diff --git a/eth/rpc/backend.go b/eth/rpc/backend.go index b765b8274..5a8bb4c5a 100644 --- a/eth/rpc/backend.go +++ b/eth/rpc/backend.go @@ -27,6 +27,8 @@ import ( "math/big" "time" + "github.com/gofrs/uuid" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/consensus" @@ -455,6 +457,14 @@ func (b *backend) SendTx(ctx context.Context, signedTx *types.Transaction) error return b.chain.SendTx(ctx, signedTx) } +func (b *backend) SendPrivTx(ctx context.Context, signedPrivTx *types.Transaction) error { + return b.chain.SendPrivTx(ctx, signedPrivTx) +} + +func (b *backend) SendBundle(ctx context.Context, txs types.Transactions, blockNumber int64, uuid uuid.UUID, signingAddress common.Address, minTimestamp uint64, maxTimestamp uint64, revertingTxHashes []common.Hash) error { + return b.chain.SendBundle(ctx, txs, blockNumber, uuid, signingAddress, minTimestamp, maxTimestamp, revertingTxHashes) +} + func (b *backend) GetPoolTransactions() (types.Transactions, error) { b.logger.Info("called eth.rpc.backend.GetPoolTransactions") return b.chain.GetPoolTransactions()