Skip to content

Commit

Permalink
UT: fix some flaky tests (ethereum#1379)
Browse files Browse the repository at this point in the history
* core/state: Remove prefetcher on stop
* core/blockchain: Wait for `triedb.Dereference` in `writeBlockWithState`
* eth/protocols/diff: Fix index mismatch in `TestGetDiffLayers`
  • Loading branch information
ngotchac authored Apr 3, 2023
1 parent bd76c25 commit 221ef7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,11 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
bc.triegc.Push(root, number)
break
}
go triedb.Dereference(root.(common.Hash))
wg.Add(1)
go func() {
triedb.Dereference(root.(common.Hash))
wg.Done()
}()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (s *StateDB) StopPrefetcher() {
s.prefetcherLock.Lock()
if s.prefetcher != nil {
s.prefetcher.close()
s.prefetcher = nil
}
s.prefetcherLock.Unlock()
}
Expand Down
6 changes: 3 additions & 3 deletions eth/protocols/diff/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func testGetDiffLayers(t *testing.T, protocol uint) {
missDiffPackets := make([]FullDiffLayersPacket, 0)

for i := 0; i < 100; i++ {
number := uint64(rand.Int63n(1024))
if number == 0 {
continue
// Find a non 0 random number
var number uint64
for ; number == 0; number = uint64(rand.Int63n(1024)) {
}
foundHash := backend.chain.GetCanonicalHash(number + 1024)
missHash := backend.chain.GetCanonicalHash(number)
Expand Down

0 comments on commit 221ef7d

Please sign in to comment.