@@ -63,82 +63,92 @@ func NewBuilder(sk *bls.SecretKey, bc IBeaconClient, relay IRelay, builderSignin
6363 }
6464}
6565
66- func (b * Builder ) OnPayloadAttribute (attrs * BuilderPayloadAttributes ) error {
67- if attrs != nil {
68- vd , err := b .relay .GetValidatorForSlot (attrs .Slot )
69- if err != nil {
70- log .Info ("could not get validator while submitting block" , "err" , err , "slot" , attrs .Slot )
71- return err
72- }
73-
74- attrs .SuggestedFeeRecipient = [20 ]byte (vd .FeeRecipient )
75- attrs .GasLimit = vd .GasLimit
76-
77- if b .eth .Synced () {
78- parentBlock := b .eth .GetBlockByHash (attrs .HeadHash )
79- if parentBlock == nil {
80- log .Info ("Block hash not found in blocktree" , "head block hash" , attrs .HeadHash )
81- return err
82- }
83-
84- executableData , block := b .eth .BuildBlock (attrs )
85- if executableData == nil || block == nil {
86- log .Error ("did not receive the payload" )
87- return errors .New ("could not build block" )
88- }
89- payload , err := executableDataToExecutionPayload (executableData )
90- if err != nil {
91- log .Error ("could not format execution payload" , "err" , err )
92- return err
93- }
94-
95- pubkey , err := boostTypes .HexToPubkey (string (vd .Pubkey ))
96- if err != nil {
97- log .Error ("could not parse pubkey" , "err" , err , "pubkey" , vd .Pubkey )
98- return err
99- }
100-
101- value := new (boostTypes.U256Str )
102- err = value .FromBig (block .Profit )
103- if err != nil {
104- log .Error ("could not set block value" , "err" , err )
105- return err
106- }
107-
108- blockBidMsg := boostTypes.BidTrace {
109- Slot : attrs .Slot ,
110- ParentHash : payload .ParentHash ,
111- BlockHash : payload .BlockHash ,
112- BuilderPubkey : b .builderPublicKey ,
113- ProposerPubkey : pubkey ,
114- ProposerFeeRecipient : boostTypes .Address (attrs .SuggestedFeeRecipient ),
115- GasLimit : executableData .GasLimit ,
116- GasUsed : executableData .GasUsed ,
117- Value : * value ,
118- }
119-
120- signature , err := boostTypes .SignMessage (& blockBidMsg , b .builderSigningDomain , b .builderSecretKey )
121- if err != nil {
122- log .Error ("could not sign builder bid" , "err" , err )
123- return err
124- }
125-
126- blockSubmitReq := boostTypes.BuilderSubmitBlockRequest {
127- Signature : signature ,
128- Message : & blockBidMsg ,
129- ExecutionPayload : payload ,
130- }
131-
132- err = b .relay .SubmitBlock (& blockSubmitReq )
133- if err != nil {
134- log .Error ("could not submit block" , "err" , err )
135- return err
136- }
137- }
66+ func (b * Builder ) onSealedBlock (executableData * beacon.ExecutableDataV1 , block * types.Block , proposerPubkey boostTypes.PublicKey , proposerFeeRecipient boostTypes.Address , slot uint64 ) error {
67+ payload , err := executableDataToExecutionPayload (executableData )
68+ if err != nil {
69+ log .Error ("could not format execution payload" , "err" , err )
70+ return err
71+ }
72+
73+ value := new (boostTypes.U256Str )
74+ err = value .FromBig (block .Profit )
75+ if err != nil {
76+ log .Error ("could not set block value" , "err" , err )
77+ return err
13878 }
79+
80+ blockBidMsg := boostTypes.BidTrace {
81+ Slot : slot ,
82+ ParentHash : payload .ParentHash ,
83+ BlockHash : payload .BlockHash ,
84+ BuilderPubkey : b .builderPublicKey ,
85+ ProposerPubkey : proposerPubkey ,
86+ ProposerFeeRecipient : proposerFeeRecipient ,
87+ GasLimit : executableData .GasLimit ,
88+ GasUsed : executableData .GasUsed ,
89+ Value : * value ,
90+ }
91+
92+ signature , err := boostTypes .SignMessage (& blockBidMsg , b .builderSigningDomain , b .builderSecretKey )
93+ if err != nil {
94+ log .Error ("could not sign builder bid" , "err" , err )
95+ return err
96+ }
97+
98+ blockSubmitReq := boostTypes.BuilderSubmitBlockRequest {
99+ Signature : signature ,
100+ Message : & blockBidMsg ,
101+ ExecutionPayload : payload ,
102+ }
103+
104+ err = b .relay .SubmitBlock (& blockSubmitReq )
105+ if err != nil {
106+ log .Error ("could not submit block" , "err" , err )
107+ return err
108+ }
109+
139110 return nil
140111}
141112
113+ func (b * Builder ) OnPayloadAttribute (attrs * BuilderPayloadAttributes ) error {
114+ if attrs == nil {
115+ return nil
116+ }
117+
118+ vd , err := b .relay .GetValidatorForSlot (attrs .Slot )
119+ if err != nil {
120+ log .Info ("could not get validator while submitting block" , "err" , err , "slot" , attrs .Slot )
121+ return err
122+ }
123+
124+ attrs .SuggestedFeeRecipient = [20 ]byte (vd .FeeRecipient )
125+ attrs .GasLimit = vd .GasLimit
126+
127+ proposerPubkey , err := boostTypes .HexToPubkey (string (vd .Pubkey ))
128+ if err != nil {
129+ log .Error ("could not parse pubkey" , "err" , err , "pubkey" , vd .Pubkey )
130+ return err
131+ }
132+
133+ if ! b .eth .Synced () {
134+ return errors .New ("backend not Synced" )
135+ }
136+
137+ parentBlock := b .eth .GetBlockByHash (attrs .HeadHash )
138+ if parentBlock == nil {
139+ log .Info ("Block hash not found in blocktree" , "head block hash" , attrs .HeadHash )
140+ return errors .New ("parent block not found in blocktree" )
141+ }
142+
143+ executableData , block := b .eth .BuildBlock (attrs )
144+ if executableData == nil || block == nil {
145+ log .Error ("did not receive the payload" )
146+ return errors .New ("could not build block" )
147+ }
148+
149+ return b .onSealedBlock (executableData , block , proposerPubkey , vd .FeeRecipient , attrs .Slot )
150+ }
151+
142152func executableDataToExecutionPayload (data * beacon.ExecutableDataV1 ) (* boostTypes.ExecutionPayload , error ) {
143153 transactionData := make ([]hexutil.Bytes , len (data .Transactions ))
144154 for i , tx := range data .Transactions {
0 commit comments