Skip to content

Commit

Permalink
Adjust block number for bundle fetching (ethereum#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteri authored and avalonche committed Feb 6, 2023
1 parent 75edca8 commit 1a07e49
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions flashbotsextra/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (b *bundleFetcher) Run() {
eventCh := make(chan core.ChainHeadEvent)
b.backend.BlockChain().SubscribeChainHeadEvent(eventCh)
pushBlockNum := func() {
for blockNum := range eventCh {
b.blockNumCh <- blockNum.Block.Header().Number.Int64()
for currentBlockNum := range eventCh {
b.blockNumCh <- currentBlockNum.Block.Header().Number.Int64()
}
}
addMevBundle := func() {
Expand Down Expand Up @@ -75,37 +75,37 @@ func (b *bundleFetcher) Run() {
}

func (b *bundleFetcher) fetchAndPush(ctx context.Context, pushMevBundles func(bundles []DbBundle)) {
var blockNum int64
var currentBlockNum int64
lowPrioBundleTicker := time.NewTicker(time.Second * 2)
defer lowPrioBundleTicker.Stop()

for {
select {
case blockNum = <-b.blockNumCh:
case currentBlockNum = <-b.blockNumCh:
ctxH, cancelH := context.WithTimeout(ctx, time.Second*3)
bundles, err := b.db.GetPriorityBundles(ctxH, blockNum, true)
bundles, err := b.db.GetPriorityBundles(ctxH, currentBlockNum+1, true)
cancelH()
if err != nil {
log.Error("failed to fetch high prio bundles", "err", err)
continue
}
log.Info("Fetching High prio bundles", "size", len(bundles), "blockNum", blockNum)
log.Info("Fetching High prio bundles", "size", len(bundles), "currentlyBuiltBlockNum", currentBlockNum+1)
if len(bundles) != 0 {
pushMevBundles(bundles)
}

case <-lowPrioBundleTicker.C:
if blockNum == 0 {
if currentBlockNum == 0 {
continue
}
ctxL, cancelL := context.WithTimeout(ctx, time.Second*3)
bundles, err := b.db.GetPriorityBundles(ctxL, blockNum, false)
bundles, err := b.db.GetPriorityBundles(ctxL, currentBlockNum+1, false)
cancelL()
if err != nil {
log.Error("failed to fetch low prio bundles", "err", err)
continue
}
log.Info("Fetching low prio bundles", "len", len(bundles), "blockNum", blockNum)
log.Info("Fetching low prio bundles", "len", len(bundles), "currentlyBuiltBlockNum", currentBlockNum+1)
if len(bundles) != 0 {
pushMevBundles(bundles)
}
Expand Down

0 comments on commit 1a07e49

Please sign in to comment.