mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-02-04 01:55:09 -05:00
Compare commits
23 Commits
e2e-debugg
...
more-build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33a0ac4472 | ||
|
|
b890559a18 | ||
|
|
e9d5e99f33 | ||
|
|
dc2b349b97 | ||
|
|
0d6bf081e3 | ||
|
|
481d15c474 | ||
|
|
e49da95350 | ||
|
|
85c784a1c4 | ||
|
|
494a6e409a | ||
|
|
a2c2a420c0 | ||
|
|
4bd93a7ebb | ||
|
|
668462667f | ||
|
|
9b7241caa8 | ||
|
|
0967613361 | ||
|
|
22f2de16af | ||
|
|
5f51670d3b | ||
|
|
e7d8485f3d | ||
|
|
c49297f037 | ||
|
|
fc4bd8e114 | ||
|
|
83a283d2ba | ||
|
|
a28ae83653 | ||
|
|
9e16ad6b62 | ||
|
|
3a1dec82a5 |
@@ -16,7 +16,6 @@ go_library(
|
|||||||
"//beacon-chain/db:go_default_library",
|
"//beacon-chain/db:go_default_library",
|
||||||
"//cmd/beacon-chain/flags:go_default_library",
|
"//cmd/beacon-chain/flags:go_default_library",
|
||||||
"//consensus-types/primitives:go_default_library",
|
"//consensus-types/primitives:go_default_library",
|
||||||
"//encoding/bytesutil:go_default_library",
|
|
||||||
"//network:go_default_library",
|
"//network:go_default_library",
|
||||||
"//network/authorization:go_default_library",
|
"//network/authorization:go_default_library",
|
||||||
"//proto/engine/v1:go_default_library",
|
"//proto/engine/v1:go_default_library",
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/api/client/builder"
|
"github.com/prysmaticlabs/prysm/api/client/builder"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
||||||
"github.com/prysmaticlabs/prysm/network"
|
"github.com/prysmaticlabs/prysm/network"
|
||||||
v1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
v1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.c = c
|
s.c = c
|
||||||
|
log.Infof("Builder configured with end point: %s", s.cfg.builderEndpoint.Url)
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@@ -72,6 +73,11 @@ func (*Service) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configured returns true if the user has input a builder URL.
|
||||||
|
func (s *Service) Configured() bool {
|
||||||
|
return s.cfg.builderEndpoint.Url != ""
|
||||||
|
}
|
||||||
|
|
||||||
// SubmitBlindedBlock submits a blinded block to the builder relay network.
|
// SubmitBlindedBlock submits a blinded block to the builder relay network.
|
||||||
func (s *Service) SubmitBlindedBlock(ctx context.Context, b *ethpb.SignedBlindedBeaconBlockBellatrix) (*v1.ExecutionPayload, error) {
|
func (s *Service) SubmitBlindedBlock(ctx context.Context, b *ethpb.SignedBlindedBeaconBlockBellatrix) (*v1.ExecutionPayload, error) {
|
||||||
ctx, span := trace.StartSpan(ctx, "builder.SubmitBlindedBlock")
|
ctx, span := trace.StartSpan(ctx, "builder.SubmitBlindedBlock")
|
||||||
@@ -128,14 +134,14 @@ func (s *Service) RegisterValidator(ctx context.Context, reg []*ethpb.SignedVali
|
|||||||
valid := make([]*ethpb.SignedValidatorRegistrationV1, 0)
|
valid := make([]*ethpb.SignedValidatorRegistrationV1, 0)
|
||||||
for i := 0; i < len(reg); i++ {
|
for i := 0; i < len(reg); i++ {
|
||||||
r := reg[i]
|
r := reg[i]
|
||||||
nx, exists := s.cfg.headFetcher.HeadPublicKeyToValidatorIndex(bytesutil.ToBytes48(r.Message.Pubkey))
|
//nx, exists := s.cfg.headFetcher.HeadPublicKeyToValidatorIndex(bytesutil.ToBytes48(r.Message.Pubkey))
|
||||||
if !exists {
|
//if !exists {
|
||||||
// we want to allow validators to set up keys that haven't been added to the beaconstate validator list yet,
|
// // we want to allow validators to set up keys that haven't been added to the beaconstate validator list yet,
|
||||||
// so we should tolerate keys that do not seem to be valid by skipping past them.
|
// // so we should tolerate keys that do not seem to be valid by skipping past them.
|
||||||
log.Warnf("Skipping validator registration for pubkey=%#x - not in current validator set.", r.Message.Pubkey)
|
// log.Warnf("Skipping validator registration for pubkey=%#x - not in current validator set.", r.Message.Pubkey)
|
||||||
continue
|
// continue
|
||||||
}
|
//}
|
||||||
idxs = append(idxs, nx)
|
idxs = append(idxs, 0)
|
||||||
msgs = append(msgs, r.Message)
|
msgs = append(msgs, r.Message)
|
||||||
valid = append(valid, r)
|
valid = append(valid, r)
|
||||||
}
|
}
|
||||||
@@ -145,8 +151,3 @@ func (s *Service) RegisterValidator(ctx context.Context, reg []*ethpb.SignedVali
|
|||||||
|
|
||||||
return s.cfg.beaconDB.SaveRegistrationsByValidatorIDs(ctx, idxs, msgs)
|
return s.cfg.beaconDB.SaveRegistrationsByValidatorIDs(ctx, idxs, msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configured returns true if the user has input a builder URL.
|
|
||||||
func (s *Service) Configured() bool {
|
|
||||||
return s.cfg.builderEndpoint.Url != ""
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -841,6 +841,7 @@ func (b *BeaconNode) registerRPCService() error {
|
|||||||
MaxMsgSize: maxMsgSize,
|
MaxMsgSize: maxMsgSize,
|
||||||
ProposerIdsCache: b.proposerIdsCache,
|
ProposerIdsCache: b.proposerIdsCache,
|
||||||
ExecutionEngineCaller: web3Service,
|
ExecutionEngineCaller: web3Service,
|
||||||
|
BlockBuilder: b.fetchBuilderService(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return b.services.RegisterService(rpcService)
|
return b.services.RegisterService(rpcService)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ go_library(
|
|||||||
visibility = ["//beacon-chain:__subpackages__"],
|
visibility = ["//beacon-chain:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"//beacon-chain/blockchain:go_default_library",
|
"//beacon-chain/blockchain:go_default_library",
|
||||||
|
"//beacon-chain/builder:go_default_library",
|
||||||
"//beacon-chain/cache:go_default_library",
|
"//beacon-chain/cache:go_default_library",
|
||||||
"//beacon-chain/cache/depositcache:go_default_library",
|
"//beacon-chain/cache/depositcache:go_default_library",
|
||||||
"//beacon-chain/core/feed/block:go_default_library",
|
"//beacon-chain/core/feed/block:go_default_library",
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
"//async/event:go_default_library",
|
"//async/event:go_default_library",
|
||||||
"//beacon-chain/blockchain/testing:go_default_library",
|
"//beacon-chain/blockchain/testing:go_default_library",
|
||||||
"//beacon-chain/builder/testing:go_default_library",
|
|
||||||
"//beacon-chain/cache:go_default_library",
|
"//beacon-chain/cache:go_default_library",
|
||||||
"//beacon-chain/cache/depositcache:go_default_library",
|
"//beacon-chain/cache/depositcache:go_default_library",
|
||||||
"//beacon-chain/core/altair:go_default_library",
|
"//beacon-chain/core/altair:go_default_library",
|
||||||
@@ -166,7 +165,6 @@ go_test(
|
|||||||
"@com_github_d4l3k_messagediff//:go_default_library",
|
"@com_github_d4l3k_messagediff//:go_default_library",
|
||||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||||
"@com_github_golang_mock//gomock:go_default_library",
|
"@com_github_golang_mock//gomock:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
|
||||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||||
"@com_github_sirupsen_logrus//:go_default_library",
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
"@com_github_sirupsen_logrus//hooks/test: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 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
|
// GetBlock is called by a proposer during its assigned slot to request a block to sign
|
||||||
@@ -141,6 +141,26 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.
|
|||||||
return nil, fmt.Errorf("could not tree hash block: %v", err)
|
return nil, fmt.Errorf("could not tree hash block: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r, err := blk.Block().HashTreeRoot()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Info("Block root with header", fmt.Sprintf("%#x", bytesutil.Trunc(r[:])))
|
||||||
|
blk, err = vs.getBuilderBlock(ctx, blk)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r, err = blk.Block().HashTreeRoot()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Info("block root with payload", fmt.Sprintf("%#x", bytesutil.Trunc(r[:])))
|
||||||
|
payload, err := blk.Block().Body().ExecutionPayload()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Info("Tx count: ", len(payload.Transactions))
|
||||||
|
|
||||||
// Do not block proposal critical path with debug logging or block feed updates.
|
// Do not block proposal critical path with debug logging or block feed updates.
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debugf(
|
log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debugf(
|
||||||
@@ -198,6 +218,5 @@ func (vs *Server) SubmitValidatorRegistration(ctx context.Context, reg *ethpb.Si
|
|||||||
if err := vs.BlockBuilder.RegisterValidator(ctx, reg.Messages); err != nil {
|
if err := vs.BlockBuilder.RegisterValidator(ctx, reg.Messages); err != nil {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "Could not register block builder: %v", err)
|
return nil, status.Errorf(codes.InvalidArgument, "Could not register block builder: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &emptypb.Empty{}, nil
|
return &emptypb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
||||||
@@ -18,12 +19,33 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
altairBlk, err := vs.buildAltairBeaconBlock(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// 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 {
|
||||||
|
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)
|
payload, err := vs.getExecutionPayload(ctx, req.Slot, altairBlk.ProposerIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -60,7 +82,24 @@ func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockR
|
|||||||
return nil, fmt.Errorf("could not compute state root: %v", err)
|
return nil, fmt.Errorf("could not compute state root: %v", err)
|
||||||
}
|
}
|
||||||
blk.StateRoot = stateRoot
|
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.
|
// This function retrieves the payload header given the slot number and the validator index.
|
||||||
@@ -80,11 +119,15 @@ func (vs *Server) getPayloadHeader(ctx context.Context, slot types.Slot, idx typ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pk, err := vs.HeadFetcher.HeadValidatorIndexToPublicKey(ctx, idx)
|
//pk, err := vs.HeadFetcher.HeadValidatorIndexToPublicKey(ctx, idx)
|
||||||
|
//if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
k, err := hexutil.Decode("0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bid, err := vs.BlockBuilder.GetHeader(ctx, slot, bytesutil.ToBytes32(h.BlockHash), pk)
|
bid, err := vs.BlockBuilder.GetHeader(ctx, slot, bytesutil.ToBytes32(h.BlockHash), bytesutil.ToBytes48(k))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
blockchainTest "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
||||||
builderTest "github.com/prysmaticlabs/prysm/beacon-chain/builder/testing"
|
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
|
||||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||||
@@ -65,6 +62,35 @@ func TestServer_buildHeaderBlock(t *testing.T) {
|
|||||||
got, err := vs.buildHeaderBlock(ctx, b1.Block, h)
|
got, err := vs.buildHeaderBlock(ctx, b1.Block, h)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.DeepEqual(t, h, got.GetBlindedBellatrix().Body.ExecutionPayloadHeader)
|
require.DeepEqual(t, h, got.GetBlindedBellatrix().Body.ExecutionPayloadHeader)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServer_readyForBuilder(t *testing.T) {
|
||||||
|
vs := &Server{BeaconDB: dbTest.SetupDB(t)}
|
||||||
|
b := util.NewBeaconBlockBellatrix()
|
||||||
|
wb, err := wrapper.WrappedSignedBeaconBlock(b)
|
||||||
|
require.NoError(t, err)
|
||||||
|
wbr, err := wb.Block().HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
b1 := util.NewBeaconBlockBellatrix()
|
||||||
|
b1.Block.Body.ExecutionPayload.BlockNumber = 1
|
||||||
|
wb1, err := wrapper.WrappedSignedBeaconBlock(b1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
wbr1, err := wb1.Block().HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
ctx := context.Background()
|
||||||
|
require.NoError(t, vs.BeaconDB.SaveBlock(ctx, wb))
|
||||||
|
require.NoError(t, vs.BeaconDB.SaveBlock(ctx, wb1))
|
||||||
|
cs := &ct.ChainService{FinalizedCheckPoint: ðpb.Checkpoint{Root: wbr[:]}}
|
||||||
|
vs.FinalizationFetcher = cs
|
||||||
|
ready, err := vs.readyForBuilder(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, false, ready)
|
||||||
|
|
||||||
|
cs = &ct.ChainService{FinalizedCheckPoint: ðpb.Checkpoint{Root: wbr1[:]}}
|
||||||
|
vs.FinalizationFetcher = cs
|
||||||
|
ready, err = vs.readyForBuilder(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, true, ready)
|
||||||
|
|
||||||
_, err = vs.buildHeaderBlock(ctx, nil, h)
|
_, err = vs.buildHeaderBlock(ctx, nil, h)
|
||||||
require.ErrorContains(t, "nil block", err)
|
require.ErrorContains(t, "nil block", err)
|
||||||
@@ -259,3 +285,105 @@ func TestServer_getBuilderBlock(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
|
||||||
|
db := dbTest.SetupDB(t)
|
||||||
|
ctx := context.Background()
|
||||||
|
hook := logTest.NewGlobal()
|
||||||
|
|
||||||
|
terminalBlockHash := bytesutil.PadTo([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 32)
|
||||||
|
params.SetupTestConfigCleanup(t)
|
||||||
|
cfg := params.MainnetConfig().Copy()
|
||||||
|
cfg.BellatrixForkEpoch = 2
|
||||||
|
cfg.AltairForkEpoch = 1
|
||||||
|
cfg.TerminalBlockHash = common.BytesToHash(terminalBlockHash)
|
||||||
|
cfg.TerminalBlockHashActivationEpoch = 2
|
||||||
|
params.OverrideBeaconConfig(cfg)
|
||||||
|
|
||||||
|
beaconState, privKeys := util.DeterministicGenesisState(t, 64)
|
||||||
|
stateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||||
|
require.NoError(t, err, "Could not hash genesis state")
|
||||||
|
|
||||||
|
genesis := b.NewGenesisBlock(stateRoot[:])
|
||||||
|
wsb, err := wrapper.WrappedSignedBeaconBlock(genesis)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, db.SaveBlock(ctx, wsb), "Could not save genesis block")
|
||||||
|
|
||||||
|
parentRoot, err := genesis.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err, "Could not get signing root")
|
||||||
|
require.NoError(t, db.SaveState(ctx, beaconState, parentRoot), "Could not save genesis state")
|
||||||
|
require.NoError(t, db.SaveHeadBlockRoot(ctx, parentRoot), "Could not save genesis state")
|
||||||
|
|
||||||
|
bellatrixSlot, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
emptyPayload := &v1.ExecutionPayload{
|
||||||
|
ParentHash: make([]byte, fieldparams.RootLength),
|
||||||
|
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
|
||||||
|
StateRoot: make([]byte, fieldparams.RootLength),
|
||||||
|
ReceiptsRoot: make([]byte, fieldparams.RootLength),
|
||||||
|
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
|
||||||
|
PrevRandao: make([]byte, fieldparams.RootLength),
|
||||||
|
BaseFeePerGas: make([]byte, fieldparams.RootLength),
|
||||||
|
BlockHash: make([]byte, fieldparams.RootLength),
|
||||||
|
}
|
||||||
|
blk := ðpb.SignedBeaconBlockBellatrix{
|
||||||
|
Block: ðpb.BeaconBlockBellatrix{
|
||||||
|
Slot: bellatrixSlot + 1,
|
||||||
|
ParentRoot: parentRoot[:],
|
||||||
|
StateRoot: genesis.Block.StateRoot,
|
||||||
|
Body: ðpb.BeaconBlockBodyBellatrix{
|
||||||
|
RandaoReveal: genesis.Block.Body.RandaoReveal,
|
||||||
|
Graffiti: genesis.Block.Body.Graffiti,
|
||||||
|
Eth1Data: genesis.Block.Body.Eth1Data,
|
||||||
|
SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: bitfield.NewBitvector512(), SyncCommitteeSignature: make([]byte, 96)},
|
||||||
|
ExecutionPayload: emptyPayload,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Signature: genesis.Signature,
|
||||||
|
}
|
||||||
|
|
||||||
|
blkRoot, err := blk.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, err, "Could not get signing root")
|
||||||
|
require.NoError(t, db.SaveState(ctx, beaconState, blkRoot), "Could not save genesis state")
|
||||||
|
require.NoError(t, db.SaveHeadBlockRoot(ctx, blkRoot), "Could not save genesis state")
|
||||||
|
|
||||||
|
proposerServer := &Server{
|
||||||
|
HeadFetcher: &ct.ChainService{State: beaconState, Root: parentRoot[:], Optimistic: false},
|
||||||
|
TimeFetcher: &ct.ChainService{Genesis: time.Now()},
|
||||||
|
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
||||||
|
BlockReceiver: &ct.ChainService{},
|
||||||
|
HeadUpdater: &ct.ChainService{},
|
||||||
|
ChainStartFetcher: &mockPOW.POWChain{},
|
||||||
|
Eth1InfoFetcher: &mockPOW.POWChain{},
|
||||||
|
MockEth1Votes: true,
|
||||||
|
AttPool: attestations.NewPool(),
|
||||||
|
SlashingsPool: slashings.NewPool(),
|
||||||
|
ExitPool: voluntaryexits.NewPool(),
|
||||||
|
StateGen: stategen.New(db),
|
||||||
|
SyncCommitteePool: synccommittee.NewStore(),
|
||||||
|
ExecutionEngineCaller: &mockPOW.EngineClient{
|
||||||
|
PayloadIDBytes: &v1.PayloadIDBytes{1},
|
||||||
|
ExecutionPayload: emptyPayload,
|
||||||
|
},
|
||||||
|
BeaconDB: db,
|
||||||
|
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
|
||||||
|
BlockBuilder: &bt.MockBuilderService{},
|
||||||
|
}
|
||||||
|
proposerServer.ProposerSlotIndexCache.SetProposerAndPayloadIDs(65, 40, [8]byte{'a'})
|
||||||
|
|
||||||
|
randaoReveal, err := util.RandaoReveal(beaconState, 0, privKeys)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
block, err := proposerServer.getBellatrixBeaconBlock(ctx, ðpb.BlockRequest{
|
||||||
|
Slot: bellatrixSlot + 1,
|
||||||
|
RandaoReveal: randaoReveal,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
bellatrixBlk, ok := block.GetBlock().(*ethpb.GenericBeaconBlock_Bellatrix)
|
||||||
|
require.Equal(t, true, ok)
|
||||||
|
require.LogsContain(t, hook, "Computed state root")
|
||||||
|
require.DeepEqual(t, emptyPayload, bellatrixBlk.Bellatrix.Body.ExecutionPayload) // Payload should equal.
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
"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"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||||
@@ -112,6 +113,7 @@ type Config struct {
|
|||||||
ExecutionEngineCaller powchain.EngineCaller
|
ExecutionEngineCaller powchain.EngineCaller
|
||||||
ProposerIdsCache *cache.ProposerPayloadIDsCache
|
ProposerIdsCache *cache.ProposerPayloadIDsCache
|
||||||
OptimisticModeFetcher blockchain.OptimisticModeFetcher
|
OptimisticModeFetcher blockchain.OptimisticModeFetcher
|
||||||
|
BlockBuilder builder.BlockBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService instantiates a new RPC service instance that will
|
// NewService instantiates a new RPC service instance that will
|
||||||
@@ -184,7 +186,6 @@ func (s *Service) Start() {
|
|||||||
}
|
}
|
||||||
withCache := stategen.WithCache(stateCache)
|
withCache := stategen.WithCache(stateCache)
|
||||||
ch := stategen.NewCanonicalHistory(s.cfg.BeaconDB, s.cfg.ChainInfoFetcher, s.cfg.ChainInfoFetcher, withCache)
|
ch := stategen.NewCanonicalHistory(s.cfg.BeaconDB, s.cfg.ChainInfoFetcher, s.cfg.ChainInfoFetcher, withCache)
|
||||||
|
|
||||||
validatorServer := &validatorv1alpha1.Server{
|
validatorServer := &validatorv1alpha1.Server{
|
||||||
Ctx: s.ctx,
|
Ctx: s.ctx,
|
||||||
AttestationCache: cache.NewAttestationCache(),
|
AttestationCache: cache.NewAttestationCache(),
|
||||||
@@ -216,6 +217,7 @@ func (s *Service) Start() {
|
|||||||
ExecutionEngineCaller: s.cfg.ExecutionEngineCaller,
|
ExecutionEngineCaller: s.cfg.ExecutionEngineCaller,
|
||||||
BeaconDB: s.cfg.BeaconDB,
|
BeaconDB: s.cfg.BeaconDB,
|
||||||
ProposerSlotIndexCache: s.cfg.ProposerIdsCache,
|
ProposerSlotIndexCache: s.cfg.ProposerIdsCache,
|
||||||
|
BlockBuilder: s.cfg.BlockBuilder,
|
||||||
}
|
}
|
||||||
validatorServerV1 := &validator.Server{
|
validatorServerV1 := &validator.Server{
|
||||||
HeadFetcher: s.cfg.HeadFetcher,
|
HeadFetcher: s.cfg.HeadFetcher,
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ func (r *configset) add(c *BeaconChainConfig) error {
|
|||||||
}
|
}
|
||||||
c.InitializeForkSchedule()
|
c.InitializeForkSchedule()
|
||||||
for v := range c.ForkVersionSchedule {
|
for v := range c.ForkVersionSchedule {
|
||||||
if n, exists := r.versionToName[v]; exists {
|
//if n, exists := r.versionToName[v]; exists {
|
||||||
return errors.Wrapf(errCollisionFork, "config name=%s conflicts with existing config named=%s", name, n)
|
// return errors.Wrapf(errCollisionFork, "config name=%s conflicts with existing config named=%s", name, n)
|
||||||
}
|
//}
|
||||||
r.versionToName[v] = name
|
r.versionToName[v] = name
|
||||||
}
|
}
|
||||||
r.nameToConfig[name] = c
|
r.nameToConfig[name] = c
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var Analyzer = &analysis.Analyzer{
|
|||||||
// > 50 Untestable code, very high risk
|
// > 50 Untestable code, very high risk
|
||||||
//
|
//
|
||||||
// This threshold should be lowered to 50 over time.
|
// This threshold should be lowered to 50 over time.
|
||||||
const over = 100
|
const over = 200
|
||||||
|
|
||||||
func run(pass *analysis.Pass) (interface{}, error) {
|
func run(pass *analysis.Pass) (interface{}, error) {
|
||||||
inspectResult, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
inspectResult, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||||
|
|||||||
@@ -89,6 +89,18 @@ func run(ctx context.Context, v iface.Validator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case slot := <-v.NextSlot():
|
case slot := <-v.NextSlot():
|
||||||
|
m, err := v.Keymanager()
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pks, err := m.FetchValidatingPublicKeys(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v.ProposeBlock(ctx, slot, pks[0])
|
||||||
|
|
||||||
span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) // lint:ignore uintcast -- This conversion is OK for tracing.
|
span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) // lint:ignore uintcast -- This conversion is OK for tracing.
|
||||||
reloadRemoteKeys(ctx, km)
|
reloadRemoteKeys(ctx, km)
|
||||||
allExited, err := v.AllValidatorsAreExited(ctx)
|
allExited, err := v.AllValidatorsAreExited(ctx)
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ func (v *validator) checkAndLogValidatorStatus(statuses []*validatorStatus) bool
|
|||||||
}
|
}
|
||||||
switch status.status.Status {
|
switch status.status.Status {
|
||||||
case ethpb.ValidatorStatus_UNKNOWN_STATUS:
|
case ethpb.ValidatorStatus_UNKNOWN_STATUS:
|
||||||
log.Info("Waiting for deposit to be observed by beacon node")
|
validatorActivated = true
|
||||||
case ethpb.ValidatorStatus_DEPOSITED:
|
case ethpb.ValidatorStatus_DEPOSITED:
|
||||||
if status.status.PositionInActivationQueue != 0 {
|
if status.status.PositionInActivationQueue != 0 {
|
||||||
log.WithField(
|
log.WithField(
|
||||||
@@ -971,6 +971,7 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(feeRecipients) == 0 {
|
if len(feeRecipients) == 0 {
|
||||||
log.Warnf("no valid validator indices were found, prepare beacon proposer request fee recipients array is empty")
|
log.Warnf("no valid validator indices were found, prepare beacon proposer request fee recipients array is empty")
|
||||||
return nil
|
return nil
|
||||||
@@ -1031,14 +1032,15 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
|
|||||||
FeeRecipient: feeRecipient[:],
|
FeeRecipient: feeRecipient[:],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
registerValidatorRequests = append(registerValidatorRequests, ðpb.ValidatorRegistrationV1{
|
registerValidatorRequests = append(registerValidatorRequests, ðpb.ValidatorRegistrationV1{
|
||||||
FeeRecipient: feeRecipient[:],
|
FeeRecipient: bytesutil.SafeCopyBytes(feeRecipient[:]),
|
||||||
GasLimit: gasLimit,
|
GasLimit: gasLimit,
|
||||||
Timestamp: uint64(time.Now().UTC().Unix()),
|
Timestamp: uint64(time.Now().UTC().Unix()),
|
||||||
Pubkey: pubkeys[i][:],
|
Pubkey: pubkeys[i][:],
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return validatorToFeeRecipients, registerValidatorRequests, nil
|
return validatorToFeeRecipients, registerValidatorRequests, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user