[apr] Follow breadcrumb with hash and number (#2532)

pull/2536/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 26a17808db
commit 12977230c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      staking/apr/compute.go

@ -18,6 +18,8 @@ import (
type Reader interface { type Reader interface {
Config() *params.ChainConfig Config() *params.ChainConfig
GetHeaderByHash(hash common.Hash) *block.Header GetHeaderByHash(hash common.Hash) *block.Header
// GetHeader retrieves a block header from the database by hash and number.
GetHeader(hash common.Hash, number uint64) *block.Header
CurrentHeader() *block.Header CurrentHeader() *block.Header
ReadValidatorSnapshotAtEpoch( ReadValidatorSnapshotAtEpoch(
epoch *big.Int, epoch *big.Int,
@ -80,7 +82,7 @@ func pastTwoEpochHeaders(
var oneAgoHeader, twoAgoHeader **block.Header var oneAgoHeader, twoAgoHeader **block.Header
for e1, e2 := false, false; ; { for e1, e2 := false, false; ; {
current = bc.GetHeaderByHash(current.ParentHash()) current = bc.GetHeader(current.ParentHash(), current.Number().Uint64()-1)
if current == nil { if current == nil {
return nil, nil, errors.New("could not go up parent") return nil, nil, errors.New("could not go up parent")
@ -139,9 +141,6 @@ func ComputeForValidator(
) )
if err != nil { if err != nil {
utils.Logger().Debug().
RawJSON("validator-now", []byte(validatorNow.String())).
Err(err).Msg("could not retrieve two snapshot ago")
return &zero, nil return &zero, nil
} }
@ -151,9 +150,6 @@ func ComputeForValidator(
) )
if err != nil { if err != nil {
utils.Logger().Debug().
RawJSON("validator-now", []byte(validatorNow.String())).
Err(err).Msg("could not retrieve one snapshot ago")
return &zero, nil return &zero, nil
} }
@ -163,11 +159,6 @@ func ComputeForValidator(
headerOneEpochAgo, headerTwoEpochAgo, err := pastTwoEpochHeaders(bc) headerOneEpochAgo, headerTwoEpochAgo, err := pastTwoEpochHeaders(bc)
if err != nil {
utils.Logger().Debug().Err(err).Msg("could not retrieve past two epoch headers")
return &zero, nil
}
// TODO Figure out why this is happening // TODO Figure out why this is happening
if headerOneEpochAgo == nil || headerTwoEpochAgo == nil || err != nil { if headerOneEpochAgo == nil || headerTwoEpochAgo == nil || err != nil {
utils.Logger().Debug(). utils.Logger().Debug().

Loading…
Cancel
Save