Add GenesisValidatorsRoot to GetGenesis (#5619)

* Add GenesisValidatorsRoot to GetGenesis

* Add genesis state

* Add to test

* Change to get val root from genesis fetcher

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Ivan Martinez
2020-04-27 02:31:50 -04:00
committed by GitHub
parent 07e8609b69
commit eb5513f8c2
6 changed files with 22 additions and 1 deletions

View File

@@ -1305,7 +1305,7 @@ go_repository(
go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "1c66911b2ef3c1a290abb2156bcecb33ac32725f",
commit = "ba9042096e9fc49606279513d3e24e5e8cdbd5a0",
importpath = "github.com/prysmaticlabs/ethereumapis",
)

View File

@@ -547,6 +547,7 @@ func (b *BeaconNode) registerRPCService(ctx *cli.Context) error {
BlockReceiver: chainService,
AttestationReceiver: chainService,
GenesisTimeFetcher: chainService,
GenesisFetcher: chainService,
AttestationsPool: b.attestationPool,
ExitPool: b.exitPool,
SlashingsPool: b.slashingsPool,

View File

@@ -29,6 +29,8 @@ go_test(
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/testutil:go_default_library",
"//shared/version:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",

View File

@@ -27,6 +27,7 @@ type Server struct {
BeaconDB db.ReadOnlyDatabase
PeersFetcher p2p.PeersProvider
GenesisTimeFetcher blockchain.TimeFetcher
GenesisFetcher blockchain.GenesisFetcher
}
// GetSyncStatus checks the current network sync status of the node.
@@ -47,9 +48,11 @@ func (ns *Server) GetGenesis(ctx context.Context, _ *ptypes.Empty) (*ethpb.Genes
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not convert genesis time to proto: %v", err)
}
genValRoot := ns.GenesisFetcher.GenesisValidatorRoot()
return &ethpb.Genesis{
GenesisTime: gt,
DepositContractAddress: contractAddr,
GenesisValidatorsRoot: genValRoot[:],
}, nil
}

View File

@@ -13,6 +13,8 @@ import (
dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
mockP2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/version"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
@@ -48,9 +50,15 @@ func TestNodeServer_GetGenesis(t *testing.T) {
if err := db.SaveDepositContractAddress(ctx, addr); err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
genValRoot := bytesutil.ToBytes32([]byte("I am root"))
ns := &Server{
BeaconDB: db,
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Unix(0, 0)},
GenesisFetcher: &mock.ChainService{
State: st,
ValidatorsRoot: genValRoot,
},
}
res, err := ns.GetGenesis(context.Background(), &ptypes.Empty{})
if err != nil {
@@ -66,6 +74,9 @@ func TestNodeServer_GetGenesis(t *testing.T) {
if !res.GenesisTime.Equal(pUnix) {
t.Errorf("Wanted GenesisTime() = %v, received %v", pUnix, res.GenesisTime)
}
if !bytes.Equal(genValRoot[:], res.GenesisValidatorsRoot) {
t.Errorf("Wanted GenesisValidatorsRoot = %v, received %v", genValRoot, res.GenesisValidatorsRoot)
}
}
func TestNodeServer_GetVersion(t *testing.T) {

View File

@@ -59,6 +59,7 @@ type Service struct {
finalizationFetcher blockchain.FinalizationFetcher
participationFetcher blockchain.ParticipationFetcher
genesisTimeFetcher blockchain.TimeFetcher
genesisFetcher blockchain.GenesisFetcher
attestationReceiver blockchain.AttestationReceiver
blockReceiver blockchain.BlockReceiver
powChainService powchain.Chain
@@ -108,6 +109,7 @@ type Config struct {
POWChainService powchain.Chain
ChainStartFetcher powchain.ChainStartFetcher
GenesisTimeFetcher blockchain.TimeFetcher
GenesisFetcher blockchain.GenesisFetcher
MockEth1Votes bool
AttestationsPool attestations.Pool
ExitPool *voluntaryexits.Pool
@@ -138,6 +140,7 @@ func NewService(ctx context.Context, cfg *Config) *Service {
finalizationFetcher: cfg.FinalizationFetcher,
participationFetcher: cfg.ParticipationFetcher,
genesisTimeFetcher: cfg.GenesisTimeFetcher,
genesisFetcher: cfg.GenesisFetcher,
attestationReceiver: cfg.AttestationReceiver,
blockReceiver: cfg.BlockReceiver,
p2p: cfg.Broadcaster,
@@ -241,6 +244,7 @@ func (s *Service) Start() {
SyncChecker: s.syncService,
GenesisTimeFetcher: s.genesisTimeFetcher,
PeersFetcher: s.peersFetcher,
GenesisFetcher: s.genesisFetcher,
}
beaconChainServer := &beacon.Server{
Ctx: s.ctx,