@@ -3,10 +3,14 @@ package builder
33import (
44 "context"
55 "errors"
6+ "math/big"
67 _ "os"
78 "sync"
89 "time"
910
11+ "github.com/attestantio/go-eth2-client/spec/bellatrix"
12+ "github.com/attestantio/go-eth2-client/spec/capella"
13+ "github.com/attestantio/go-eth2-client/spec/phase0"
1014 "github.com/ethereum/go-ethereum/common"
1115 blockvalidation "github.com/ethereum/go-ethereum/eth/block-validation"
1216 "github.com/holiman/uint256"
@@ -20,9 +24,7 @@ import (
2024
2125 capellaapi "github.com/attestantio/go-builder-client/api/capella"
2226 apiv1 "github.com/attestantio/go-builder-client/api/v1"
23- "github.com/attestantio/go-eth2-client/spec/bellatrix"
24- "github.com/attestantio/go-eth2-client/spec/capella"
25- "github.com/attestantio/go-eth2-client/spec/phase0"
27+
2628 "github.com/flashbots/go-boost-utils/bls"
2729 boostTypes "github.com/flashbots/go-boost-utils/types"
2830)
@@ -106,34 +108,34 @@ func (b *Builder) Stop() error {
106108 return nil
107109}
108110
109- func (b * Builder ) onSealedBlock (block * types.Block , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
111+ func (b * Builder ) onSealedBlock (block * types.Block , blockValue * big. Int , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
110112 if b .eth .Config ().IsShanghai (block .Time ()) {
111- if err := b .submitCapellaBlock (block , ordersClosedAt , sealedAt , commitedBundles , allBundles , proposerPubkey , vd , attrs ); err != nil {
113+ if err := b .submitCapellaBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , proposerPubkey , vd , attrs ); err != nil {
112114 return err
113115 }
114116 } else {
115- if err := b .submitBellatrixBlock (block , ordersClosedAt , sealedAt , commitedBundles , allBundles , proposerPubkey , vd , attrs ); err != nil {
117+ if err := b .submitBellatrixBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , proposerPubkey , vd , attrs ); err != nil {
116118 return err
117119 }
118120 }
119121
120- log .Info ("submitted block" , "slot" , attrs .Slot , "value" , block . Profit .String (), "parent" , block .ParentHash , "hash" , block .Hash (), "#commitedBundles" , len (commitedBundles ))
122+ log .Info ("submitted block" , "slot" , attrs .Slot , "value" , blockValue .String (), "parent" , block .ParentHash , "hash" , block .Hash (), "#commitedBundles" , len (commitedBundles ))
121123
122124 return nil
123125}
124126
125- func (b * Builder ) submitBellatrixBlock (block * types.Block , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
126- value := new (boostTypes. U256Str )
127- err := value . FromBig ( block . Profit )
127+ func (b * Builder ) submitBellatrixBlock (block * types.Block , blockValue * big. Int , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
128+ executableData := engine . BlockToExecutableData ( block , blockValue )
129+ payload , err := executableDataToExecutionPayload ( executableData . ExecutionPayload )
128130 if err != nil {
129- log .Error ("could not set block value " , "err" , err )
131+ log .Error ("could not format execution payload " , "err" , err )
130132 return err
131133 }
132134
133- executableData := engine . BlockToExecutableData ( block , block . Profit )
134- payload , err := executableDataToExecutionPayload ( executableData . ExecutionPayload )
135+ value := new (boostTypes. U256Str )
136+ err = value . FromBig ( blockValue )
135137 if err != nil {
136- log .Error ("could not format execution payload " , "err" , err )
138+ log .Error ("could not set block value " , "err" , err )
137139 return err
138140 }
139141
@@ -167,26 +169,29 @@ func (b *Builder) submitBellatrixBlock(block *types.Block, ordersClosedAt time.T
167169 log .Error ("could not validate block" , "err" , err )
168170 }
169171 } else {
170- go b .ds .ConsumeBuiltBlock (block , ordersClosedAt , sealedAt , commitedBundles , allBundles , & blockBidMsg )
172+ go b .ds .ConsumeBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , & blockBidMsg )
171173 err = b .relay .SubmitBlock (& blockSubmitReq , vd )
172174 if err != nil {
173175 log .Error ("could not submit block" , "err" , err , "#commitedBundles" , len (commitedBundles ))
174176 return err
175177 }
176178 }
179+
180+ log .Info ("submitted block" , "slot" , blockBidMsg .Slot , "value" , blockBidMsg .Value .String (), "parent" , blockBidMsg .ParentHash , "hash" , block .Hash (), "#commitedBundles" , len (commitedBundles ))
181+
177182 return nil
178183}
179184
180- func (b * Builder ) submitCapellaBlock (block * types.Block , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
181- executableData := engine .BlockToExecutableData (block , block . Profit )
185+ func (b * Builder ) submitCapellaBlock (block * types.Block , blockValue * big. Int , ordersClosedAt time.Time , sealedAt time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle , proposerPubkey boostTypes.PublicKey , vd ValidatorData , attrs * types.BuilderPayloadAttributes ) error {
186+ executableData := engine .BlockToExecutableData (block , blockValue )
182187 payload , err := executableDataToCapellaExecutionPayload (executableData .ExecutionPayload )
183188 if err != nil {
184189 log .Error ("could not format execution payload" , "err" , err )
185190 return err
186191 }
187192
188193 value := new (boostTypes.U256Str )
189- err = value .FromBig (block . Profit )
194+ err = value .FromBig (blockValue )
190195 if err != nil {
191196 log .Error ("could not set block value" , "err" , err )
192197 return err
@@ -218,13 +223,12 @@ func (b *Builder) submitCapellaBlock(block *types.Block, ordersClosedAt time.Tim
218223 ExecutionPayload : payload ,
219224 }
220225
221- go b .ds .ConsumeBuiltBlock (block , ordersClosedAt , sealedAt , commitedBundles , allBundles , & boostBidTrace )
226+ go b .ds .ConsumeBuiltBlock (block , blockValue , ordersClosedAt , sealedAt , commitedBundles , allBundles , & boostBidTrace )
222227 err = b .relay .SubmitBlockCapella (& blockSubmitReq , vd )
223228 if err != nil {
224229 log .Error ("could not submit block" , "err" , err , "#commitedBundles" , len (commitedBundles ))
225230 return err
226231 }
227-
228232 return nil
229233}
230234
@@ -274,10 +278,7 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro
274278 }
275279
276280 for _ , currentAttrs := range b .slotAttrs {
277- seen := attrs .HeadHash == currentAttrs .HeadHash && attrs .Slot == currentAttrs .Slot &&
278- attrs .GasLimit == currentAttrs .GasLimit && attrs .SuggestedFeeRecipient == currentAttrs .SuggestedFeeRecipient
279-
280- if seen {
281+ if attrs .Equal (& currentAttrs ) {
281282 log .Debug ("ignoring known payload attribute" , "slot" , attrs .Slot , "hash" , attrs .HeadHash )
282283 return nil
283284 }
@@ -290,6 +291,7 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro
290291
291292type blockQueueEntry struct {
292293 block * types.Block
294+ blockValue * big.Int
293295 ordersCloseTime time.Time
294296 sealedAt time.Time
295297 commitedBundles []types.SimulatedBundle
@@ -320,7 +322,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
320322 submitBestBlock := func () {
321323 queueMu .Lock ()
322324 if queueBestEntry .block .Hash () != queueLastSubmittedHash {
323- err := b .onSealedBlock (queueBestEntry .block , queueBestEntry .ordersCloseTime , queueBestEntry .sealedAt , queueBestEntry .commitedBundles , queueBestEntry .allBundles , proposerPubkey , vd , attrs )
325+ err := b .onSealedBlock (queueBestEntry .block , queueBestEntry .blockValue , queueBestEntry . ordersCloseTime , queueBestEntry .sealedAt , queueBestEntry .commitedBundles , queueBestEntry .allBundles , proposerPubkey , vd , attrs )
324326
325327 if err != nil {
326328 log .Error ("could not run sealed block hook" , "err" , err )
@@ -335,7 +337,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
335337 go runResubmitLoop (ctx , b .limiter , queueSignal , submitBestBlock )
336338
337339 // Populates queue with submissions that increase block profit
338- blockHook := func (block * types.Block , ordersCloseTime time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle ) {
340+ blockHook := func (block * types.Block , blockValue * big. Int , ordersCloseTime time.Time , commitedBundles []types.SimulatedBundle , allBundles []types.SimulatedBundle ) {
339341 if ctx .Err () != nil {
340342 return
341343 }
@@ -347,6 +349,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
347349 if block .Hash () != queueLastSubmittedHash {
348350 queueBestEntry = blockQueueEntry {
349351 block : block ,
352+ blockValue : new (big.Int ).Set (blockValue ),
350353 ordersCloseTime : ordersCloseTime ,
351354 sealedAt : sealedAt ,
352355 commitedBundles : commitedBundles ,
0 commit comments