fix tests

This commit is contained in:
wanwiset25 2024-06-28 14:23:47 +04:00
parent 829ca9f198
commit 4be4f2eeb1
13 changed files with 278 additions and 227 deletions

View file

@ -1774,10 +1774,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
return 0, events, coalescedLogs, nil
}
func (bc *BlockChain) InsertBlock(block *types.Block) (int, error) {
func (bc *BlockChain) InsertBlock(block *types.Block) error {
events, logs, err := bc.insertBlock(block)
bc.PostChainEvents(events, logs)
return 0, err
return err
}
func (bc *BlockChain) PrepareBlock(block *types.Block) (err error) {

View file

@ -51,6 +51,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/miner"
"github.com/XinFinOrg/XDPoSChain/node"
"github.com/XinFinOrg/XDPoSChain/p2p"
"github.com/XinFinOrg/XDPoSChain/p2p/enr"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/rpc"

View file

@ -674,9 +674,12 @@ func TestCanonicalSynchronisation63Full(t *testing.T) { testCanonicalSynchronisa
func TestCanonicalSynchronisation63Fast(t *testing.T) { testCanonicalSynchronisation(t, 63, FastSync) }
func TestCanonicalSynchronisation64Full(t *testing.T) { testCanonicalSynchronisation(t, 64, FullSync) }
func TestCanonicalSynchronisation64Fast(t *testing.T) { testCanonicalSynchronisation(t, 64, FastSync) }
func TestCanonicalSynchronisation64Light(t *testing.T) {
testCanonicalSynchronisation(t, 64, LightSync)
}
func TestCanonicalSynchronisation64Light(t *testing.T) {testCanonicalSynchronisation(t, 64, LightSync)}
func TestCanonicalSynchronisation100Full(t *testing.T) { testCanonicalSynchronisation(t, 100, FullSync) }
func TestCanonicalSynchronisation100Fast(t *testing.T) { testCanonicalSynchronisation(t, 100, FastSync) }
func TestCanonicalSynchronisation101Full(t *testing.T) { testCanonicalSynchronisation(t, 101, FullSync) }
func TestCanonicalSynchronisation101Fast(t *testing.T) { testCanonicalSynchronisation(t, 101, FastSync) }
func TestCanonicalSynchronisation101Light(t *testing.T) {testCanonicalSynchronisation(t, 101, LightSync)}
func testCanonicalSynchronisation(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -704,6 +707,10 @@ func TestThrottling63Full(t *testing.T) { testThrottling(t, 63, FullSync) }
func TestThrottling63Fast(t *testing.T) { testThrottling(t, 63, FastSync) }
func TestThrottling64Full(t *testing.T) { testThrottling(t, 64, FullSync) }
func TestThrottling64Fast(t *testing.T) { testThrottling(t, 64, FastSync) }
func TestThrottling100Full(t *testing.T) { testThrottling(t, 100, FullSync) }
func TestThrottling100Fast(t *testing.T) { testThrottling(t, 100, FastSync) }
func TestThrottling101Full(t *testing.T) { testThrottling(t, 101, FullSync) }
func TestThrottling101Fast(t *testing.T) { testThrottling(t, 101, FastSync) }
func testThrottling(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -791,6 +798,11 @@ func TestForkedSync63Fast(t *testing.T) { testForkedSync(t, 63, FastSync) }
func TestForkedSync64Full(t *testing.T) { testForkedSync(t, 64, FullSync) }
func TestForkedSync64Fast(t *testing.T) { testForkedSync(t, 64, FastSync) }
func TestForkedSync64Light(t *testing.T) { testForkedSync(t, 64, LightSync) }
func TestForkedSync100Full(t *testing.T) { testForkedSync(t, 100, FullSync) }
func TestForkedSync100Fast(t *testing.T) { testForkedSync(t, 100, FastSync) }
func TestForkedSync101Full(t *testing.T) { testForkedSync(t, 101, FullSync) }
func TestForkedSync101Fast(t *testing.T) { testForkedSync(t, 101, FastSync) }
func TestForkedSync101Light(t *testing.T) { testForkedSync(t, 101, LightSync) }
func testForkedSync(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -826,6 +838,11 @@ func TestHeavyForkedSync63Fast(t *testing.T) { testHeavyForkedSync(t, 63, FastS
func TestHeavyForkedSync64Full(t *testing.T) { testHeavyForkedSync(t, 64, FullSync) }
func TestHeavyForkedSync64Fast(t *testing.T) { testHeavyForkedSync(t, 64, FastSync) }
func TestHeavyForkedSync64Light(t *testing.T) { testHeavyForkedSync(t, 64, LightSync) }
func TestHeavyForkedSync100Full(t *testing.T) { testHeavyForkedSync(t, 100, FullSync) }
func TestHeavyForkedSync100Fast(t *testing.T) { testHeavyForkedSync(t, 100, FastSync) }
func TestHeavyForkedSync101Full(t *testing.T) { testHeavyForkedSync(t, 101, FullSync) }
func TestHeavyForkedSync101Fast(t *testing.T) { testHeavyForkedSync(t, 101, FastSync) }
func TestHeavyForkedSync101Light(t *testing.T) { testHeavyForkedSync(t, 101, LightSync) }
func testHeavyForkedSync(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -862,6 +879,11 @@ func TestBoundedForkedSync63Fast(t *testing.T) { testBoundedForkedSync(t, 63, F
func TestBoundedForkedSync64Full(t *testing.T) { testBoundedForkedSync(t, 64, FullSync) }
func TestBoundedForkedSync64Fast(t *testing.T) { testBoundedForkedSync(t, 64, FastSync) }
func TestBoundedForkedSync64Light(t *testing.T) { testBoundedForkedSync(t, 64, LightSync) }
func TestBoundedForkedSync100Full(t *testing.T) { testBoundedForkedSync(t, 100, FullSync) }
func TestBoundedForkedSync100Fast(t *testing.T) { testBoundedForkedSync(t, 100, FastSync) }
func TestBoundedForkedSync101Full(t *testing.T) { testBoundedForkedSync(t, 101, FullSync) }
func TestBoundedForkedSync101Fast(t *testing.T) { testBoundedForkedSync(t, 101, FastSync) }
func TestBoundedForkedSync101Light(t *testing.T) { testBoundedForkedSync(t, 101, LightSync) }
func testBoundedForkedSync(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -891,15 +913,18 @@ func testBoundedForkedSync(t *testing.T, protocol int, mode SyncMode) {
// Tests that chain forks are contained within a certain interval of the current
// chain head for short but heavy forks too. These are a bit special because they
// take different ancestor lookup paths.
func TestBoundedHeavyForkedSync62(t *testing.T) { testBoundedHeavyForkedSync(t, 62, FullSync) }
func TestBoundedHeavyForkedSync63Full(t *testing.T) { testBoundedHeavyForkedSync(t, 63, FullSync) }
func TestBoundedHeavyForkedSync63Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 63, FastSync) }
func TestBoundedHeavyForkedSync64Full(t *testing.T) { testBoundedHeavyForkedSync(t, 64, FullSync) }
func TestBoundedHeavyForkedSync64Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 64, FastSync) }
func TestBoundedHeavyForkedSync64Light(t *testing.T) { testBoundedHeavyForkedSync(t, 64, LightSync) }
func TestBoundedHeavyForkedSync62(t *testing.T) { testBoundedHeavyForkedSync(t, 62, FullSync) }
func TestBoundedHeavyForkedSync63Full(t *testing.T) { testBoundedHeavyForkedSync(t, 63, FullSync) }
func TestBoundedHeavyForkedSync63Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 63, FastSync) }
func TestBoundedHeavyForkedSync64Full(t *testing.T) { testBoundedHeavyForkedSync(t, 64, FullSync) }
func TestBoundedHeavyForkedSync64Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 64, FastSync) }
func TestBoundedHeavyForkedSync64Light(t *testing.T) { testBoundedHeavyForkedSync(t, 64, LightSync) }
func TestBoundedHeavyForkedSync100Full(t *testing.T) { testBoundedHeavyForkedSync(t, 100, FullSync) }
func TestBoundedHeavyForkedSync100Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 100, FastSync) }
func TestBoundedHeavyForkedSync100Light(t *testing.T) { testBoundedHeavyForkedSync(t, 100, LightSync) }
func TestBoundedHeavyForkedSync101Full(t *testing.T) { testBoundedHeavyForkedSync(t, 101, FullSync) }
func TestBoundedHeavyForkedSync101Fast(t *testing.T) { testBoundedHeavyForkedSync(t, 101, FastSync) }
func TestBoundedHeavyForkedSync101Light(t *testing.T) { testBoundedHeavyForkedSync(t, 101, LightSync) }
func testBoundedHeavyForkedSync(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -964,15 +989,18 @@ func TestInactiveDownloader63(t *testing.T) {
}
// Tests that a canceled download wipes all previously accumulated state.
func TestCancel62(t *testing.T) { testCancel(t, 62, FullSync) }
func TestCancel63Full(t *testing.T) { testCancel(t, 63, FullSync) }
func TestCancel63Fast(t *testing.T) { testCancel(t, 63, FastSync) }
func TestCancel64Full(t *testing.T) { testCancel(t, 64, FullSync) }
func TestCancel64Fast(t *testing.T) { testCancel(t, 64, FastSync) }
func TestCancel64Light(t *testing.T) { testCancel(t, 64, LightSync) }
func TestCancel62(t *testing.T) { testCancel(t, 62, FullSync) }
func TestCancel63Full(t *testing.T) { testCancel(t, 63, FullSync) }
func TestCancel63Fast(t *testing.T) { testCancel(t, 63, FastSync) }
func TestCancel64Full(t *testing.T) { testCancel(t, 64, FullSync) }
func TestCancel64Fast(t *testing.T) { testCancel(t, 64, FastSync) }
func TestCancel64Light(t *testing.T) { testCancel(t, 64, LightSync) }
func TestCancel100Full(t *testing.T) { testCancel(t, 100, FullSync) }
func TestCancel100Fast(t *testing.T) { testCancel(t, 100, FastSync) }
func TestCancel100Light(t *testing.T) { testCancel(t, 100, LightSync) }
func TestCancel101Full(t *testing.T) { testCancel(t, 101, FullSync) }
func TestCancel101Fast(t *testing.T) { testCancel(t, 101, FastSync) }
func TestCancel101Light(t *testing.T) { testCancel(t, 101, LightSync) }
func testCancel(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1008,15 +1036,18 @@ func testCancel(t *testing.T, protocol int, mode SyncMode) {
}
// Tests that synchronisation from multiple peers works as intended (multi thread sanity test).
func TestMultiSynchronisation62(t *testing.T) { testMultiSynchronisation(t, 62, FullSync) }
func TestMultiSynchronisation63Full(t *testing.T) { testMultiSynchronisation(t, 63, FullSync) }
func TestMultiSynchronisation63Fast(t *testing.T) { testMultiSynchronisation(t, 63, FastSync) }
func TestMultiSynchronisation64Full(t *testing.T) { testMultiSynchronisation(t, 64, FullSync) }
func TestMultiSynchronisation64Fast(t *testing.T) { testMultiSynchronisation(t, 64, FastSync) }
func TestMultiSynchronisation64Light(t *testing.T) { testMultiSynchronisation(t, 64, LightSync) }
func TestMultiSynchronisation62(t *testing.T) { testMultiSynchronisation(t, 62, FullSync) }
func TestMultiSynchronisation63Full(t *testing.T) { testMultiSynchronisation(t, 63, FullSync) }
func TestMultiSynchronisation63Fast(t *testing.T) { testMultiSynchronisation(t, 63, FastSync) }
func TestMultiSynchronisation64Full(t *testing.T) { testMultiSynchronisation(t, 64, FullSync) }
func TestMultiSynchronisation64Fast(t *testing.T) { testMultiSynchronisation(t, 64, FastSync) }
func TestMultiSynchronisation64Light(t *testing.T) { testMultiSynchronisation(t, 64, LightSync) }
func TestMultiSynchronisation100Full(t *testing.T) { testMultiSynchronisation(t, 100, FullSync) }
func TestMultiSynchronisation100Fast(t *testing.T) { testMultiSynchronisation(t, 100, FastSync) }
func TestMultiSynchronisation100Light(t *testing.T) { testMultiSynchronisation(t, 100, LightSync) }
func TestMultiSynchronisation101Full(t *testing.T) { testMultiSynchronisation(t, 101, FullSync) }
func TestMultiSynchronisation101Fast(t *testing.T) { testMultiSynchronisation(t, 101, FastSync) }
func TestMultiSynchronisation101Light(t *testing.T) { testMultiSynchronisation(t, 101, LightSync) }
func testMultiSynchronisation(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1041,15 +1072,18 @@ func testMultiSynchronisation(t *testing.T, protocol int, mode SyncMode) {
// Tests that synchronisations behave well in multi-version protocol environments
// and not wreak havoc on other nodes in the network.
func TestMultiProtoSynchronisation62(t *testing.T) { testMultiProtoSync(t, 62, FullSync) }
func TestMultiProtoSynchronisation63Full(t *testing.T) { testMultiProtoSync(t, 63, FullSync) }
func TestMultiProtoSynchronisation63Fast(t *testing.T) { testMultiProtoSync(t, 63, FastSync) }
func TestMultiProtoSynchronisation64Full(t *testing.T) { testMultiProtoSync(t, 64, FullSync) }
func TestMultiProtoSynchronisation64Fast(t *testing.T) { testMultiProtoSync(t, 64, FastSync) }
func TestMultiProtoSynchronisation64Light(t *testing.T) { testMultiProtoSync(t, 64, LightSync) }
func TestMultiProtoSynchronisation62(t *testing.T) { testMultiProtoSync(t, 62, FullSync) }
func TestMultiProtoSynchronisation63Full(t *testing.T) { testMultiProtoSync(t, 63, FullSync) }
func TestMultiProtoSynchronisation63Fast(t *testing.T) { testMultiProtoSync(t, 63, FastSync) }
func TestMultiProtoSynchronisation64Full(t *testing.T) { testMultiProtoSync(t, 64, FullSync) }
func TestMultiProtoSynchronisation64Fast(t *testing.T) { testMultiProtoSync(t, 64, FastSync) }
func TestMultiProtoSynchronisation64Light(t *testing.T) { testMultiProtoSync(t, 64, LightSync) }
func TestMultiProtoSynchronisation100Full(t *testing.T) { testMultiProtoSync(t, 100, FullSync) }
func TestMultiProtoSynchronisation100Fast(t *testing.T) { testMultiProtoSync(t, 100, FastSync) }
func TestMultiProtoSynchronisation100Light(t *testing.T) { testMultiProtoSync(t, 100, LightSync) }
func TestMultiProtoSynchronisation101Full(t *testing.T) { testMultiProtoSync(t, 101, FullSync) }
func TestMultiProtoSynchronisation101Fast(t *testing.T) { testMultiProtoSync(t, 101, FastSync) }
func TestMultiProtoSynchronisation101Light(t *testing.T) { testMultiProtoSync(t, 101, LightSync) }
func testMultiProtoSync(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1066,6 +1100,7 @@ func testMultiProtoSync(t *testing.T, protocol int, mode SyncMode) {
tester.newPeer("peer 63", 63, hashes, headers, blocks, receipts)
tester.newPeer("peer 64", 64, hashes, headers, blocks, receipts)
tester.newPeer("peer 100", 100, hashes, headers, blocks, receipts)
tester.newPeer("peer 101", 101, hashes, headers, blocks, receipts)
// Synchronise with the requested peer and make sure all blocks were retrieved
if err := tester.sync(fmt.Sprintf("peer %d", protocol), nil, mode); err != nil {
@ -1074,7 +1109,7 @@ func testMultiProtoSync(t *testing.T, protocol int, mode SyncMode) {
assertOwnChain(t, tester, targetBlocks+1)
// Check that no peers have been dropped off
for _, version := range []int{62, 63, 64, 100} {
for _, version := range []int{62, 63, 64, 100, 101} {
peer := fmt.Sprintf("peer %d", version)
if _, ok := tester.peerHashes[peer]; !ok {
t.Errorf("%s dropped", peer)
@ -1084,15 +1119,18 @@ func testMultiProtoSync(t *testing.T, protocol int, 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 TestEmptyShortCircuit62(t *testing.T) { testEmptyShortCircuit(t, 62, FullSync) }
func TestEmptyShortCircuit63Full(t *testing.T) { testEmptyShortCircuit(t, 63, FullSync) }
func TestEmptyShortCircuit63Fast(t *testing.T) { testEmptyShortCircuit(t, 63, FastSync) }
func TestEmptyShortCircuit64Full(t *testing.T) { testEmptyShortCircuit(t, 64, FullSync) }
func TestEmptyShortCircuit64Fast(t *testing.T) { testEmptyShortCircuit(t, 64, FastSync) }
func TestEmptyShortCircuit64Light(t *testing.T) { testEmptyShortCircuit(t, 64, LightSync) }
func TestEmptyShortCircuit62(t *testing.T) { testEmptyShortCircuit(t, 62, FullSync) }
func TestEmptyShortCircuit63Full(t *testing.T) { testEmptyShortCircuit(t, 63, FullSync) }
func TestEmptyShortCircuit63Fast(t *testing.T) { testEmptyShortCircuit(t, 63, FastSync) }
func TestEmptyShortCircuit64Full(t *testing.T) { testEmptyShortCircuit(t, 64, FullSync) }
func TestEmptyShortCircuit64Fast(t *testing.T) { testEmptyShortCircuit(t, 64, FastSync) }
func TestEmptyShortCircuit64Light(t *testing.T) { testEmptyShortCircuit(t, 64, LightSync) }
func TestEmptyShortCircuit100Full(t *testing.T) { testEmptyShortCircuit(t, 100, FullSync) }
func TestEmptyShortCircuit100Fast(t *testing.T) { testEmptyShortCircuit(t, 100, FastSync) }
func TestEmptyShortCircuit100Light(t *testing.T) { testEmptyShortCircuit(t, 100, LightSync) }
func TestEmptyShortCircuit101Full(t *testing.T) { testEmptyShortCircuit(t, 101, FullSync) }
func TestEmptyShortCircuit101Fast(t *testing.T) { testEmptyShortCircuit(t, 101, FastSync) }
func TestEmptyShortCircuit101Light(t *testing.T) { testEmptyShortCircuit(t, 101, LightSync) }
func testEmptyShortCircuit(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1142,15 +1180,18 @@ func testEmptyShortCircuit(t *testing.T, protocol int, mode SyncMode) {
// Tests that headers are enqueued continuously, preventing malicious nodes from
// stalling the downloader by feeding gapped header chains.
func TestMissingHeaderAttack62(t *testing.T) { testMissingHeaderAttack(t, 62, FullSync) }
func TestMissingHeaderAttack63Full(t *testing.T) { testMissingHeaderAttack(t, 63, FullSync) }
func TestMissingHeaderAttack63Fast(t *testing.T) { testMissingHeaderAttack(t, 63, FastSync) }
func TestMissingHeaderAttack64Full(t *testing.T) { testMissingHeaderAttack(t, 64, FullSync) }
func TestMissingHeaderAttack64Fast(t *testing.T) { testMissingHeaderAttack(t, 64, FastSync) }
func TestMissingHeaderAttack64Light(t *testing.T) { testMissingHeaderAttack(t, 64, LightSync) }
func TestMissingHeaderAttack62(t *testing.T) { testMissingHeaderAttack(t, 62, FullSync) }
func TestMissingHeaderAttack63Full(t *testing.T) { testMissingHeaderAttack(t, 63, FullSync) }
func TestMissingHeaderAttack63Fast(t *testing.T) { testMissingHeaderAttack(t, 63, FastSync) }
func TestMissingHeaderAttack64Full(t *testing.T) { testMissingHeaderAttack(t, 64, FullSync) }
func TestMissingHeaderAttack64Fast(t *testing.T) { testMissingHeaderAttack(t, 64, FastSync) }
func TestMissingHeaderAttack64Light(t *testing.T) { testMissingHeaderAttack(t, 64, LightSync) }
func TestMissingHeaderAttack100Full(t *testing.T) { testMissingHeaderAttack(t, 100, FullSync) }
func TestMissingHeaderAttack100Fast(t *testing.T) { testMissingHeaderAttack(t, 100, FastSync) }
func TestMissingHeaderAttack100Light(t *testing.T) { testMissingHeaderAttack(t, 100, LightSync) }
func TestMissingHeaderAttack101Full(t *testing.T) { testMissingHeaderAttack(t, 101, FullSync) }
func TestMissingHeaderAttack101Fast(t *testing.T) { testMissingHeaderAttack(t, 101, FastSync) }
func TestMissingHeaderAttack101Light(t *testing.T) { testMissingHeaderAttack(t, 101, LightSync) }
func testMissingHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1180,15 +1221,18 @@ func testMissingHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
// Tests that if requested headers are shifted (i.e. first is missing), the queue
// detects the invalid numbering.
func TestShiftedHeaderAttack62(t *testing.T) { testShiftedHeaderAttack(t, 62, FullSync) }
func TestShiftedHeaderAttack63Full(t *testing.T) { testShiftedHeaderAttack(t, 63, FullSync) }
func TestShiftedHeaderAttack63Fast(t *testing.T) { testShiftedHeaderAttack(t, 63, FastSync) }
func TestShiftedHeaderAttack64Full(t *testing.T) { testShiftedHeaderAttack(t, 64, FullSync) }
func TestShiftedHeaderAttack64Fast(t *testing.T) { testShiftedHeaderAttack(t, 64, FastSync) }
func TestShiftedHeaderAttack64Light(t *testing.T) { testShiftedHeaderAttack(t, 64, LightSync) }
func TestShiftedHeaderAttack62(t *testing.T) { testShiftedHeaderAttack(t, 62, FullSync) }
func TestShiftedHeaderAttack63Full(t *testing.T) { testShiftedHeaderAttack(t, 63, FullSync) }
func TestShiftedHeaderAttack63Fast(t *testing.T) { testShiftedHeaderAttack(t, 63, FastSync) }
func TestShiftedHeaderAttack64Full(t *testing.T) { testShiftedHeaderAttack(t, 64, FullSync) }
func TestShiftedHeaderAttack64Fast(t *testing.T) { testShiftedHeaderAttack(t, 64, FastSync) }
func TestShiftedHeaderAttack64Light(t *testing.T) { testShiftedHeaderAttack(t, 64, LightSync) }
func TestShiftedHeaderAttack100Full(t *testing.T) { testShiftedHeaderAttack(t, 100, FullSync) }
func TestShiftedHeaderAttack100Fast(t *testing.T) { testShiftedHeaderAttack(t, 100, FastSync) }
func TestShiftedHeaderAttack100Light(t *testing.T) { testShiftedHeaderAttack(t, 100, LightSync) }
func TestShiftedHeaderAttack101Full(t *testing.T) { testShiftedHeaderAttack(t, 101, FullSync) }
func TestShiftedHeaderAttack101Fast(t *testing.T) { testShiftedHeaderAttack(t, 101, FastSync) }
func TestShiftedHeaderAttack101Light(t *testing.T) { testShiftedHeaderAttack(t, 101, LightSync) }
func testShiftedHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1220,11 +1264,13 @@ func testShiftedHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
// Tests that upon detecting an invalid header, the recent ones are rolled back
// for various failure scenarios. Afterwards a full sync is attempted to make
// sure no state was corrupted.
func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
func TestInvalidHeaderRollback64Light(t *testing.T) { testInvalidHeaderRollback(t, 64, LightSync) }
func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
func TestInvalidHeaderRollback64Light(t *testing.T) { testInvalidHeaderRollback(t, 64, LightSync) }
func TestInvalidHeaderRollback100Fast(t *testing.T) { testInvalidHeaderRollback(t, 100, FastSync) }
func TestInvalidHeaderRollback100Light(t *testing.T) { testInvalidHeaderRollback(t, 100, LightSync) }
func TestInvalidHeaderRollback101Fast(t *testing.T) { testInvalidHeaderRollback(t, 101, FastSync) }
func TestInvalidHeaderRollback101Light(t *testing.T) { testInvalidHeaderRollback(t, 101, LightSync) }
func testInvalidHeaderRollback(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1311,15 +1357,18 @@ func testInvalidHeaderRollback(t *testing.T, protocol int, mode SyncMode) {
// Tests that a peer advertising an high TD doesn't get to stall the downloader
// afterwards by not sending any useful hashes.
func TestHighTDStarvationAttack62(t *testing.T) { testHighTDStarvationAttack(t, 62, FullSync) }
func TestHighTDStarvationAttack63Full(t *testing.T) { testHighTDStarvationAttack(t, 63, FullSync) }
func TestHighTDStarvationAttack63Fast(t *testing.T) { testHighTDStarvationAttack(t, 63, FastSync) }
func TestHighTDStarvationAttack64Full(t *testing.T) { testHighTDStarvationAttack(t, 64, FullSync) }
func TestHighTDStarvationAttack64Fast(t *testing.T) { testHighTDStarvationAttack(t, 64, FastSync) }
func TestHighTDStarvationAttack64Light(t *testing.T) { testHighTDStarvationAttack(t, 64, LightSync) }
func TestHighTDStarvationAttack62(t *testing.T) { testHighTDStarvationAttack(t, 62, FullSync) }
func TestHighTDStarvationAttack63Full(t *testing.T) { testHighTDStarvationAttack(t, 63, FullSync) }
func TestHighTDStarvationAttack63Fast(t *testing.T) { testHighTDStarvationAttack(t, 63, FastSync) }
func TestHighTDStarvationAttack64Full(t *testing.T) { testHighTDStarvationAttack(t, 64, FullSync) }
func TestHighTDStarvationAttack64Fast(t *testing.T) { testHighTDStarvationAttack(t, 64, FastSync) }
func TestHighTDStarvationAttack64Light(t *testing.T) { testHighTDStarvationAttack(t, 64, LightSync) }
func TestHighTDStarvationAttack100Full(t *testing.T) { testHighTDStarvationAttack(t, 100, FullSync) }
func TestHighTDStarvationAttack100Fast(t *testing.T) { testHighTDStarvationAttack(t, 100, FastSync) }
func TestHighTDStarvationAttack100Light(t *testing.T) { testHighTDStarvationAttack(t, 100, LightSync) }
func TestHighTDStarvationAttack101Full(t *testing.T) { testHighTDStarvationAttack(t, 101, FullSync) }
func TestHighTDStarvationAttack101Fast(t *testing.T) { testHighTDStarvationAttack(t, 101, FastSync) }
func TestHighTDStarvationAttack101Light(t *testing.T) { testHighTDStarvationAttack(t, 101, LightSync) }
func testHighTDStarvationAttack(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1336,10 +1385,11 @@ func testHighTDStarvationAttack(t *testing.T, protocol int, mode SyncMode) {
}
// Tests that misbehaving peers are disconnected, whilst behaving ones are not.
func TestBlockHeaderAttackerDropping62(t *testing.T) { testBlockHeaderAttackerDropping(t, 62) }
func TestBlockHeaderAttackerDropping63(t *testing.T) { testBlockHeaderAttackerDropping(t, 63) }
func TestBlockHeaderAttackerDropping64(t *testing.T) { testBlockHeaderAttackerDropping(t, 64) }
func TestBlockHeaderAttackerDropping62(t *testing.T) { testBlockHeaderAttackerDropping(t, 62) }
func TestBlockHeaderAttackerDropping63(t *testing.T) { testBlockHeaderAttackerDropping(t, 63) }
func TestBlockHeaderAttackerDropping64(t *testing.T) { testBlockHeaderAttackerDropping(t, 64) }
func TestBlockHeaderAttackerDropping100(t *testing.T) { testBlockHeaderAttackerDropping(t, 100) }
func TestBlockHeaderAttackerDropping101(t *testing.T) { testBlockHeaderAttackerDropping(t, 101) }
func testBlockHeaderAttackerDropping(t *testing.T, protocol int) {
t.Parallel()
@ -1395,15 +1445,18 @@ func testBlockHeaderAttackerDropping(t *testing.T, protocol int) {
// Tests that synchronisation progress (origin block number, current block number
// and highest block number) is tracked and updated correctly.
func TestSyncProgress62(t *testing.T) { testSyncProgress(t, 62, FullSync) }
func TestSyncProgress63Full(t *testing.T) { testSyncProgress(t, 63, FullSync) }
func TestSyncProgress63Fast(t *testing.T) { testSyncProgress(t, 63, FastSync) }
func TestSyncProgress64Full(t *testing.T) { testSyncProgress(t, 64, FullSync) }
func TestSyncProgress64Fast(t *testing.T) { testSyncProgress(t, 64, FastSync) }
func TestSyncProgress64Light(t *testing.T) { testSyncProgress(t, 64, LightSync) }
func TestSyncProgress62(t *testing.T) { testSyncProgress(t, 62, FullSync) }
func TestSyncProgress63Full(t *testing.T) { testSyncProgress(t, 63, FullSync) }
func TestSyncProgress63Fast(t *testing.T) { testSyncProgress(t, 63, FastSync) }
func TestSyncProgress64Full(t *testing.T) { testSyncProgress(t, 64, FullSync) }
func TestSyncProgress64Fast(t *testing.T) { testSyncProgress(t, 64, FastSync) }
func TestSyncProgress64Light(t *testing.T) { testSyncProgress(t, 64, LightSync) }
func TestSyncProgress100Full(t *testing.T) { testSyncProgress(t, 100, FullSync) }
func TestSyncProgress100Fast(t *testing.T) { testSyncProgress(t, 100, FastSync) }
func TestSyncProgress100Light(t *testing.T) { testSyncProgress(t, 100, LightSync) }
func TestSyncProgress101Full(t *testing.T) { testSyncProgress(t, 101, FullSync) }
func TestSyncProgress101Fast(t *testing.T) { testSyncProgress(t, 101, FastSync) }
func TestSyncProgress101Light(t *testing.T) { testSyncProgress(t, 101, LightSync) }
func testSyncProgress(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1471,15 +1524,18 @@ func testSyncProgress(t *testing.T, protocol int, mode SyncMode) {
// Tests that synchronisation progress (origin block number and highest block
// number) is tracked and updated correctly in case of a fork (or manual head
// revertal).
func TestForkedSyncProgress62(t *testing.T) { testForkedSyncProgress(t, 62, FullSync) }
func TestForkedSyncProgress63Full(t *testing.T) { testForkedSyncProgress(t, 63, FullSync) }
func TestForkedSyncProgress63Fast(t *testing.T) { testForkedSyncProgress(t, 63, FastSync) }
func TestForkedSyncProgress64Full(t *testing.T) { testForkedSyncProgress(t, 64, FullSync) }
func TestForkedSyncProgress64Fast(t *testing.T) { testForkedSyncProgress(t, 64, FastSync) }
func TestForkedSyncProgress64Light(t *testing.T) { testForkedSyncProgress(t, 64, LightSync) }
func TestForkedSyncProgress62(t *testing.T) { testForkedSyncProgress(t, 62, FullSync) }
func TestForkedSyncProgress63Full(t *testing.T) { testForkedSyncProgress(t, 63, FullSync) }
func TestForkedSyncProgress63Fast(t *testing.T) { testForkedSyncProgress(t, 63, FastSync) }
func TestForkedSyncProgress64Full(t *testing.T) { testForkedSyncProgress(t, 64, FullSync) }
func TestForkedSyncProgress64Fast(t *testing.T) { testForkedSyncProgress(t, 64, FastSync) }
func TestForkedSyncProgress64Light(t *testing.T) { testForkedSyncProgress(t, 64, LightSync) }
func TestForkedSyncProgress100Full(t *testing.T) { testForkedSyncProgress(t, 100, FullSync) }
func TestForkedSyncProgress100Fast(t *testing.T) { testForkedSyncProgress(t, 100, FastSync) }
func TestForkedSyncProgress100Light(t *testing.T) { testForkedSyncProgress(t, 100, LightSync) }
func TestForkedSyncProgress101Full(t *testing.T) { testForkedSyncProgress(t, 101, FullSync) }
func TestForkedSyncProgress101Fast(t *testing.T) { testForkedSyncProgress(t, 101, FastSync) }
func TestForkedSyncProgress101Light(t *testing.T) { testForkedSyncProgress(t, 101, LightSync) }
func testForkedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1550,15 +1606,18 @@ func testForkedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
// Tests that if synchronisation is aborted due to some failure, then the progress
// origin is not updated in the next sync cycle, as it should be considered the
// continuation of the previous sync and not a new instance.
func TestFailedSyncProgress62(t *testing.T) { testFailedSyncProgress(t, 62, FullSync) }
func TestFailedSyncProgress63Full(t *testing.T) { testFailedSyncProgress(t, 63, FullSync) }
func TestFailedSyncProgress63Fast(t *testing.T) { testFailedSyncProgress(t, 63, FastSync) }
func TestFailedSyncProgress64Full(t *testing.T) { testFailedSyncProgress(t, 64, FullSync) }
func TestFailedSyncProgress64Fast(t *testing.T) { testFailedSyncProgress(t, 64, FastSync) }
func TestFailedSyncProgress64Light(t *testing.T) { testFailedSyncProgress(t, 64, LightSync) }
func TestFailedSyncProgress62(t *testing.T) { testFailedSyncProgress(t, 62, FullSync) }
func TestFailedSyncProgress63Full(t *testing.T) { testFailedSyncProgress(t, 63, FullSync) }
func TestFailedSyncProgress63Fast(t *testing.T) { testFailedSyncProgress(t, 63, FastSync) }
func TestFailedSyncProgress64Full(t *testing.T) { testFailedSyncProgress(t, 64, FullSync) }
func TestFailedSyncProgress64Fast(t *testing.T) { testFailedSyncProgress(t, 64, FastSync) }
func TestFailedSyncProgress64Light(t *testing.T) { testFailedSyncProgress(t, 64, LightSync) }
func TestFailedSyncProgress100Full(t *testing.T) { testFailedSyncProgress(t, 100, FullSync) }
func TestFailedSyncProgress100Fast(t *testing.T) { testFailedSyncProgress(t, 100, FastSync) }
func TestFailedSyncProgress100Light(t *testing.T) { testFailedSyncProgress(t, 100, LightSync) }
func TestFailedSyncProgress101Full(t *testing.T) { testFailedSyncProgress(t, 101, FullSync) }
func TestFailedSyncProgress101Fast(t *testing.T) { testFailedSyncProgress(t, 101, FastSync) }
func TestFailedSyncProgress101Light(t *testing.T) { testFailedSyncProgress(t, 101, LightSync) }
func testFailedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1630,15 +1689,18 @@ func testFailedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
// Tests that if an attacker fakes a chain height, after the attack is detected,
// the progress height is successfully reduced at the next sync invocation.
func TestFakedSyncProgress62(t *testing.T) { testFakedSyncProgress(t, 62, FullSync) }
func TestFakedSyncProgress63Full(t *testing.T) { testFakedSyncProgress(t, 63, FullSync) }
func TestFakedSyncProgress63Fast(t *testing.T) { testFakedSyncProgress(t, 63, FastSync) }
func TestFakedSyncProgress64Full(t *testing.T) { testFakedSyncProgress(t, 64, FullSync) }
func TestFakedSyncProgress64Fast(t *testing.T) { testFakedSyncProgress(t, 64, FastSync) }
func TestFakedSyncProgress64Light(t *testing.T) { testFakedSyncProgress(t, 64, LightSync) }
func TestFakedSyncProgress62(t *testing.T) { testFakedSyncProgress(t, 62, FullSync) }
func TestFakedSyncProgress63Full(t *testing.T) { testFakedSyncProgress(t, 63, FullSync) }
func TestFakedSyncProgress63Fast(t *testing.T) { testFakedSyncProgress(t, 63, FastSync) }
func TestFakedSyncProgress64Full(t *testing.T) { testFakedSyncProgress(t, 64, FullSync) }
func TestFakedSyncProgress64Fast(t *testing.T) { testFakedSyncProgress(t, 64, FastSync) }
func TestFakedSyncProgress64Light(t *testing.T) { testFakedSyncProgress(t, 64, LightSync) }
func TestFakedSyncProgress100Full(t *testing.T) { testFakedSyncProgress(t, 100, FullSync) }
func TestFakedSyncProgress100Fast(t *testing.T) { testFakedSyncProgress(t, 100, FastSync) }
func TestFakedSyncProgress100Light(t *testing.T) { testFakedSyncProgress(t, 100, LightSync) }
func TestFakedSyncProgress101Full(t *testing.T) { testFakedSyncProgress(t, 101, FullSync) }
func TestFakedSyncProgress101Fast(t *testing.T) { testFakedSyncProgress(t, 101, FastSync) }
func TestFakedSyncProgress101Light(t *testing.T) { testFakedSyncProgress(t, 101, LightSync) }
func testFakedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
t.Parallel()
@ -1729,6 +1791,9 @@ func TestDeliverHeadersHang(t *testing.T) {
{100, FullSync},
{100, FastSync},
{100, LightSync},
{101, FullSync},
{101, FastSync},
{101, LightSync},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("protocol %d mode %v", tc.protocol, tc.syncMode), func(t *testing.T) {

View file

@ -94,7 +94,7 @@ type chainHeightFn func() uint64
type chainInsertFn func(types.Blocks) (int, error)
// blockInsertFn is a callback type to insert a batch of blocks into the local chain.
type blockInsertFn func(types.Block) (int, error)
type blockInsertFn func(types.Block) (error)
type blockPrepareFn func(block *types.Block) error
@ -777,7 +777,7 @@ func (f *BlockFetcher) insert(peer string, block *types.Block) {
return
}
// Run the actual import and log any issues
if _, err := f.insertBlock(*block); err != nil {
if err := f.insertBlock(*block); err != nil {
log.Warn("Propagated block import failed", "peer", peer, "number", block.Number(), "hash", hash, "err", err)
return
}

View file

@ -93,7 +93,7 @@ func newTester() *fetcherTester {
blocks: map[common.Hash]*types.Block{genesis.Hash(): genesis},
drops: make(map[string]bool),
}
tester.fetcher = NewBlockFetcher(tester.getBlock, tester.verifyHeader, tester.handleProposedBlock, tester.broadcastBlock, tester.chainHeight, tester.insertChain, tester.prepareBlock, tester.dropPeer)
tester.fetcher = NewBlockFetcher(tester.getBlock, tester.verifyHeader, tester.handleProposedBlock, tester.broadcastBlock, tester.chainHeight, tester.insertBlock, tester.prepareBlock, tester.dropPeer)
tester.fetcher.Start()
return tester
@ -150,7 +150,7 @@ func (f *fetcherTester) insertChain(blocks types.Blocks) (int, error) {
}
// insertBlock injects a new blocks into the simulated chain.
func (f *fetcherTester) insertBlock(block *types.Block) error {
func (f *fetcherTester) insertBlock(block types.Block) error {
f.lock.Lock()
defer f.lock.Unlock()
@ -164,7 +164,7 @@ func (f *fetcherTester) insertBlock(block *types.Block) error {
}
// Otherwise build our current chain
f.hashes = append(f.hashes, block.Hash())
f.blocks[block.Hash()] = block
f.blocks[block.Hash()] = &block
return nil
}
@ -311,12 +311,13 @@ func verifyProposeBlockHandlerCalled(t *testing.T, proposedBlockChan chan *types
// Tests that a fetcher accepts block announcements and initiates retrievals for
// them, successfully importing into the local chain.
func TestSequentialAnnouncements62(t *testing.T) { testSequentialAnnouncements(t, 62) }
func TestSequentialAnnouncements63(t *testing.T) { testSequentialAnnouncements(t, 63) }
func TestSequentialAnnouncements64(t *testing.T) { testSequentialAnnouncements(t, 64) }
func TestSequentialAnnouncements62(t *testing.T) { testSequentialAnnouncements(t, 62) }
func TestSequentialAnnouncements63(t *testing.T) { testSequentialAnnouncements(t, 63) }
func TestSequentialAnnouncements64(t *testing.T) { testSequentialAnnouncements(t, 64) }
func TestSequentialAnnouncements100(t *testing.T) { testSequentialAnnouncements(t, 100) }
func TestSequentialAnnouncements101(t *testing.T) { testSequentialAnnouncements(t, 101) }
func testSequentialAnnouncements(t *testing.T, protocol int) {
func testSequentialAnnouncements(t *testing.T, protocol int) {
// Create a chain of blocks to import
targetBlocks := 4 * hashLimit
hashes, blocks := makeChain(targetBlocks, 0, genesis)
@ -347,12 +348,13 @@ func testSequentialAnnouncements(t *testing.T, protocol int) {
// Tests that if blocks are announced by multiple peers (or even the same buggy
// peer), they will only get downloaded at most once.
func TestConcurrentAnnouncements62(t *testing.T) { testConcurrentAnnouncements(t, 62) }
func TestConcurrentAnnouncements63(t *testing.T) { testConcurrentAnnouncements(t, 63) }
func TestConcurrentAnnouncements64(t *testing.T) { testConcurrentAnnouncements(t, 64) }
func TestConcurrentAnnouncements62(t *testing.T) { testConcurrentAnnouncements(t, 62) }
func TestConcurrentAnnouncements63(t *testing.T) { testConcurrentAnnouncements(t, 63) }
func TestConcurrentAnnouncements64(t *testing.T) { testConcurrentAnnouncements(t, 64) }
func TestConcurrentAnnouncements100(t *testing.T) { testConcurrentAnnouncements(t, 100) }
func TestConcurrentAnnouncements101(t *testing.T) { testConcurrentAnnouncements(t, 101) }
func testConcurrentAnnouncements(t *testing.T, protocol int) {
func testConcurrentAnnouncements(t *testing.T, protocol int) {
// Create a chain of blocks to import
targetBlocks := 4 * hashLimit
hashes, blocks := makeChain(targetBlocks, 0, genesis)
@ -396,12 +398,13 @@ func testConcurrentAnnouncements(t *testing.T, protocol int) {
// Tests that announcements arriving while a previous is being fetched still
// results in a valid import.
func TestOverlappingAnnouncements62(t *testing.T) { testOverlappingAnnouncements(t, 62) }
func TestOverlappingAnnouncements63(t *testing.T) { testOverlappingAnnouncements(t, 63) }
func TestOverlappingAnnouncements64(t *testing.T) { testOverlappingAnnouncements(t, 64) }
func TestOverlappingAnnouncements62(t *testing.T) { testOverlappingAnnouncements(t, 62) }
func TestOverlappingAnnouncements63(t *testing.T) { testOverlappingAnnouncements(t, 63) }
func TestOverlappingAnnouncements64(t *testing.T) { testOverlappingAnnouncements(t, 64) }
func TestOverlappingAnnouncements100(t *testing.T) { testOverlappingAnnouncements(t, 100) }
func TestOverlappingAnnouncements101(t *testing.T) { testOverlappingAnnouncements(t, 101) }
func testOverlappingAnnouncements(t *testing.T, protocol int) {
func testOverlappingAnnouncements(t *testing.T, protocol int) {
// Create a chain of blocks to import
targetBlocks := 4 * hashLimit
hashes, blocks := makeChain(targetBlocks, 0, genesis)
@ -434,12 +437,13 @@ func testOverlappingAnnouncements(t *testing.T, protocol int) {
}
// Tests that announces already being retrieved will not be duplicated.
func TestPendingDeduplication62(t *testing.T) { testPendingDeduplication(t, 62) }
func TestPendingDeduplication63(t *testing.T) { testPendingDeduplication(t, 63) }
func TestPendingDeduplication64(t *testing.T) { testPendingDeduplication(t, 64) }
func TestPendingDeduplication62(t *testing.T) { testPendingDeduplication(t, 62) }
func TestPendingDeduplication63(t *testing.T) { testPendingDeduplication(t, 63) }
func TestPendingDeduplication64(t *testing.T) { testPendingDeduplication(t, 64) }
func TestPendingDeduplication100(t *testing.T) { testPendingDeduplication(t, 100) }
func TestPendingDeduplication101(t *testing.T) { testPendingDeduplication(t, 101) }
func testPendingDeduplication(t *testing.T, protocol int) {
func testPendingDeduplication(t *testing.T, protocol int) {
// Create a hash and corresponding block
hashes, blocks := makeChain(1, 0, genesis)
@ -478,12 +482,13 @@ func testPendingDeduplication(t *testing.T, protocol int) {
// Tests that announcements retrieved in a random order are cached and eventually
// imported when all the gaps are filled in.
func TestRandomArrivalImport62(t *testing.T) { testRandomArrivalImport(t, 62) }
func TestRandomArrivalImport63(t *testing.T) { testRandomArrivalImport(t, 63) }
func TestRandomArrivalImport64(t *testing.T) { testRandomArrivalImport(t, 64) }
func TestRandomArrivalImport62(t *testing.T) { testRandomArrivalImport(t, 62) }
func TestRandomArrivalImport63(t *testing.T) { testRandomArrivalImport(t, 63) }
func TestRandomArrivalImport64(t *testing.T) { testRandomArrivalImport(t, 64) }
func TestRandomArrivalImport100(t *testing.T) { testRandomArrivalImport(t, 100) }
func TestRandomArrivalImport101(t *testing.T) { testRandomArrivalImport(t, 101) }
func testRandomArrivalImport(t *testing.T, protocol int) {
func testRandomArrivalImport(t *testing.T, protocol int) {
// Create a chain of blocks to import, and choose one to delay
targetBlocks := maxQueueDist
hashes, blocks := makeChain(targetBlocks, 0, genesis)
@ -513,12 +518,13 @@ func testRandomArrivalImport(t *testing.T, protocol int) {
// Tests that direct block enqueues (due to block propagation vs. hash announce)
// are correctly schedule, filling and import queue gaps.
func TestQueueGapFill62(t *testing.T) { testQueueGapFill(t, 62) }
func TestQueueGapFill63(t *testing.T) { testQueueGapFill(t, 63) }
func TestQueueGapFill64(t *testing.T) { testQueueGapFill(t, 64) }
func TestQueueGapFill62(t *testing.T) { testQueueGapFill(t, 62) }
func TestQueueGapFill63(t *testing.T) { testQueueGapFill(t, 63) }
func TestQueueGapFill64(t *testing.T) { testQueueGapFill(t, 64) }
func TestQueueGapFill100(t *testing.T) { testQueueGapFill(t, 100) }
func TestQueueGapFill101(t *testing.T) { testQueueGapFill(t, 101) }
func testQueueGapFill(t *testing.T, protocol int) {
func testQueueGapFill(t *testing.T, protocol int) {
// Create a chain of blocks to import, and choose one to not announce at all
targetBlocks := maxQueueDist
hashes, blocks := makeChain(targetBlocks, 0, genesis)
@ -548,12 +554,13 @@ func testQueueGapFill(t *testing.T, protocol int) {
// Tests that blocks arriving from various sources (multiple propagations, hash
// announces, etc) do not get scheduled for import multiple times.
func TestImportDeduplication62(t *testing.T) { testImportDeduplication(t, 62) }
func TestImportDeduplication63(t *testing.T) { testImportDeduplication(t, 63) }
func TestImportDeduplication64(t *testing.T) { testImportDeduplication(t, 64) }
func TestImportDeduplication62(t *testing.T) { testImportDeduplication(t, 62) }
func TestImportDeduplication63(t *testing.T) { testImportDeduplication(t, 63) }
func TestImportDeduplication64(t *testing.T) { testImportDeduplication(t, 64) }
func TestImportDeduplication100(t *testing.T) { testImportDeduplication(t, 100) }
func TestImportDeduplication101(t *testing.T) { testImportDeduplication(t, 101) }
func testImportDeduplication(t *testing.T, protocol int) {
func testImportDeduplication(t *testing.T, protocol int) {
// Create two blocks to import (one for duplication, the other for stalling)
hashes, blocks := makeChain(2, 0, genesis)
@ -563,9 +570,9 @@ func testImportDeduplication(t *testing.T, protocol int) {
bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0)
counter := uint32(0)
tester.fetcher.insertChain = func(blocks types.Blocks) (int, error) {
tester.fetcher.insertBlock = func(block types.Block) error {
atomic.AddUint32(&counter, uint32(1))
return tester.insertChain(blocks)
return tester.insertBlock(block)
}
// Instrument the fetching and imported events
fetching := make(chan []common.Hash)
@ -627,10 +634,11 @@ func TestDistantPropagationDiscarding(t *testing.T) {
// Tests that announcements with numbers much lower or higher than out current
// head get discarded to prevent wasting resources on useless blocks from faulty
// peers.
func TestDistantAnnouncementDiscarding62(t *testing.T) { testDistantAnnouncementDiscarding(t, 62) }
func TestDistantAnnouncementDiscarding63(t *testing.T) { testDistantAnnouncementDiscarding(t, 63) }
func TestDistantAnnouncementDiscarding64(t *testing.T) { testDistantAnnouncementDiscarding(t, 64) }
func TestDistantAnnouncementDiscarding62(t *testing.T) { testDistantAnnouncementDiscarding(t, 62) }
func TestDistantAnnouncementDiscarding63(t *testing.T) { testDistantAnnouncementDiscarding(t, 63) }
func TestDistantAnnouncementDiscarding64(t *testing.T) { testDistantAnnouncementDiscarding(t, 64) }
func TestDistantAnnouncementDiscarding100(t *testing.T) { testDistantAnnouncementDiscarding(t, 100) }
func TestDistantAnnouncementDiscarding101(t *testing.T) { testDistantAnnouncementDiscarding(t, 101) }
func testDistantAnnouncementDiscarding(t *testing.T, protocol int) {
// Create a long chain to import and define the discard boundaries
@ -671,10 +679,11 @@ func testDistantAnnouncementDiscarding(t *testing.T, protocol int) {
// Tests that peers announcing blocks with invalid numbers (i.e. not matching
// the headers provided afterwards) get dropped as malicious.
func TestInvalidNumberAnnouncement62(t *testing.T) { testInvalidNumberAnnouncement(t, 62) }
func TestInvalidNumberAnnouncement63(t *testing.T) { testInvalidNumberAnnouncement(t, 63) }
func TestInvalidNumberAnnouncement64(t *testing.T) { testInvalidNumberAnnouncement(t, 64) }
func TestInvalidNumberAnnouncement62(t *testing.T) { testInvalidNumberAnnouncement(t, 62) }
func TestInvalidNumberAnnouncement63(t *testing.T) { testInvalidNumberAnnouncement(t, 63) }
func TestInvalidNumberAnnouncement64(t *testing.T) { testInvalidNumberAnnouncement(t, 64) }
func TestInvalidNumberAnnouncement100(t *testing.T) { testInvalidNumberAnnouncement(t, 100) }
func TestInvalidNumberAnnouncement101(t *testing.T) { testInvalidNumberAnnouncement(t, 101) }
func testInvalidNumberAnnouncement(t *testing.T, protocol int) {
// Create a single block to import and check numbers against
@ -720,10 +729,11 @@ func testInvalidNumberAnnouncement(t *testing.T, protocol int) {
// Tests that if a block is empty (i.e. header only), no body request should be
// made, and instead the header should be assembled into a whole block in itself.
func TestEmptyBlockShortCircuit62(t *testing.T) { testEmptyBlockShortCircuit(t, 62) }
func TestEmptyBlockShortCircuit63(t *testing.T) { testEmptyBlockShortCircuit(t, 63) }
func TestEmptyBlockShortCircuit64(t *testing.T) { testEmptyBlockShortCircuit(t, 64) }
func TestEmptyBlockShortCircuit100(t *testing.T) { testEmptyBlockShortCircuit(t, 64) }
func TestEmptyBlockShortCircuit62(t *testing.T) { testEmptyBlockShortCircuit(t, 62) }
func TestEmptyBlockShortCircuit63(t *testing.T) { testEmptyBlockShortCircuit(t, 63) }
func TestEmptyBlockShortCircuit64(t *testing.T) { testEmptyBlockShortCircuit(t, 64) }
func TestEmptyBlockShortCircuit100(t *testing.T) { testEmptyBlockShortCircuit(t, 100) }
func TestEmptyBlockShortCircuit101(t *testing.T) { testEmptyBlockShortCircuit(t, 101) }
func testEmptyBlockShortCircuit(t *testing.T, protocol int) {
// Create a chain of blocks to import
@ -765,10 +775,11 @@ func testEmptyBlockShortCircuit(t *testing.T, protocol int) {
// Tests that a peer is unable to use unbounded memory with sending infinite
// block announcements to a node, but that even in the face of such an attack,
// the fetcher remains operational.
func TestHashMemoryExhaustionAttack62(t *testing.T) { testHashMemoryExhaustionAttack(t, 62) }
func TestHashMemoryExhaustionAttack63(t *testing.T) { testHashMemoryExhaustionAttack(t, 63) }
func TestHashMemoryExhaustionAttack64(t *testing.T) { testHashMemoryExhaustionAttack(t, 64) }
func TestHashMemoryExhaustionAttack62(t *testing.T) { testHashMemoryExhaustionAttack(t, 62) }
func TestHashMemoryExhaustionAttack63(t *testing.T) { testHashMemoryExhaustionAttack(t, 63) }
func TestHashMemoryExhaustionAttack64(t *testing.T) { testHashMemoryExhaustionAttack(t, 64) }
func TestHashMemoryExhaustionAttack100(t *testing.T) { testHashMemoryExhaustionAttack(t, 100) }
func TestHashMemoryExhaustionAttack101(t *testing.T) { testHashMemoryExhaustionAttack(t, 101) }
func testHashMemoryExhaustionAttack(t *testing.T, protocol int) {
// Create a tester with instrumented import hooks

View file

@ -246,7 +246,7 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
return blockchain.CurrentBlock().NumberU64()
}
inserter := func(block types.Block) (int, error) {
inserter := func(block types.Block) (error) {
// If sync hasn't reached the checkpoint yet, deny importing weird blocks.
//
// Ideally we would also compare the head block's timestamp and similarly reject
@ -255,7 +255,7 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
// which would prevent full nodes from accepting it.
if manager.blockchain.CurrentBlock().NumberU64() < manager.checkpointNumber {
log.Warn("Unsynced yet, discarded propagated block", "number", block.Number(), "hash", block.Hash())
return 0, nil
return nil
}
// If fast sync is running, deny importing weird blocks. This is a problematic
// clause when starting up a new network, because fast-syncing miners might not
@ -264,14 +264,14 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
// or not. This should be fixed if we figure out a solution.
if atomic.LoadUint32(&manager.fastSync) == 1 {
log.Warn("Fast syncing, discarded propagated block", "number", block.Number(), "hash", block.Hash())
return 0, nil
return nil
}
n, err := manager.blockchain.InsertBlock(&block)
// n, err := manager.blockchain.InsertChain(blocks)
err := manager.blockchain.InsertBlock(&block)
// n, err := manager.blockchain.InsertChain(blocks) //TODO: only use InsertChain like go-eth
if err == nil {
atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
}
return n, err
return err
}
prepare := func(block *types.Block) error {
@ -699,7 +699,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
}
case supportsEth63(p.version) && msg.Code == GetNodeDataMsg:
case isEth63OrHigher(p.version) && msg.Code == GetNodeDataMsg:
// Decode the retrieval message
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
@ -726,7 +726,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
return p.SendNodeData(data)
case supportsEth63(p.version) && msg.Code == NodeDataMsg:
case isEth63OrHigher(p.version) && msg.Code == NodeDataMsg:
// A batch of node state data arrived to one of our previous requests
var data [][]byte
if err := msg.Decode(&data); err != nil {
@ -737,7 +737,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
log.Debug("Failed to deliver node state data", "err", err)
}
case supportsEth63(p.version) && msg.Code == GetReceiptsMsg:
case isEth63OrHigher(p.version) && msg.Code == GetReceiptsMsg:
// Decode the retrieval message
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
@ -773,7 +773,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
return p.SendReceiptsRLP(receipts)
case supportsEth63(p.version) && msg.Code == ReceiptsMsg:
case isEth63OrHigher(p.version) && msg.Code == ReceiptsMsg:
// A batch of receipts arrived to one of our previous requests
var receipts [][]*types.Receipt
if err := msg.Decode(&receipts); err != nil {
@ -847,7 +847,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
}
case msg.Code == NewPooledTransactionHashesMsg && supportsEth65(p.version):
case msg.Code == NewPooledTransactionHashesMsg && isEth65OrHigher(p.version):
// New transaction announcement arrived, make sure we have
// a valid and fresh chain to handle them
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
@ -863,7 +863,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
pm.txFetcher.Notify(p.id, hashes)
case msg.Code == GetPooledTransactionsMsg && supportsEth65(p.version):
case msg.Code == GetPooledTransactionsMsg && isEth65OrHigher(p.version):
// Decode the retrieval message
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
@ -899,7 +899,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
return p.SendPooledTransactionsRLP(hashes, txs)
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && supportsEth65(p.version)):
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && isEth65OrHigher(p.version)):
// Transactions arrived, make sure we have a valid and fresh chain to handle them
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
break

View file

@ -40,9 +40,10 @@ import (
)
// Tests that block headers can be retrieved from a remote chain based on user queries.
func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }
func TestGetBlockHeaders64(t *testing.T) { testGetBlockHeaders(t, 64) }
func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }
func TestGetBlockHeaders64(t *testing.T) { testGetBlockHeaders(t, 64) }
func TestGetBlockHeaders100(t *testing.T) { testGetBlockHeaders(t, 100) }
func TestGetBlockHeaders101(t *testing.T) { testGetBlockHeaders(t, 101) }
func testGetBlockHeaders(t *testing.T, protocol int) {
pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, downloader.MaxHashFetch+15, nil, nil)
@ -200,9 +201,10 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
}
// Tests that block contents can be retrieved from a remote chain based on their hashes.
func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }
func TestGetBlockBodies64(t *testing.T) { testGetBlockBodies(t, 64) }
func TestGetBlockBodies100(t *testing.T) { testGetBlockBodies(t, 100)}
func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }
func TestGetBlockBodies64(t *testing.T) { testGetBlockBodies(t, 64) }
func TestGetBlockBodies100(t *testing.T) { testGetBlockBodies(t, 100) }
func TestGetBlockBodies101(t *testing.T) { testGetBlockBodies(t, 101) }
func testGetBlockBodies(t *testing.T, protocol int) {
pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, downloader.MaxBlockFetch+15, nil, nil)
@ -273,9 +275,10 @@ func testGetBlockBodies(t *testing.T, protocol int) {
}
// Tests that the node state database can be retrieved based on hashes.
func TestGetNodeData63(t *testing.T) { testGetNodeData(t, 63) }
func TestGetNodeData64(t *testing.T) { testGetNodeData(t, 64) }
func TestGetNodeData63(t *testing.T) { testGetNodeData(t, 63) }
func TestGetNodeData64(t *testing.T) { testGetNodeData(t, 64) }
func TestGetNodeData100(t *testing.T) { testGetNodeData(t, 100) }
func TestGetNodeData101(t *testing.T) { testGetNodeData(t, 101) }
func testGetNodeData(t *testing.T, protocol int) {
// Define three accounts to simulate transactions with
@ -369,9 +372,10 @@ func testGetNodeData(t *testing.T, protocol int) {
}
// Tests that the transaction receipts can be retrieved based on hashes.
func TestGetReceipt63(t *testing.T) { testGetReceipt(t, 63) }
func TestGetReceipt64(t *testing.T) { testGetReceipt(t, 64) }
func TestGetReceipt63(t *testing.T) { testGetReceipt(t, 63) }
func TestGetReceipt64(t *testing.T) { testGetReceipt(t, 64) }
func TestGetReceipt100(t *testing.T) { testGetReceipt(t, 100) }
func TestGetReceipt101(t *testing.T) { testGetReceipt(t, 101) }
func testGetReceipt(t *testing.T, protocol int) {
// Define three accounts to simulate transactions with
@ -557,7 +561,7 @@ func testBroadcastBlock(t *testing.T, totalPeers, broadcastExpected int) {
if err != nil {
t.Fatalf("failed to create new blockchain: %v", err)
}
pm, err := NewProtocolManager(config, downloader.FullSync, DefaultConfig.NetworkId, evmux, &testTxPool{pool: make(map[common.Hash]*types.Transaction)}, pow, blockchain, db)
pm, err := NewProtocolManager(config, downloader.FullSync, ethconfig.Defaults.NetworkId, evmux, &testTxPool{pool: make(map[common.Hash]*types.Transaction)}, pow, blockchain, db)
if err != nil {
t.Fatalf("failed to start test protocol manager: %v", err)
}
@ -625,7 +629,7 @@ func TestBroadcastMalformedBlock(t *testing.T) {
if err != nil {
t.Fatalf("failed to create new blockchain: %v", err)
}
pm, err := NewProtocolManager(config, downloader.FullSync, DefaultConfig.NetworkId, new(event.TypeMux), new(testTxPool), engine, blockchain, db)
pm, err := NewProtocolManager(config, downloader.FullSync, ethconfig.Defaults.NetworkId, new(event.TypeMux), new(testTxPool), engine, blockchain, db)
if err != nil {
t.Fatalf("failed to start test protocol manager: %v", err)
}

View file

@ -71,7 +71,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
}
// pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db)
pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx, pool: make(map[common.Hash]*types.Transaction)}, engine, blockchain, db)
pm, err := NewProtocolManager(gspec.Config, mode, ethconfig.Defaults.NetworkId, evmux, &testTxPool{added: newtx, pool: make(map[common.Hash]*types.Transaction)}, engine, blockchain, db)
if err != nil {
return nil, nil, err
}
@ -207,26 +207,18 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te
func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesis common.Hash, forkID forkid.ID, forkFilter forkid.Filter) {
var msg interface{}
switch {
case p.version == xdpos2:
case isEth63(p.version):
msg = &statusData63{
ProtocolVersion: uint32(p.version),
NetworkId: DefaultConfig.NetworkId,
NetworkId: ethconfig.Defaults.NetworkId,
TD: td,
CurrentBlock: head,
GenesisBlock: genesis,
}
case p.version == eth63:
msg = &statusData63{
ProtocolVersion: uint32(p.version),
NetworkId: DefaultConfig.NetworkId,
TD: td,
CurrentBlock: head,
GenesisBlock: genesis,
}
case p.version >= eth64:
case isEth64OrHigher(p.version):
msg = &statusData{
ProtocolVersion: uint32(p.version),
NetworkID: DefaultConfig.NetworkId,
NetworkID: ethconfig.Defaults.NetworkId,
TD: td,
Head: head,
Genesis: genesis,
@ -236,6 +228,7 @@ func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesi
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
}
if err := p2p.ExpectMsg(p.app, StatusMsg, msg); err != nil {
fmt.Println("p2p expect msg err", err)
t.Fatalf("status recv: %v", err)
}
if err := p2p.Send(p.app, StatusMsg, msg); err != nil {

View file

@ -783,25 +783,7 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
)
go func() {
switch {
case supportsEth65(p.version):
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
ProtocolVersion: uint32(p.version),
NetworkID: network,
TD: td,
Head: head,
Genesis: genesis,
ForkID: forkID,
})
case supportsEth64(p.version):
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
ProtocolVersion: uint32(p.version),
NetworkID: network,
TD: td,
Head: head,
Genesis: genesis,
ForkID: forkID,
})
case supportsEth63(p.version):
case isEth63(p.version):
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
ProtocolVersion: uint32(p.version),
NetworkId: network,
@ -809,16 +791,25 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
CurrentBlock: head,
GenesisBlock: genesis,
})
case isEth64OrHigher(p.version):
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
ProtocolVersion: uint32(p.version),
NetworkID: network,
TD: td,
Head: head,
Genesis: genesis,
ForkID: forkID,
})
default:
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
}
}()
go func() {
switch {
case supportsEth64(p.version):
errc <- p.readStatus(network, &status, genesis, forkFilter)
case supportsEth63(p.version):
case isEth63(p.version):
errc <- p.readStatusLegacy(network, &status63, genesis)
case isEth64OrHigher(p.version):
errc <- p.readStatus(network, &status, genesis, forkFilter)
default:
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
}
@ -836,10 +827,10 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
}
}
switch {
case supportsEth64(p.version):
p.td, p.head = status.TD, status.Head
case supportsEth63(p.version):
case isEth63(p.version):
p.td, p.head = status63.TD, status63.CurrentBlock
case isEth64OrHigher(p.version):
p.td, p.head = status.TD, status.Head
default:
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
}

View file

@ -38,44 +38,26 @@ const (
xdpos22 = 101 //xdpos2.2 = eth65
)
// XDC needs the below functions because direct number equality doesn't work (eg. version >= 63)
// we should try to match protocols 1 to 1 from now on, bump xdpos along with any new eth (eg. eth66 = xdpos23 only)
// try to follow the exact comparison from go-ethereum as much as possible (eg. version >= 63 <> isEth63OrHigher(version))
func isEth63(version int) bool {
switch {
case version < 63:
return false
case version >= 63:
case version == 63:
return true
case version == 100:
return true
default:
return false
}
}
func supportsEth64(version int) bool {
switch {
case version < 64:
return false
case version < 100:
return true
case version == 100:
return false
case version > 100:
return true
default:
return false
}
}
func isEth64(version int) bool {
switch {
case version < 65:
return false
case version < 100:
case version == 64:
return true
default:
return false
}
}
func isEth65(version int) bool {
switch {
case version == 65:

View file

@ -33,6 +33,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/core/vm"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
"github.com/XinFinOrg/XDPoSChain/event"
"github.com/XinFinOrg/XDPoSChain/p2p"
"github.com/XinFinOrg/XDPoSChain/p2p/enode"
@ -66,15 +67,15 @@ func TestStatusMsgErrors63(t *testing.T) {
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
},
{
code: StatusMsg, data: statusData63{10, DefaultConfig.NetworkId, td, head.Hash(), genesis.Hash()},
code: StatusMsg, data: statusData63{10, ethconfig.Defaults.NetworkId, td, head.Hash(), genesis.Hash()},
wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", 63),
},
{
code: StatusMsg, data: statusData63{63, 999, td, head.Hash(), genesis.Hash()},
wantError: errResp(ErrNetworkIDMismatch, "999 (!= %d)", DefaultConfig.NetworkId),
wantError: errResp(ErrNetworkIDMismatch, "999 (!= %d)", ethconfig.Defaults.NetworkId),
},
{
code: StatusMsg, data: statusData63{63, DefaultConfig.NetworkId, td, head.Hash(), common.Hash{3}},
code: StatusMsg, data: statusData63{63, ethconfig.Defaults.NetworkId, td, head.Hash(), common.Hash{3}},
wantError: errResp(ErrGenesisMismatch, "0300000000000000 (!= %x)", genesis.Hash().Bytes()[:8]),
},
}
@ -118,19 +119,19 @@ func TestStatusMsgErrors64(t *testing.T) {
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
},
{
code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, td, head.Hash(), genesis.Hash(), forkID},
code: StatusMsg, data: statusData{10, ethconfig.Defaults.NetworkId, td, head.Hash(), genesis.Hash(), forkID},
wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", 64),
},
{
code: StatusMsg, data: statusData{64, 999, td, head.Hash(), genesis.Hash(), forkID},
wantError: errResp(ErrNetworkIDMismatch, "999 (!= %d)", DefaultConfig.NetworkId),
wantError: errResp(ErrNetworkIDMismatch, "999 (!= %d)", ethconfig.Defaults.NetworkId),
},
{
code: StatusMsg, data: statusData{64, DefaultConfig.NetworkId, td, head.Hash(), common.Hash{3}, forkID},
code: StatusMsg, data: statusData{64, ethconfig.Defaults.NetworkId, td, head.Hash(), common.Hash{3}, forkID},
wantError: errResp(ErrGenesisMismatch, "0300000000000000000000000000000000000000000000000000000000000000 (!= %x)", genesis.Hash()),
},
{
code: StatusMsg, data: statusData{64, DefaultConfig.NetworkId, td, head.Hash(), genesis.Hash(), forkid.ID{Hash: [4]byte{0x00, 0x01, 0x02, 0x03}}},
code: StatusMsg, data: statusData{64, ethconfig.Defaults.NetworkId, td, head.Hash(), genesis.Hash(), forkid.ID{Hash: [4]byte{0x00, 0x01, 0x02, 0x03}}},
wantError: errResp(ErrForkIDRejected, forkid.ErrLocalIncompatibleOrStale.Error()),
},
}
@ -255,6 +256,7 @@ func TestRecvTransactions63(t *testing.T) { testRecvTransactions(t, 63) }
func TestRecvTransactions64(t *testing.T) { testRecvTransactions(t, 64) }
func TestRecvTransactions65(t *testing.T) { testRecvTransactions(t, 65) }
func TestRecvTransactions100(t *testing.T) { testRecvTransactions(t, 100) }
func TestRecvTransactions101(t *testing.T) { testRecvTransactions(t, 101) }
func testRecvTransactions(t *testing.T, protocol int) {
txAdded := make(chan []*types.Transaction)
@ -284,7 +286,8 @@ func testRecvTransactions(t *testing.T, protocol int) {
func TestSendTransactions63(t *testing.T) { testSendTransactions(t, 63) }
func TestSendTransactions64(t *testing.T) { testSendTransactions(t, 64) }
func TestSendTransactions65(t *testing.T) { testSendTransactions(t, 65) }
func TestSendTransactions100(t *testing.T) { testSendTransactions(t, 100) }
func TestSendTransactions100(t *testing.T) { testSendTransactions(t, 100) }
func TestSendTransactions101(t *testing.T) { testSendTransactions(t, 101) }
func testSendTransactions(t *testing.T, protocol int) {
pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, 0, nil, nil)

View file

@ -61,7 +61,7 @@ func (pm *ProtocolManager) syncTransactions(p *peer) {
// The eth/65 protocol introduces proper transaction announcements, so instead
// of dripping transactions across multiple peers, just send the entire list as
// an announcement and let the remote side decide what they need (likely nothing).
if supportsEth65(p.version) {
if isEth65OrHigher(p.version) {
hashes := make([]common.Hash, len(txs))
for i, tx := range txs {
hashes[i] = tx.Hash()
@ -89,7 +89,7 @@ func (pm *ProtocolManager) txsyncLoop64() {
)
// send starts a sending a pack of transactions from the sync.
send := func(s *txsync) {
if supportsEth65(s.p.version) {
if isEth65OrHigher(s.p.version) {
panic("initial transaction syncer running on eth/65+")
}
// Fill pack with transactions up to the target size.

View file

@ -30,6 +30,7 @@ func TestFastSyncDisabling63(t *testing.T) { testFastSyncDisabling(t, 63) }
func TestFastSyncDisabling64(t *testing.T) { testFastSyncDisabling(t, 64) }
func TestFastSyncDisabling65(t *testing.T) { testFastSyncDisabling(t, 65) }
func TestFastSyncDisabling100(t *testing.T) { testFastSyncDisabling(t, 100) }
func TestFastSyncDisabling101(t *testing.T) { testFastSyncDisabling(t, 101) }
// Tests that fast sync gets disabled as soon as a real block is successfully
// imported into the blockchain.