@@ -43,6 +43,14 @@ import {Clock, ClockEvent, IClock} from "../util/clock.js";
43
43
import { ensureDir , writeIfNotExist } from "../util/file.js" ;
44
44
import { isOptimisticBlock } from "../util/forkChoice.js" ;
45
45
import { BufferPool } from "../util/bufferPool.js" ;
46
+ import {
47
+ blindedOrFullBlockToFull ,
48
+ deserializeFullOrBlindedSignedBeaconBlock ,
49
+ getEth1BlockHashFromSerializedBlock ,
50
+ serializeFullOrBlindedSignedBeaconBlock ,
51
+ } from "../util/fullOrBlindedBlock.js" ;
52
+ import { ExecutionPayloadBody } from "../execution/engine/types.js" ;
53
+ import { Eth1Error , Eth1ErrorCode } from "../eth1/errors.js" ;
46
54
import { BlockProcessor , ImportBlockOpts } from "./blocks/index.js" ;
47
55
import { ChainEventEmitter , ChainEvent } from "./emitter.js" ;
48
56
import {
@@ -506,7 +514,11 @@ export class BeaconChain implements IBeaconChain {
506
514
if ( block ) {
507
515
const data = await this . db . block . get ( fromHexString ( block . blockRoot ) ) ;
508
516
if ( data ) {
509
- return { block : data , executionOptimistic : isOptimisticBlock ( block ) , finalized : false } ;
517
+ return {
518
+ block : await this . blindedOrFullBlockToFull ( data ) ,
519
+ executionOptimistic : isOptimisticBlock ( block ) ,
520
+ finalized : false ,
521
+ } ;
510
522
}
511
523
}
512
524
// A non-finalized slot expected to be found in the hot db, could be archived during
@@ -515,7 +527,7 @@ export class BeaconChain implements IBeaconChain {
515
527
}
516
528
517
529
const data = await this . db . blockArchive . get ( slot ) ;
518
- return data && { block : data , executionOptimistic : false , finalized : true } ;
530
+ return data && { block : await this . blindedOrFullBlockToFull ( data ) , executionOptimistic : false , finalized : true } ;
519
531
}
520
532
521
533
async getBlockByRoot (
@@ -525,7 +537,11 @@ export class BeaconChain implements IBeaconChain {
525
537
if ( block ) {
526
538
const data = await this . db . block . get ( fromHexString ( root ) ) ;
527
539
if ( data ) {
528
- return { block : data , executionOptimistic : isOptimisticBlock ( block ) , finalized : false } ;
540
+ return {
541
+ block : await this . blindedOrFullBlockToFull ( data ) ,
542
+ executionOptimistic : isOptimisticBlock ( block ) ,
543
+ finalized : false ,
544
+ } ;
529
545
}
530
546
// If block is not found in hot db, try cold db since there could be an archive cycle happening
531
547
// TODO: Add a lock to the archiver to have deterministic behavior on where are blocks
@@ -570,6 +586,28 @@ export class BeaconChain implements IBeaconChain {
570
586
return this . produceBlockWrapper < BlockType . Blinded > ( BlockType . Blinded , blockAttributes ) ;
571
587
}
572
588
589
+ async blindedOrFullBlockToFull ( block : allForks . FullOrBlindedSignedBeaconBlock ) : Promise < allForks . SignedBeaconBlock > {
590
+ const info = this . config . getForkInfo ( block . message . slot ) ;
591
+ return blindedOrFullBlockToFull (
592
+ this . config ,
593
+ info . seq ,
594
+ block ,
595
+ await this . getTransactionsAndWithdrawals ( info . seq , toHexString ( block . message . body . eth1Data . blockHash ) )
596
+ ) ;
597
+ }
598
+
599
+ async blindedOrFullBlockToFullBytes ( forkSeq : ForkSeq , block : Uint8Array ) : Promise < Uint8Array > {
600
+ return serializeFullOrBlindedSignedBeaconBlock (
601
+ this . config ,
602
+ blindedOrFullBlockToFull (
603
+ this . config ,
604
+ forkSeq ,
605
+ deserializeFullOrBlindedSignedBeaconBlock ( this . config , block ) ,
606
+ await this . getTransactionsAndWithdrawals ( forkSeq , toHexString ( getEth1BlockHashFromSerializedBlock ( block ) ) )
607
+ )
608
+ ) ;
609
+ }
610
+
573
611
async produceBlockWrapper < T extends BlockType > (
574
612
blockType : T ,
575
613
{
@@ -799,6 +837,23 @@ export class BeaconChain implements IBeaconChain {
799
837
}
800
838
}
801
839
840
+ private async getTransactionsAndWithdrawals (
841
+ forkSeq : ForkSeq ,
842
+ blockHash : string
843
+ ) : Promise < Partial < ExecutionPayloadBody > > {
844
+ if ( forkSeq < ForkSeq . bellatrix ) {
845
+ return { } ;
846
+ }
847
+ const [ payload ] = await this . executionEngine . getPayloadBodiesByHash ( [ blockHash ] ) ;
848
+ if ( ! payload ) {
849
+ throw new Eth1Error (
850
+ { code : Eth1ErrorCode . INVALID_PAYLOAD_BODY , blockHash} ,
851
+ "payload body not found by eth1 engine"
852
+ ) ;
853
+ }
854
+ return payload ;
855
+ }
856
+
802
857
/**
803
858
* Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 .
804
859
* However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification
0 commit comments