From 1a07e49c9ce09daef13ae51a2737e6e2541cbab1 Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Wed, 21 Sep 2022 18:32:01 +0200 Subject: [PATCH] Adjust block number for bundle fetching (#32) --- flashbotsextra/fetcher.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flashbotsextra/fetcher.go b/flashbotsextra/fetcher.go index 05e01c4a858a..956698bc1582 100644 --- a/flashbotsextra/fetcher.go +++ b/flashbotsextra/fetcher.go @@ -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() { @@ -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) }