2022-02-08 01:29:11 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2022-05-02 15:43:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
2022-02-08 01:29:11 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.BeaconBlockBellatrix, error) {
|
|
|
|
altairBlk, err := vs.buildAltairBeaconBlock(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-14 18:44:40 +00:00
|
|
|
payload, err := vs.getExecutionPayload(ctx, req.Slot, altairBlk.ProposerIndex)
|
2022-03-09 20:26:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-08 01:29:11 +00:00
|
|
|
blk := ðpb.BeaconBlockBellatrix{
|
|
|
|
Slot: altairBlk.Slot,
|
|
|
|
ProposerIndex: altairBlk.ProposerIndex,
|
|
|
|
ParentRoot: altairBlk.ParentRoot,
|
|
|
|
StateRoot: params.BeaconConfig().ZeroHash[:],
|
|
|
|
Body: ðpb.BeaconBlockBodyBellatrix{
|
|
|
|
RandaoReveal: altairBlk.Body.RandaoReveal,
|
|
|
|
Eth1Data: altairBlk.Body.Eth1Data,
|
|
|
|
Graffiti: altairBlk.Body.Graffiti,
|
|
|
|
ProposerSlashings: altairBlk.Body.ProposerSlashings,
|
|
|
|
AttesterSlashings: altairBlk.Body.AttesterSlashings,
|
|
|
|
Attestations: altairBlk.Body.Attestations,
|
|
|
|
Deposits: altairBlk.Body.Deposits,
|
|
|
|
VoluntaryExits: altairBlk.Body.VoluntaryExits,
|
|
|
|
SyncAggregate: altairBlk.Body.SyncAggregate,
|
2022-03-09 20:26:23 +00:00
|
|
|
ExecutionPayload: payload,
|
2022-02-08 01:29:11 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
// Compute state root with the newly constructed block.
|
2022-03-25 23:00:44 +00:00
|
|
|
wsb, err := wrapper.WrappedSignedBeaconBlock(
|
2022-02-08 01:29:11 +00:00
|
|
|
ðpb.SignedBeaconBlockBellatrix{Block: blk, Signature: make([]byte, 96)},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
stateRoot, err := vs.computeStateRoot(ctx, wsb)
|
|
|
|
if err != nil {
|
|
|
|
interop.WriteBlockToDisk(wsb, true /*failed*/)
|
|
|
|
return nil, fmt.Errorf("could not compute state root: %v", err)
|
|
|
|
}
|
|
|
|
blk.StateRoot = stateRoot
|
|
|
|
return blk, nil
|
|
|
|
}
|