-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(op-geth): support droppingTxHashes when sendBundle #240
base: develop
Are you sure you want to change the base?
Changes from 10 commits
5bd2b5a
6bbc128
7012e8a
faf00f9
e034bc5
a7f7530
a8a1acc
20adb95
bc0cd43
9a3cc41
5d93678
f1e1585
a661ba7
3fdd424
d4c6fef
41fb2c1
6c4bf32
97311c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,10 @@ func (p *BundlePool) reset(newHead *types.Header) { | |
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
if len(p.bundles) == 0 { | ||
return | ||
} | ||
|
||
// Prune outdated bundles and invalid bundles | ||
block := p.chain.GetBlock(newHead.Hash(), newHead.Number.Uint64()) | ||
txSet := mapset.NewSet[common.Hash]() | ||
|
@@ -370,16 +374,27 @@ func (p *BundlePool) reset(newHead *types.Header) { | |
txSet.Add(tx.Hash()) | ||
} | ||
} | ||
var wg sync.WaitGroup | ||
for hash, bundle := range p.bundles { | ||
if (bundle.MaxTimestamp != 0 && newHead.Time > bundle.MaxTimestamp) || | ||
(bundle.MaxBlockNumber != 0 && newHead.Number.Cmp(new(big.Int).SetUint64(bundle.MaxBlockNumber)) > 0) { | ||
p.slots -= numSlots(p.bundles[hash]) | ||
delete(p.bundles, hash) | ||
} else if txSet.Contains(bundle.Txs[0].Hash()) { | ||
p.slots -= numSlots(p.bundles[hash]) | ||
delete(p.bundles, hash) | ||
} | ||
wg.Add(1) | ||
go func(hash common.Hash, bundle *types.Bundle) { | ||
defer wg.Done() | ||
if (bundle.MaxTimestamp != 0 && newHead.Time > bundle.MaxTimestamp) || | ||
(bundle.MaxBlockNumber != 0 && newHead.Number.Cmp(new(big.Int).SetUint64(bundle.MaxBlockNumber)) > 0) { | ||
p.slots -= numSlots(p.bundles[hash]) | ||
delete(p.bundles, hash) | ||
} else { | ||
for _, tx := range bundle.Txs { | ||
if txSet.Contains(tx.Hash()) && !containsHash(bundle.DroppingTxHashes, tx.Hash()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend maintain unDroppableTxHashesSet as a cache, we can use it here and in the check of simulation, avoid iterate the slice again and again. |
||
p.slots -= numSlots(p.bundles[hash]) | ||
delete(p.bundles, hash) | ||
break | ||
} | ||
} | ||
} | ||
}(hash, bundle) | ||
} | ||
wg.Wait() | ||
bundleGauge.Update(int64(len(p.bundles))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need these 2 lines if we early return when len(p.bundles) == 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
slotsGauge.Update(int64(p.slots)) | ||
} | ||
|
@@ -447,6 +462,15 @@ func numSlots(bundle *types.Bundle) uint64 { | |
return (bundle.Size() + bundleSlotSize - 1) / bundleSlotSize | ||
} | ||
|
||
func containsHash(arr []common.Hash, match common.Hash) bool { | ||
for _, elem := range arr { | ||
if elem == match { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// ===================================================================================================================== | ||
|
||
type BundleHeap []*types.Bundle | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it thread safe to do
p.slots -=
anddelete(p.bundles, hash)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
reset
function itself is thread safe since we havein the beginning of the function.
However, if you use go func here, it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed go func, just use single thread.