@@ -29,6 +29,8 @@ import (
2929 "github.com/flashbots/go-boost-utils/utils"
3030 "github.com/holiman/uint256"
3131 "golang.org/x/time/rate"
32+
33+ "github.com/cenkalti/backoff/v4"
3234)
3335
3436const (
@@ -64,6 +66,7 @@ type IBuilder interface {
6466
6567type Builder struct {
6668 ds flashbotsextra.IDatabaseService
69+ blockConsumer flashbotsextra.BlockConsumer
6770 relay IRelay
6871 eth IEthereumService
6972 dryRun bool
@@ -91,6 +94,7 @@ type Builder struct {
9194type BuilderArgs struct {
9295 sk * bls.SecretKey
9396 ds flashbotsextra.IDatabaseService
97+ blockConsumer flashbotsextra.BlockConsumer
9498 relay IRelay
9599 builderSigningDomain phase0.Domain
96100 builderBlockResubmitInterval time.Duration
@@ -130,6 +134,7 @@ func NewBuilder(args BuilderArgs) (*Builder, error) {
130134 slotCtx , slotCtxCancel := context .WithCancel (context .Background ())
131135 return & Builder {
132136 ds : args .ds ,
137+ blockConsumer : args .blockConsumer ,
133138 relay : args .relay ,
134139 eth : args .eth ,
135140 dryRun : args .dryRun ,
@@ -267,7 +272,7 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, blockValue *big.Int,
267272 log .Error ("could not validate bellatrix block" , "err" , err )
268273 }
269274 } else {
270- go b .ds . ConsumeBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , usedSbundles , & blockBidMsg )
275+ go b .processBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , usedSbundles , & blockBidMsg )
271276 err = b .relay .SubmitBlock (& blockSubmitReq , vd )
272277 if err != nil {
273278 log .Error ("could not submit bellatrix block" , "err" , err , "#commitedBundles" , len (commitedBundles ))
@@ -326,7 +331,7 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or
326331 log .Error ("could not validate block for capella" , "err" , err )
327332 }
328333 } else {
329- go b .ds . ConsumeBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , usedSbundles , & blockBidMsg )
334+ go b .processBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , usedSbundles , & blockBidMsg )
330335 err = b .relay .SubmitBlockCapella (& blockSubmitReq , vd )
331336 if err != nil {
332337 log .Error ("could not submit capella block" , "err" , err , "#commitedBundles" , len (commitedBundles ))
@@ -338,6 +343,19 @@ func (b *Builder) submitCapellaBlock(block *types.Block, blockValue *big.Int, or
338343 return nil
339344}
340345
346+ func (b * Builder ) processBuiltBlock (block * types.Block , blockValue * big.Int , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , usedSbundles []types.UsedSBundle , bidTrace * apiv1.BidTrace ) {
347+ back := backoff .NewExponentialBackOff ()
348+ back .MaxInterval = 3 * time .Second
349+ back .MaxElapsedTime = 12 * time .Second
350+ err := backoff .Retry (func () error {
351+ return b .blockConsumer .ConsumeBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , usedSbundles , bidTrace )
352+ }, back )
353+ if err != nil {
354+ log .Error ("could not consume built block" , "err" , err )
355+ } else {
356+ log .Info ("successfully relayed block data to consumer" )
357+ }
358+ }
341359func (b * Builder ) OnPayloadAttribute (attrs * types.BuilderPayloadAttributes ) error {
342360 if attrs == nil {
343361 return nil
0 commit comments