mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Compare commits
3 Commits
attDataBen
...
builder-pr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f8d1508ce | ||
|
|
af986ae368 | ||
|
|
f53bccfdb7 |
@@ -60,6 +60,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) {
|
||||
return nil, err
|
||||
}
|
||||
s.c = c
|
||||
log.Infof("Builder configured with end point: %s", s.cfg.builderEndpoint.Url)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -841,6 +841,7 @@ func (b *BeaconNode) registerRPCService() error {
|
||||
MaxMsgSize: maxMsgSize,
|
||||
ProposerIdsCache: b.proposerIdsCache,
|
||||
ExecutionEngineCaller: web3Service,
|
||||
BlockBuilder: b.fetchBuilderService(),
|
||||
})
|
||||
|
||||
return b.services.RegisterService(rpcService)
|
||||
|
||||
@@ -10,6 +10,7 @@ go_library(
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain:go_default_library",
|
||||
"//beacon-chain/builder:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/cache/depositcache:go_default_library",
|
||||
"//beacon-chain/core/feed/block:go_default_library",
|
||||
|
||||
@@ -62,7 +62,7 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
|
||||
return nil, status.Errorf(codes.Internal, "Could not fetch Bellatrix beacon block: %v", err)
|
||||
}
|
||||
|
||||
return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: blk}}, nil
|
||||
return blk, nil
|
||||
}
|
||||
|
||||
// GetBlock is called by a proposer during its assigned slot to request a block to sign
|
||||
@@ -141,6 +141,11 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.
|
||||
return nil, fmt.Errorf("could not tree hash block: %v", err)
|
||||
}
|
||||
|
||||
blk, err = vs.getBuilderBlock(ctx, blk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Do not block proposal critical path with debug logging or block feed updates.
|
||||
defer func() {
|
||||
log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debugf(
|
||||
|
||||
@@ -16,14 +16,49 @@ import (
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.BeaconBlockBellatrix, error) {
|
||||
func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) {
|
||||
altairBlk, err := vs.buildAltairBeaconBlock(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"NilStatus": vs.BlockBuilder != nil,
|
||||
"Configured": vs.BlockBuilder.Configured(),
|
||||
}).Info("Checking builder status")
|
||||
|
||||
// Did the user specify block builder
|
||||
if vs.BlockBuilder != nil && vs.BlockBuilder.Configured() {
|
||||
// Does the protocol allow node to use block builder to construct payload header now
|
||||
ready, err := vs.readyForBuilder(ctx)
|
||||
if err == nil && ready {
|
||||
log.Info("Builder is ready")
|
||||
// Retrieve header from block builder and construct the head block if there's no error.
|
||||
h, err := vs.getPayloadHeader(ctx, req.Slot, altairBlk.ProposerIndex)
|
||||
if err == nil {
|
||||
log.WithFields(logrus.Fields{
|
||||
"BlockHash": fmt.Sprintf("%#x", h.BlockHash),
|
||||
"TxRoot": fmt.Sprintf("%#x", h.TransactionsRoot),
|
||||
"FeeRecipient": fmt.Sprintf("%#x", h.FeeRecipient),
|
||||
"GasUsed": h.GasUsed,
|
||||
"GasLimit": h.GasLimit,
|
||||
}).Info("Retrieved payload header from builder")
|
||||
return vs.buildHeaderBlock(ctx, altairBlk, h)
|
||||
}
|
||||
// If there's an error at retrieving header, default back to using local EE.
|
||||
log.WithError(err).Warning("Could not construct block using the header from builders, using local execution engine instead")
|
||||
}
|
||||
if err != nil {
|
||||
log.WithError(err).Warning("Could not decide builder is ready")
|
||||
}
|
||||
if !ready {
|
||||
log.Debug("Can't use builder yet. Using local execution engine to propose")
|
||||
}
|
||||
}
|
||||
|
||||
payload, err := vs.getExecutionPayload(ctx, req.Slot, altairBlk.ProposerIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -60,7 +95,24 @@ func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockR
|
||||
return nil, fmt.Errorf("could not compute state root: %v", err)
|
||||
}
|
||||
blk.StateRoot = stateRoot
|
||||
return blk, nil
|
||||
return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: blk}}, nil
|
||||
}
|
||||
|
||||
// readyForBuilder returns true if builder is allowed to be used. Builder is allowed to be use after the
|
||||
// first finalized checkpt has been execution-enabled.
|
||||
func (vs *Server) readyForBuilder(ctx context.Context) (bool, error) {
|
||||
cp := vs.FinalizationFetcher.FinalizedCheckpt()
|
||||
if bytesutil.ToBytes32(cp.Root) == params.BeaconConfig().ZeroHash {
|
||||
return false, nil
|
||||
}
|
||||
b, err := vs.BeaconDB.Block(ctx, bytesutil.ToBytes32(cp.Root))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := coreBlock.BeaconBlockIsNil(b); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return blocks.IsExecutionBlock(b.Block().Body())
|
||||
}
|
||||
|
||||
// This function retrieves the payload header given the slot number and the validator index.
|
||||
@@ -181,10 +233,27 @@ func (vs *Server) getBuilderBlock(ctx context.Context, b interfaces.SignedBeacon
|
||||
Signature: b.Signature(),
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"BlockHash": fmt.Sprintf("%#x", h.BlockHash),
|
||||
"TxRoot": fmt.Sprintf("%#x", h.TransactionsRoot),
|
||||
"FeeRecipient": fmt.Sprintf("%#x", h.FeeRecipient),
|
||||
"GasUsed": h.GasUsed,
|
||||
"GasLimit": h.GasLimit,
|
||||
}).Info("Submitting blind block")
|
||||
|
||||
payload, err := vs.BlockBuilder.SubmitBlindedBlock(ctx, sb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "could not submit blind block")
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"BlockHash": fmt.Sprintf("%#x", payload.BlockHash),
|
||||
"Txs": len(payload.Transactions),
|
||||
"FeeRecipient": fmt.Sprintf("%#x", payload.FeeRecipient),
|
||||
"GasUsed": payload.GasUsed,
|
||||
"GasLimit": payload.GasLimit,
|
||||
}).Info("Retrieved payload")
|
||||
|
||||
bb := ðpb.SignedBeaconBlockBellatrix{
|
||||
Block: ðpb.BeaconBlockBellatrix{
|
||||
Slot: sb.Block.Slot,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/builder"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||
@@ -112,6 +113,7 @@ type Config struct {
|
||||
ExecutionEngineCaller powchain.EngineCaller
|
||||
ProposerIdsCache *cache.ProposerPayloadIDsCache
|
||||
OptimisticModeFetcher blockchain.OptimisticModeFetcher
|
||||
BlockBuilder builder.BlockBuilder
|
||||
}
|
||||
|
||||
// NewService instantiates a new RPC service instance that will
|
||||
@@ -216,6 +218,7 @@ func (s *Service) Start() {
|
||||
ExecutionEngineCaller: s.cfg.ExecutionEngineCaller,
|
||||
BeaconDB: s.cfg.BeaconDB,
|
||||
ProposerSlotIndexCache: s.cfg.ProposerIdsCache,
|
||||
BlockBuilder: s.cfg.BlockBuilder,
|
||||
}
|
||||
validatorServerV1 := &validator.Server{
|
||||
HeadFetcher: s.cfg.HeadFetcher,
|
||||
|
||||
Reference in New Issue
Block a user