Revert "Prevent Reorg Infinite Loops in Initial Sync (#2109)" (#2110)

This reverts commit d0790246a2.
This commit is contained in:
Raul Jordan
2019-03-29 16:51:58 -05:00
committed by GitHub
parent d0790246a2
commit 5b89da1ce2
9 changed files with 197 additions and 321 deletions

View File

@@ -51,6 +51,16 @@ func (ms *mockSyncService) ResumeSync() {
}
type mockChainService struct{}
func (m *mockChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) (*pb.BeaconState, error) {
return &pb.BeaconState{}, nil
}
func (m *mockChainService) ApplyForkChoiceRule(ctx context.Context, block *pb.BeaconBlock, computedState *pb.BeaconState) error {
return nil
}
func setUpGenesisStateAndBlock(beaconDB *db.BeaconDB, t *testing.T) {
ctx := context.Background()
genesisTime := time.Now()
@@ -83,9 +93,10 @@ func TestSavingBlock_InSync(t *testing.T) {
setUpGenesisStateAndBlock(db, t)
cfg := &Config{
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
ChainService: &mockChainService{},
}
ss := NewInitialSyncService(context.Background(), cfg)
ss.reqState = false
@@ -106,17 +117,12 @@ func TestSavingBlock_InSync(t *testing.T) {
genericHash := make([]byte, 32)
genericHash[0] = 'a'
fState := &pb.BeaconState{
beaconState := &pb.BeaconState{
FinalizedEpoch: params.BeaconConfig().GenesisSlot + 1,
}
jState := &pb.BeaconState{
JustifiedEpoch: params.BeaconConfig().GenesisSlot + 2,
}
stateResponse := &pb.BeaconStateResponse{
FinalizedState: fState,
JustifiedState: jState,
CanonicalState: jState,
BeaconState: beaconState,
}
incorrectState := &pb.BeaconState{
@@ -125,12 +131,10 @@ func TestSavingBlock_InSync(t *testing.T) {
}
incorrectStateResponse := &pb.BeaconStateResponse{
FinalizedState: incorrectState,
JustifiedState: incorrectState,
CanonicalState: incorrectState,
BeaconState: incorrectState,
}
stateRoot, err := hashutil.HashProto(fState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("unable to tree hash state: %v", err)
}
@@ -175,7 +179,7 @@ func TestSavingBlock_InSync(t *testing.T) {
ss.stateBuf <- msg2
if ss.currentSlot == incorrectStateResponse.CanonicalState.FinalizedEpoch*params.BeaconConfig().SlotsPerEpoch {
if ss.currentSlot == incorrectStateResponse.BeaconState.FinalizedEpoch*params.BeaconConfig().SlotsPerEpoch {
t.Fatalf("Beacon state updated incorrectly: %d", ss.currentSlot)
}
@@ -186,10 +190,7 @@ func TestSavingBlock_InSync(t *testing.T) {
msg1 = getBlockResponseMsg(params.BeaconConfig().GenesisSlot + 1)
ss.blockBuf <- msg1
if params.BeaconConfig().GenesisSlot+1 != ss.currentSlot {
t.Fatalf(
"Slot saved when it was not supposed too: %v",
stateResponse.CanonicalState.FinalizedEpoch*params.BeaconConfig().SlotsPerEpoch,
)
t.Fatalf("Slot saved when it was not supposed too: %v", stateResponse.BeaconState.FinalizedEpoch*params.BeaconConfig().SlotsPerEpoch)
}
msg1 = getBlockResponseMsg(params.BeaconConfig().GenesisSlot + 2)
@@ -213,9 +214,10 @@ func TestProcessingBatchedBlocks_OK(t *testing.T) {
setUpGenesisStateAndBlock(db, t)
cfg := &Config{
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
ChainService: &mockChainService{},
}
ss := NewInitialSyncService(context.Background(), cfg)
ss.reqState = false
@@ -254,9 +256,10 @@ func TestProcessingBlocks_SkippedSlots(t *testing.T) {
setUpGenesisStateAndBlock(db, t)
cfg := &Config{
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
ChainService: &mockChainService{},
}
ss := NewInitialSyncService(context.Background(), cfg)
ss.reqState = false
@@ -314,9 +317,10 @@ func TestDelayChan_OK(t *testing.T) {
setUpGenesisStateAndBlock(db, t)
cfg := &Config{
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
P2P: &mockP2P{},
SyncService: &mockSyncService{},
BeaconDB: db,
ChainService: &mockChainService{},
}
ss := NewInitialSyncService(context.Background(), cfg)
ss.reqState = false
@@ -337,20 +341,15 @@ func TestDelayChan_OK(t *testing.T) {
genericHash := make([]byte, 32)
genericHash[0] = 'a'
fState := &pb.BeaconState{
FinalizedEpoch: params.BeaconConfig().GenesisEpoch + 1,
}
jState := &pb.BeaconState{
FinalizedEpoch: params.BeaconConfig().GenesisEpoch + 1,
JustifiedEpoch: params.BeaconConfig().GenesisEpoch + 2,
beaconState := &pb.BeaconState{
FinalizedEpoch: params.BeaconConfig().GenesisSlot + 1,
}
stateResponse := &pb.BeaconStateResponse{
FinalizedState: fState,
JustifiedState: jState,
BeaconState: beaconState,
}
stateRoot, err := hashutil.HashProto(fState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("unable to tree hash state: %v", err)
}
@@ -410,6 +409,7 @@ func TestRequestBlocksBySlot_OK(t *testing.T) {
cfg := &Config{
P2P: &mockP2P{},
SyncService: &mockSyncService{},
ChainService: &mockChainService{},
BeaconDB: db,
BlockBufferSize: 100,
}