|
|
@ -74,14 +74,12 @@ func testSequentialAnnouncements(t *testing.T, protocol int) { |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
defer teardown() |
|
|
|
defer teardown() |
|
|
|
|
|
|
|
|
|
|
|
// Create connected peer pair.
|
|
|
|
// Create connected peer pair, the initial signal from LES server
|
|
|
|
c.handler.fetcher.noAnnounce = true // Ignore the first announce from peer which can trigger a resync.
|
|
|
|
// is discarded to prevent syncing.
|
|
|
|
p1, _, err := newTestPeerPair("peer", protocol, s.handler, c.handler) |
|
|
|
p1, _, err := newTestPeerPair("peer", protocol, s.handler, c.handler, true) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
c.handler.fetcher.noAnnounce = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
importCh := make(chan interface{}) |
|
|
|
importCh := make(chan interface{}) |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { |
|
|
|
importCh <- header |
|
|
|
importCh <- header |
|
|
@ -114,14 +112,12 @@ func testGappedAnnouncements(t *testing.T, protocol int) { |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
defer teardown() |
|
|
|
defer teardown() |
|
|
|
|
|
|
|
|
|
|
|
// Create connected peer pair.
|
|
|
|
// Create connected peer pair, the initial signal from LES server
|
|
|
|
c.handler.fetcher.noAnnounce = true // Ignore the first announce from peer which can trigger a resync.
|
|
|
|
// is discarded to prevent syncing.
|
|
|
|
peer, _, err := newTestPeerPair("peer", protocol, s.handler, c.handler) |
|
|
|
peer, _, err := newTestPeerPair("peer", protocol, s.handler, c.handler, true) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
c.handler.fetcher.noAnnounce = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done := make(chan *types.Header, 1) |
|
|
|
done := make(chan *types.Header, 1) |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { done <- header } |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { done <- header } |
|
|
|
|
|
|
|
|
|
|
@ -141,29 +137,11 @@ func testGappedAnnouncements(t *testing.T, protocol int) { |
|
|
|
verifyChainHeight(t, c.handler.fetcher, 4) |
|
|
|
verifyChainHeight(t, c.handler.fetcher, 4) |
|
|
|
|
|
|
|
|
|
|
|
// Send a reorged announcement
|
|
|
|
// Send a reorged announcement
|
|
|
|
var newAnno = make(chan struct{}, 1) |
|
|
|
|
|
|
|
c.handler.fetcher.noAnnounce = true |
|
|
|
|
|
|
|
c.handler.fetcher.newAnnounce = func(*serverPeer, *announceData) { |
|
|
|
|
|
|
|
newAnno <- struct{}{} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
blocks, _ := core.GenerateChain(rawdb.ReadChainConfig(s.db, s.backend.Blockchain().Genesis().Hash()), s.backend.Blockchain().GetBlockByNumber(3), |
|
|
|
blocks, _ := core.GenerateChain(rawdb.ReadChainConfig(s.db, s.backend.Blockchain().Genesis().Hash()), s.backend.Blockchain().GetBlockByNumber(3), |
|
|
|
ethash.NewFaker(), s.db, 2, func(i int, gen *core.BlockGen) { |
|
|
|
ethash.NewFaker(), s.db, 2, func(i int, gen *core.BlockGen) { |
|
|
|
gen.OffsetTime(-9) // higher block difficulty
|
|
|
|
gen.OffsetTime(-9) // higher block difficulty
|
|
|
|
}) |
|
|
|
}) |
|
|
|
s.backend.Blockchain().InsertChain(blocks) |
|
|
|
s.backend.Blockchain().InsertChain(blocks) |
|
|
|
<-newAnno |
|
|
|
|
|
|
|
c.handler.fetcher.noAnnounce = false |
|
|
|
|
|
|
|
c.handler.fetcher.newAnnounce = nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
latest = blocks[len(blocks)-1].Header() |
|
|
|
|
|
|
|
hash, number = latest.Hash(), latest.Number.Uint64() |
|
|
|
|
|
|
|
td = rawdb.ReadTd(s.db, hash, number) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
announce = announceData{hash, number, td, 1, nil} |
|
|
|
|
|
|
|
if peer.cpeer.announceType == announceTypeSigned { |
|
|
|
|
|
|
|
announce.sign(s.handler.server.privateKey) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
peer.cpeer.sendAnnounce(announce) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<-done // Wait syncing
|
|
|
|
<-done // Wait syncing
|
|
|
|
verifyChainHeight(t, c.handler.fetcher, 5) |
|
|
|
verifyChainHeight(t, c.handler.fetcher, 5) |
|
|
@ -206,20 +184,15 @@ func testTrustedAnnouncement(t *testing.T, protocol int) { |
|
|
|
teardowns[i]() |
|
|
|
teardowns[i]() |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
c.handler.fetcher.noAnnounce = true // Ignore the first announce from peer which can trigger a resync.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Connect all server instances.
|
|
|
|
// Connect all server instances.
|
|
|
|
for i := 0; i < len(servers); i++ { |
|
|
|
for i := 0; i < len(servers); i++ { |
|
|
|
sp, cp, err := connect(servers[i].handler, nodes[i].ID(), c.handler, protocol) |
|
|
|
sp, cp, err := connect(servers[i].handler, nodes[i].ID(), c.handler, protocol, true) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("connect server and client failed, err %s", err) |
|
|
|
t.Fatalf("connect server and client failed, err %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
cpeers = append(cpeers, cp) |
|
|
|
cpeers = append(cpeers, cp) |
|
|
|
speers = append(speers, sp) |
|
|
|
speers = append(speers, sp) |
|
|
|
} |
|
|
|
} |
|
|
|
c.handler.fetcher.noAnnounce = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newHead := make(chan *types.Header, 1) |
|
|
|
newHead := make(chan *types.Header, 1) |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { newHead <- header } |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { newHead <- header } |
|
|
|
|
|
|
|
|
|
|
@ -262,14 +235,12 @@ func testInvalidAnnounces(t *testing.T, protocol int) { |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
s, c, teardown := newClientServerEnv(t, netconfig) |
|
|
|
defer teardown() |
|
|
|
defer teardown() |
|
|
|
|
|
|
|
|
|
|
|
// Create connected peer pair.
|
|
|
|
// Create connected peer pair, the initial signal from LES server
|
|
|
|
c.handler.fetcher.noAnnounce = true // Ignore the first announce from peer which can trigger a resync.
|
|
|
|
// is discarded to prevent syncing.
|
|
|
|
peer, _, err := newTestPeerPair("peer", lpv3, s.handler, c.handler) |
|
|
|
peer, _, err := newTestPeerPair("peer", lpv3, s.handler, c.handler, true) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
t.Fatalf("Failed to create peer pair %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
c.handler.fetcher.noAnnounce = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done := make(chan *types.Header, 1) |
|
|
|
done := make(chan *types.Header, 1) |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { done <- header } |
|
|
|
c.handler.fetcher.newHeadHook = func(header *types.Header) { done <- header } |
|
|
|
|
|
|
|
|
|
|
|