|
|
|
@ -76,7 +76,7 @@ func newTesterWithNotification(t *testing.T, success func()) *downloadTester { |
|
|
|
|
chain: chain, |
|
|
|
|
peers: make(map[string]*downloadTesterPeer), |
|
|
|
|
} |
|
|
|
|
tester.downloader = New(db, new(event.TypeMux), tester.chain, nil, tester.dropPeer, success) |
|
|
|
|
tester.downloader = New(db, new(event.TypeMux), tester.chain, tester.dropPeer, success) |
|
|
|
|
return tester |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -384,9 +384,6 @@ func assertOwnChain(t *testing.T, tester *downloadTester, length int) { |
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
|
|
headers, blocks, receipts := length, length, length |
|
|
|
|
if tester.downloader.getMode() == LightSync { |
|
|
|
|
blocks, receipts = 1, 1 |
|
|
|
|
} |
|
|
|
|
if hs := int(tester.chain.CurrentHeader().Number.Uint64()) + 1; hs != headers { |
|
|
|
|
t.Fatalf("synchronised headers mismatch: have %v, want %v", hs, headers) |
|
|
|
|
} |
|
|
|
@ -398,9 +395,8 @@ func assertOwnChain(t *testing.T, tester *downloadTester, length int) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestCanonicalSynchronisation68Full(t *testing.T) { testCanonSync(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestCanonicalSynchronisation68Snap(t *testing.T) { testCanonSync(t, eth.ETH68, SnapSync) } |
|
|
|
|
func TestCanonicalSynchronisation68Light(t *testing.T) { testCanonSync(t, eth.ETH68, LightSync) } |
|
|
|
|
func TestCanonicalSynchronisation68Full(t *testing.T) { testCanonSync(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestCanonicalSynchronisation68Snap(t *testing.T) { testCanonSync(t, eth.ETH68, SnapSync) } |
|
|
|
|
|
|
|
|
|
func testCanonSync(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
success := make(chan struct{}) |
|
|
|
@ -505,9 +501,8 @@ func testThrottling(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that a canceled download wipes all previously accumulated state.
|
|
|
|
|
func TestCancel68Full(t *testing.T) { testCancel(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestCancel68Snap(t *testing.T) { testCancel(t, eth.ETH68, SnapSync) } |
|
|
|
|
func TestCancel68Light(t *testing.T) { testCancel(t, eth.ETH68, LightSync) } |
|
|
|
|
func TestCancel68Full(t *testing.T) { testCancel(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestCancel68Snap(t *testing.T) { testCancel(t, eth.ETH68, SnapSync) } |
|
|
|
|
|
|
|
|
|
func testCancel(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
complete := make(chan struct{}) |
|
|
|
@ -538,9 +533,8 @@ func testCancel(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
|
|
|
|
|
// Tests that synchronisations behave well in multi-version protocol environments
|
|
|
|
|
// and not wreak havoc on other nodes in the network.
|
|
|
|
|
func TestMultiProtoSynchronisation68Full(t *testing.T) { testMultiProtoSync(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestMultiProtoSynchronisation68Snap(t *testing.T) { testMultiProtoSync(t, eth.ETH68, SnapSync) } |
|
|
|
|
func TestMultiProtoSynchronisation68Light(t *testing.T) { testMultiProtoSync(t, eth.ETH68, LightSync) } |
|
|
|
|
func TestMultiProtoSynchronisation68Full(t *testing.T) { testMultiProtoSync(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestMultiProtoSynchronisation68Snap(t *testing.T) { testMultiProtoSync(t, eth.ETH68, SnapSync) } |
|
|
|
|
|
|
|
|
|
func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
complete := make(chan struct{}) |
|
|
|
@ -578,9 +572,8 @@ func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
|
|
|
|
|
// Tests that if a block is empty (e.g. header only), no body request should be
|
|
|
|
|
// made, and instead the header should be assembled into a whole block in itself.
|
|
|
|
|
func TestEmptyShortCircuit68Full(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestEmptyShortCircuit68Snap(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, SnapSync) } |
|
|
|
|
func TestEmptyShortCircuit68Light(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, LightSync) } |
|
|
|
|
func TestEmptyShortCircuit68Full(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestEmptyShortCircuit68Snap(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, SnapSync) } |
|
|
|
|
|
|
|
|
|
func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
success := make(chan struct{}) |
|
|
|
@ -619,7 +612,7 @@ func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
// Validate the number of block bodies that should have been requested
|
|
|
|
|
bodiesNeeded, receiptsNeeded := 0, 0 |
|
|
|
|
for _, block := range chain.blocks[1:] { |
|
|
|
|
if mode != LightSync && (len(block.Transactions()) > 0 || len(block.Uncles()) > 0) { |
|
|
|
|
if len(block.Transactions()) > 0 || len(block.Uncles()) > 0 { |
|
|
|
|
bodiesNeeded++ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -694,9 +687,8 @@ func testBeaconSync(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
|
|
|
|
|
// Tests that synchronisation progress (origin block number, current block number
|
|
|
|
|
// and highest block number) is tracked and updated correctly.
|
|
|
|
|
func TestSyncProgress68Full(t *testing.T) { testSyncProgress(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestSyncProgress68Snap(t *testing.T) { testSyncProgress(t, eth.ETH68, SnapSync) } |
|
|
|
|
func TestSyncProgress68Light(t *testing.T) { testSyncProgress(t, eth.ETH68, LightSync) } |
|
|
|
|
func TestSyncProgress68Full(t *testing.T) { testSyncProgress(t, eth.ETH68, FullSync) } |
|
|
|
|
func TestSyncProgress68Snap(t *testing.T) { testSyncProgress(t, eth.ETH68, SnapSync) } |
|
|
|
|
|
|
|
|
|
func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
success := make(chan struct{}) |
|
|
|
@ -734,17 +726,7 @@ func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) { |
|
|
|
|
if err := tester.downloader.BeaconSync(mode, chain.blocks[len(chain.blocks)-1].Header(), nil); err != nil { |
|
|
|
|
t.Fatalf("failed to beacon-sync chain: %v", err) |
|
|
|
|
} |
|
|
|
|
var startingBlock uint64 |
|
|
|
|
if mode == LightSync { |
|
|
|
|
// in light-sync mode:
|
|
|
|
|
// * the starting block is 0 on the second sync cycle because blocks
|
|
|
|
|
// are never downloaded.
|
|
|
|
|
// * The current/highest blocks reported in the progress reflect the
|
|
|
|
|
// current/highest header.
|
|
|
|
|
startingBlock = 0 |
|
|
|
|
} else { |
|
|
|
|
startingBlock = uint64(len(chain.blocks)/2 - 1) |
|
|
|
|
} |
|
|
|
|
startingBlock := uint64(len(chain.blocks)/2 - 1) |
|
|
|
|
|
|
|
|
|
select { |
|
|
|
|
case <-success: |
|
|
|
|