8000 fix(test): `TestBlockPoolMaliciousNode` shutdown threads at exit (backport #4633) by mergify[bot] · Pull Request #4635 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(test): TestBlockPoolMaliciousNode shutdown threads at exit (backport #4633) #4635

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

Merged
merged 3 commits into from
Dec 11, 2024
Merged
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
38 changes: 24 additions & 14 deletions blocksync/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,29 +319,39 @@ func TestBlockPoolMaliciousNode(t *testing.T) {
for _, peer := range peers {
pool.SetPeerRange(peer.id, peer.base, peer.height)
}

ticker := time.NewTicker(1 * time.Second) // Speed of new block creation
defer ticker.Stop()
for {
time.Sleep(1 * time.Second) // Speed of new block creation
for _, peer := range peers {
peer.height += 1 // Network height increases on all peers
pool.SetPeerRange(peer.id, peer.base, peer.height) // Tell the pool that a new height is available
select {
case <-pool.Quit():
return
case <-ticker.C:
for _, peer := range peers {
peer.height++ // Network height increases on all peers
pool.SetPeerRange(peer.id, peer.base, peer.height) // Tell the pool that a new height is available
}
}
}
}()

// Start a goroutine to verify blocks
go func() {
ticker := time.NewTicker(500 * time.Millisecond) // Speed of new block creation
defer ticker.Stop()
for {
time.Sleep(500 * time.Millisecond) // Speed of block verification
if !pool.IsRunning() {
select {
case <-pool.Quit():
return
}
first, second, _ := pool.PeekTwoBlocks()
if first != nil && second != nil {
if second.LastCommit == nil {
// Second block is fake
pool.RemovePeerAndRedoAllPeerRequests(second.Height)
} else {
pool.PopRequest()
case <-ticker.C:
first, second, _ := pool.PeekTwoBlocks()
if first != nil && second != nil {
if second.LastCommit == nil {
// Second block is fake
pool.RemovePeerAndRedoAllPeerRequests(second.Height)
} else {
pool.PopRequest()
}
}
}
}
Expand Down
Loading
0