From 4ea5661f8f80ce367776afd781c5b14139c31c61 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Mon, 27 Jan 2020 01:50:40 +0800 Subject: [PATCH] Clear Pre-Genesis Objects (#4656) * remove pre-genesis data * Merge branch 'master' into clearUnusedObjects * lint * Merge branch 'clearUnusedObjects' of https://github.com/prysmaticlabs/geth-sharding into clearUnusedObjects * fic build * gaz * faulty mock * Update beacon-chain/blockchain/service.go --- beacon-chain/blockchain/service.go | 3 +++ beacon-chain/interop-cold-start/service.go | 5 +++++ beacon-chain/powchain/service.go | 7 +++++++ beacon-chain/powchain/testing/faulty_mock.go | 5 +++++ beacon-chain/powchain/testing/mock.go | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 2c54dea6084..da284b61600 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -224,6 +224,9 @@ func (s *Service) initializeBeaconChain( log.Info("Initialized beacon chain genesis state") + // Clear out all pre-genesis data now that the state is initialized. + s.chainStartFetcher.ClearPreGenesisData() + // Update committee shuffled indices for genesis epoch. if err := helpers.UpdateCommitteeCache(genesisState, 0 /* genesis epoch */); err != nil { return err diff --git a/beacon-chain/interop-cold-start/service.go b/beacon-chain/interop-cold-start/service.go index ab0b2ab96af..dac4b40c070 100644 --- a/beacon-chain/interop-cold-start/service.go +++ b/beacon-chain/interop-cold-start/service.go @@ -127,6 +127,11 @@ func (s *Service) PreGenesisState() *pb.BeaconState { return &pb.BeaconState{} } +// ClearPreGenesisData -- +func (s *Service) ClearPreGenesisData() { + //no-op +} + // DepositByPubkey mocks out the deposit cache functionality for interop. func (s *Service) DepositByPubkey(ctx context.Context, pubKey []byte) (*ethpb.Deposit, *big.Int) { return ðpb.Deposit{}, big.NewInt(1) diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 1b0a90f6d25..6b5eba00fcf 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -65,6 +65,7 @@ type ChainStartFetcher interface { ChainStartDeposits() []*ethpb.Deposit ChainStartEth1Data() *ethpb.Eth1Data PreGenesisState() *pb.BeaconState + ClearPreGenesisData() } // ChainInfoFetcher retrieves information about eth1 metadata at the eth2 genesis time. @@ -241,6 +242,12 @@ func (s *Service) ChainStartDeposits() []*ethpb.Deposit { return s.chainStartData.ChainstartDeposits } +// ClearPreGenesisData clears out the stored chainstart deposits and beacon state. +func (s *Service) ClearPreGenesisData() { + s.chainStartData.ChainstartDeposits = []*ethpb.Deposit{} + s.preGenesisState = &pb.BeaconState{} +} + // ChainStartEth1Data returns the eth1 data at chainstart. func (s *Service) ChainStartEth1Data() *ethpb.Eth1Data { return s.chainStartData.Eth1Data diff --git a/beacon-chain/powchain/testing/faulty_mock.go b/beacon-chain/powchain/testing/faulty_mock.go index 439d1268bdb..2a9429a9b80 100644 --- a/beacon-chain/powchain/testing/faulty_mock.go +++ b/beacon-chain/powchain/testing/faulty_mock.go @@ -77,6 +77,11 @@ func (f *FaultyMockPOWChain) PreGenesisState() *pb.BeaconState { return &pb.BeaconState{} } +// ClearPreGenesisData -- +func (f *FaultyMockPOWChain) ClearPreGenesisData() { + //no-op +} + // IsConnectedToETH1 -- func (f *FaultyMockPOWChain) IsConnectedToETH1() bool { return true diff --git a/beacon-chain/powchain/testing/mock.go b/beacon-chain/powchain/testing/mock.go index bd70a5293bb..c53d62d42c9 100644 --- a/beacon-chain/powchain/testing/mock.go +++ b/beacon-chain/powchain/testing/mock.go @@ -100,6 +100,11 @@ func (m *POWChain) PreGenesisState() *pb.BeaconState { return &pb.BeaconState{} } +// ClearPreGenesisData -- +func (m *POWChain) ClearPreGenesisData() { + //no-op +} + // IsConnectedToETH1 -- func (m *POWChain) IsConnectedToETH1() bool { return true