Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

bundle specific mutex #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ type TxPool struct {
scope event.SubscriptionScope
signer types.Signer
mu sync.RWMutex
bmu sync.RWMutex

istanbul bool // Fork indicator whether we are in the istanbul stage.
eip2718 bool // Fork indicator whether we are using EIP-2718 type transactions.
Expand Down Expand Up @@ -361,8 +362,8 @@ type IFetcher interface {
}

func (pool *TxPool) RegisterBundleFetcher(fetcher IFetcher) {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.bmu.Lock()
defer pool.bmu.Unlock()

pool.bundleFetcher = fetcher
}
Expand Down Expand Up @@ -665,8 +666,8 @@ func resolveCancellableBundles(lubCh chan []types.LatestUuidBundle, errCh chan e
// also prunes bundles that are outdated
// Returns regular bundles and a function resolving to current cancellable bundles
func (pool *TxPool) MevBundles(blockNumber *big.Int, blockTimestamp uint64) ([]types.MevBundle, chan []types.MevBundle) {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.bmu.Lock()
defer pool.bmu.Unlock()

ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
lubCh, errCh := pool.fetchLatestCancellableBundles(ctx, blockNumber)
Expand Down Expand Up @@ -719,8 +720,8 @@ func (pool *TxPool) MevBundles(blockNumber *big.Int, blockTimestamp uint64) ([]t

// AddMevBundles adds a mev bundles to the pool
func (pool *TxPool) AddMevBundles(mevBundles []types.MevBundle) error {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.bmu.Lock()
defer pool.bmu.Unlock()

pool.mevBundles = append(pool.mevBundles, mevBundles...)
return nil
Expand All @@ -734,8 +735,8 @@ func (pool *TxPool) AddMevBundle(txs types.Transactions, blockNumber *big.Int, r
}
bundleHash := common.BytesToHash(bundleHasher.Sum(nil))

pool.mu.Lock()
defer pool.mu.Unlock()
pool.bmu.Lock()
defer pool.bmu.Unlock()

pool.mevBundles = append(pool.mevBundles, types.MevBundle{
Txs: txs,
Expand Down
4 changes: 3 additions & 1 deletion core/txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,9 @@ func TestSlotCount(t *testing.T) {
func TestBundleCancellations(t *testing.T) {
// Create the pool to test the status retrievals with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{100, statedb, new(event.Feed)}
gasLimit := atomic.Uint64{}
gasLimit.Store(uint64(100))
blockchain := &testBlockChain{gasLimit, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
fetcher := &mockFetcher{make(map[int64]error), make(map[int64][]types.LatestUuidBundle)}
Expand Down