Extract powchain info to a separate struct

This commit is contained in:
rkapka
2021-01-22 08:09:18 +01:00
parent 45baf6e2b7
commit e01dd5222b
3 changed files with 17 additions and 9 deletions

View File

@@ -37,15 +37,23 @@ const depositlogRequestLimit = 10000
const additiveFactorMultiplier = 0.10
const multiplicativeDecreaseDivisor = 2
// GenesisPowchainInfo contains information about the genesis event.
type GenesisPowchainInfo struct {
Time uint64 // Genesis time.
BlockNumber *big.Int // Eth1 block number.
}
func tooMuchDataRequestedError(err error) bool {
// this error is only infura specific (other providers might have different error messages)
return err.Error() == "query returned more than 10000 results"
}
// Eth2GenesisPowchainInfo retrieves the genesis time and eth1 block number of the beacon chain
// from the deposit contract.
func (s *Service) Eth2GenesisPowchainInfo() (uint64, *big.Int) {
return s.chainStartData.GenesisTime, big.NewInt(int64(s.chainStartData.GenesisBlock))
// Eth2GenesisPowchainInfo retrieves information about genesis.
func (s *Service) Eth2GenesisPowchainInfo() GenesisPowchainInfo {
return GenesisPowchainInfo{
Time: s.chainStartData.GenesisTime,
BlockNumber: big.NewInt(int64(s.chainStartData.GenesisBlock)),
}
}
// ProcessETH1Block processes the logs from the provided eth1Block.

View File

@@ -78,7 +78,7 @@ type ChainStartFetcher interface {
// ChainInfoFetcher retrieves information about eth1 metadata at the eth2 genesis time.
type ChainInfoFetcher interface {
Eth2GenesisPowchainInfo() (uint64, *big.Int)
Eth2GenesisPowchainInfo() GenesisPowchainInfo
IsConnectedToETH1() bool
DepositContractAddress() common.Address
}

View File

@@ -285,8 +285,8 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState *stateTr
}
func (vs *Server) slotStartTime(slot uint64) uint64 {
startTime, _ := vs.Eth1InfoFetcher.Eth2GenesisPowchainInfo()
return helpers.VotingPeriodStartTime(startTime, slot)
genesisInfo := vs.Eth1InfoFetcher.Eth2GenesisPowchainInfo()
return helpers.VotingPeriodStartTime(genesisInfo.Time, slot)
}
func (vs *Server) inRangeVotes(ctx context.Context,
@@ -444,8 +444,8 @@ func (vs *Server) deposits(
return nil, err
}
_, genesisEth1Block := vs.Eth1InfoFetcher.Eth2GenesisPowchainInfo()
if genesisEth1Block.Cmp(canonicalEth1DataHeight) == 0 {
genesisInfo := vs.Eth1InfoFetcher.Eth2GenesisPowchainInfo()
if genesisInfo.BlockNumber.Cmp(canonicalEth1DataHeight) == 0 {
return []*ethpb.Deposit{}, nil
}