Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 2 second timeout to fetching eth1data #5583

Merged
merged 10 commits into from
Apr 23, 2020
13 changes: 11 additions & 2 deletions beacon-chain/rpc/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"math/rand"
"time"

"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
Expand Down Expand Up @@ -154,6 +155,9 @@ func (vs *Server) ProposeBlock(ctx context.Context, blk *ethpb.SignedBeaconBlock
// - Subtract that eth1block.number by ETH1_FOLLOW_DISTANCE.
// - This is the eth1block to use for the block proposal.
func (vs *Server) eth1Data(ctx context.Context, slot uint64) (*ethpb.Eth1Data, error) {
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
prestonvanloon marked this conversation as resolved.
Show resolved Hide resolved
defer cancel()

if vs.MockEth1Votes {
return vs.mockETH1DataVote(ctx, slot)
}
Expand All @@ -169,11 +173,13 @@ func (vs *Server) eth1Data(ctx context.Context, slot uint64) (*ethpb.Eth1Data, e
// Look up most recent block up to timestamp
blockNumber, err := vs.Eth1BlockFetcher.BlockNumberByTimestamp(ctx, eth1VotingPeriodStartTime)
if err != nil {
return nil, errors.Wrap(err, "could not get block number from timestamp")
log.WithError(err).Error("Failed to get block number from timestamp")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also could consider warning for these, i dont feel strongly for either, up to you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its an error that should be monitored

return vs.randomETH1DataVote(ctx)
}
eth1Data, err := vs.defaultEth1DataResponse(ctx, blockNumber)
if err != nil {
return nil, errors.Wrap(err, "could not get eth1 data from block number")
log.WithError(err).Error("Failed to get eth1 data from block number")
return vs.randomETH1DataVote(ctx)
}

return eth1Data, nil
Expand Down Expand Up @@ -362,6 +368,9 @@ func (vs *Server) canonicalEth1Data(ctx context.Context, beaconState *stateTrie.
// hash of eth1 block hash that is FOLLOW_DISTANCE back from its
// latest block.
func (vs *Server) defaultEth1DataResponse(ctx context.Context, currentHeight *big.Int) (*ethpb.Eth1Data, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
eth1FollowDistance := int64(params.BeaconConfig().Eth1FollowDistance)
ancestorHeight := big.NewInt(0).Sub(currentHeight, big.NewInt(eth1FollowDistance))
blockHash, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, ancestorHeight)
Expand Down