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

Fix Overflow in Status Check #5361

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ go_test(
"rpc_ping_test.go",
"rpc_status_test.go",
"rpc_test.go",
"service_test.go",
"subscriber_beacon_aggregate_proof_test.go",
"subscriber_beacon_blocks_test.go",
"subscriber_committee_index_beacon_attestation_test.go",
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/sync/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (r *Service) Status() error {
}
// If our head slot is on a previous epoch and our peers are reporting their head block are
// in the most recent epoch, then we might be out of sync.
if headEpoch := helpers.SlotToEpoch(r.chain.HeadSlot()); headEpoch < helpers.SlotToEpoch(r.chain.CurrentSlot())-1 &&
headEpoch < r.p2p.Peers().CurrentEpoch()-1 {
if headEpoch := helpers.SlotToEpoch(r.chain.HeadSlot()); headEpoch+1 < helpers.SlotToEpoch(r.chain.CurrentSlot()) &&
headEpoch+1 < r.p2p.Peers().CurrentEpoch() {
return errors.New("out of sync")
}
}
Expand Down
33 changes: 33 additions & 0 deletions beacon-chain/sync/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package sync

import (
"testing"
"time"

stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
)

func TestService_StatusZeroEpoch(t *testing.T) {
bState, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 0})
if err != nil {
t.Fatal(err)
}
r := &Service{
p2p: p2ptest.NewTestP2P(t),
initialSync: new(mockSync.Sync),
chain: &mockChain.ChainService{
Genesis: time.Now(),
State: bState,
},
}
r.chainStarted = true

err = r.Status()
if err != nil {
t.Errorf("Wanted non failing status but got: %v", err)
}
}