@@ -19,12 +19,14 @@ import (
19
19
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
20
20
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition"
21
21
"github.com/prysmaticlabs/prysm/v4/beacon-chain/db/kv"
22
+ fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
22
23
"github.com/prysmaticlabs/prysm/v4/config/params"
23
24
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
24
25
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
25
26
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
26
27
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
27
28
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
29
+ "github.com/prysmaticlabs/prysm/v4/runtime/version"
28
30
"github.com/prysmaticlabs/prysm/v4/time/slots"
29
31
"github.com/sirupsen/logrus"
30
32
"go.opencensus.io/trace"
@@ -215,11 +217,77 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
215
217
func (vs * Server ) ProposeBeaconBlock (ctx context.Context , req * ethpb.GenericSignedBeaconBlock ) (* ethpb.ProposeResponse , error ) {
216
218
ctx , span := trace .StartSpan (ctx , "ProposerServer.ProposeBeaconBlock" )
217
219
defer span .End ()
220
+
218
221
blk , err := blocks .NewSignedBeaconBlock (req .Block )
219
222
if err != nil {
220
223
return nil , status .Errorf (codes .InvalidArgument , "%s: %v" , CouldNotDecodeBlock , err )
221
224
}
222
- return vs .proposeGenericBeaconBlock (ctx , blk )
225
+
226
+ unblinder , err := newUnblinder (blk , vs .BlockBuilder )
227
+ if err != nil {
228
+ return nil , errors .Wrap (err , "could not create unblinder" )
229
+ }
230
+ blk , err = unblinder .unblindBuilderBlock (ctx )
231
+ if err != nil {
232
+ return nil , errors .Wrap (err , "could not unblind builder block" )
233
+ }
234
+
235
+ // Broadcast the new block to the network.
236
+ blkPb , err := blk .Proto ()
237
+ if err != nil {
238
+ return nil , errors .Wrap (err , "could not get protobuf block" )
239
+ }
240
+ if err := vs .P2P .Broadcast (ctx , blkPb ); err != nil {
241
+ return nil , fmt .Errorf ("could not broadcast block: %v" , err )
242
+ }
243
+
244
+ root , err := blk .Block ().HashTreeRoot ()
245
+ if err != nil {
246
+ return nil , fmt .Errorf ("could not tree hash block: %v" , err )
247
+ }
248
+ log .WithFields (logrus.Fields {
249
+ "blockRoot" : hex .EncodeToString (root [:]),
250
+ }).Debug ("Broadcasting block" )
251
+
252
+ if blk .Version () >= version .Deneb {
253
+ b , ok := req .GetBlock ().(* ethpb.GenericSignedBeaconBlock_Deneb )
254
+ if ! ok {
255
+ return nil , status .Error (codes .Internal , "Could not cast block to Deneb" )
256
+ }
257
+ if len (b .Deneb .Blobs ) > fieldparams .MaxBlobsPerBlock {
258
+ return nil , status .Errorf (codes .InvalidArgument , "Too many blobs in block: %d" , len (b .Deneb .Blobs ))
259
+ }
260
+ scs := make ([]* ethpb.BlobSidecar , len (b .Deneb .Blobs ))
261
+ for i , blob := range b .Deneb .Blobs {
262
+ if err := vs .P2P .BroadcastBlob (ctx , blob .Message .Index , blob ); err != nil {
263
+ log .WithError (err ).Errorf ("Could not broadcast blob index %d / %d" , i , len (b .Deneb .Blobs ))
264
+ }
265
+ scs [i ] = blob .Message
266
+ }
267
+ if len (scs ) > 0 {
268
+ if err := vs .BeaconDB .SaveBlobSidecar (ctx , scs ); err != nil {
269
+ return nil , err
270
+ }
271
+ }
272
+ }
273
+
274
+ // Do not block proposal critical path with debug logging or block feed updates.
275
+ defer func () {
276
+ log .WithField ("blockRoot" , fmt .Sprintf ("%#x" , bytesutil .Trunc (root [:]))).Debugf (
277
+ "Block proposal received via RPC" )
278
+ vs .BlockNotifier .BlockFeed ().Send (& feed.Event {
279
+ Type : blockfeed .ReceivedBlock ,
280
+ Data : & blockfeed.ReceivedBlockData {SignedBlock : blk },
281
+ })
282
+ }()
283
+
284
+ if err := vs .BlockReceiver .ReceiveBlock (ctx , blk , root ); err != nil {
285
+ return nil , fmt .Errorf ("could not process beacon block: %v" , err )
286
+ }
287
+
288
+ return & ethpb.ProposeResponse {
289
+ BlockRoot : root [:],
290
+ }, nil
223
291
}
224
292
225
293
// PrepareBeaconProposer caches and updates the fee recipient for the given proposer.
@@ -301,54 +369,6 @@ func (vs *Server) GetFeeRecipientByPubKey(ctx context.Context, request *ethpb.Fe
301
369
}, nil
302
370
}
303
371
304
- func (vs * Server ) proposeGenericBeaconBlock (ctx context.Context , blk interfaces.SignedBeaconBlock ) (* ethpb.ProposeResponse , error ) {
305
- ctx , span := trace .StartSpan (ctx , "ProposerServer.proposeGenericBeaconBlock" )
306
- defer span .End ()
307
- root , err := blk .Block ().HashTreeRoot ()
308
- if err != nil {
309
- return nil , fmt .Errorf ("could not tree hash block: %v" , err )
310
- }
311
-
312
- unblinder , err := newUnblinder (blk , vs .BlockBuilder )
313
- if err != nil {
314
- return nil , errors .Wrap (err , "could not create unblinder" )
315
- }
316
- blk , err = unblinder .unblindBuilderBlock (ctx )
317
- if err != nil {
318
- return nil , errors .Wrap (err , "could not unblind builder block" )
319
- }
320
-
321
- // Do not block proposal critical path with debug logging or block feed updates.
322
- defer func () {
323
- log .WithField ("blockRoot" , fmt .Sprintf ("%#x" , bytesutil .Trunc (root [:]))).Debugf (
324
- "Block proposal received via RPC" )
325
- vs .BlockNotifier .BlockFeed ().Send (& feed.Event {
326
- Type : blockfeed .ReceivedBlock ,
327
- Data : & blockfeed.ReceivedBlockData {SignedBlock : blk },
328
- })
329
- }()
330
-
331
- // Broadcast the new block to the network.
332
- blkPb , err := blk .Proto ()
333
- if err != nil {
334
- return nil , errors .Wrap (err , "could not get protobuf block" )
335
- }
336
- if err := vs .P2P .Broadcast (ctx , blkPb ); err != nil {
337
- return nil , fmt .Errorf ("could not broadcast block: %v" , err )
338
- }
339
- log .WithFields (logrus.Fields {
340
- "blockRoot" : hex .EncodeToString (root [:]),
341
- }).Debug ("Broadcasting block" )
342
-
343
- if err := vs .BlockReceiver .ReceiveBlock (ctx , blk , root ); err != nil {
344
- return nil , fmt .Errorf ("could not process beacon block: %v" , err )
345
- }
346
-
347
- return & ethpb.ProposeResponse {
348
- BlockRoot : root [:],
349
- }, nil
350
- }
351
-
352
372
// computeStateRoot computes the state root after a block has been processed through a state transition and
353
373
// returns it to the validator client.
354
374
func (vs * Server ) computeStateRoot (ctx context.Context , block interfaces.ReadOnlySignedBeaconBlock ) ([]byte , error ) {
0 commit comments