diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 737e4928a7..8847aeba4d 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -43,13 +43,10 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Test Build - run: | - make geth - - name: Uint Test env: ANDROID_HOME: "" # Skip android test run: | + go clean -testcache make test diff --git a/core/blockchain.go b/core/blockchain.go index 91371940cd..22fe3e5998 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2486,9 +2486,12 @@ func (bc *BlockChain) update() { } func (bc *BlockChain) trustedDiffLayerLoop() { - recheck := time.Tick(diffLayerFreezerRecheckInterval) + recheck := time.NewTicker(diffLayerFreezerRecheckInterval) bc.wg.Add(1) - defer bc.wg.Done() + defer func() { + bc.wg.Done() + recheck.Stop() + }() for { select { case diff := <-bc.diffQueueBuffer: @@ -2521,29 +2524,28 @@ func (bc *BlockChain) trustedDiffLayerLoop() { batch.Reset() } return - case <-recheck: + case <-recheck.C: currentHeight := bc.CurrentBlock().NumberU64() var batch ethdb.Batch for !bc.diffQueue.Empty() { diff, prio := bc.diffQueue.Pop() diffLayer := diff.(*types.DiffLayer) - // if the block old enough - if int64(currentHeight)+prio >= int64(bc.triesInMemory) { - canonicalHash := bc.GetCanonicalHash(uint64(-prio)) - // on the canonical chain - if canonicalHash == diffLayer.BlockHash { - if batch == nil { - batch = bc.db.DiffStore().NewBatch() - } - rawdb.WriteDiffLayer(batch, diffLayer.BlockHash, diffLayer) - staleHash := bc.GetCanonicalHash(uint64(-prio) - bc.diffLayerFreezerBlockLimit) - rawdb.DeleteDiffLayer(batch, staleHash) - } - } else { + // if the block not old enough + if int64(currentHeight)+prio < int64(bc.triesInMemory) { bc.diffQueue.Push(diffLayer, prio) break } + canonicalHash := bc.GetCanonicalHash(uint64(-prio)) + // on the canonical chain + if canonicalHash == diffLayer.BlockHash { + if batch == nil { + batch = bc.db.DiffStore().NewBatch() + } + rawdb.WriteDiffLayer(batch, diffLayer.BlockHash, diffLayer) + staleHash := bc.GetCanonicalHash(uint64(-prio) - bc.diffLayerFreezerBlockLimit) + rawdb.DeleteDiffLayer(batch, staleHash) + } if batch != nil && batch.ValueSize() > ethdb.IdealBatchSize { if err := batch.Write(); err != nil { panic(fmt.Sprintf("Failed to write diff layer, error %v", err)) diff --git a/core/blockchain_diff_test.go b/core/blockchain_diff_test.go index 0b289bdc1c..67affcff75 100644 --- a/core/blockchain_diff_test.go +++ b/core/blockchain_diff_test.go @@ -280,10 +280,14 @@ func TestFreezeDiffLayer(t *testing.T) { blockNum := 1024 fullBackend := newTestBackend(blockNum, true) defer fullBackend.close() + for len(fullBackend.chain.diffQueueBuffer) > 0 { + // Wait for the buffer to be zero. + } // Minus one empty block. if fullBackend.chain.diffQueue.Size() != blockNum-1 { - t.Errorf("size of diff queue is wrong, expected: %d, get: %d", blockNum, fullBackend.chain.diffQueue.Size()) + t.Errorf("size of diff queue is wrong, expected: %d, get: %d", blockNum-1, fullBackend.chain.diffQueue.Size()) } + time.Sleep(diffLayerFreezerRecheckInterval + 1*time.Second) if fullBackend.chain.diffQueue.Size() != int(fullBackend.chain.triesInMemory) { t.Errorf("size of diff queue is wrong, expected: %d, get: %d", blockNum, fullBackend.chain.diffQueue.Size()) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 4314bd45a9..6874534817 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1568,8 +1568,8 @@ func TestLargeReorgTrieGC(t *testing.T) { t.Fatalf("failed to finalize competitor chain: %v", err) } for i, block := range competitor[:len(competitor)-TestTriesInMemory] { - if node, _ := chain.stateCache.TrieDB().Node(block.Root()); node != nil { - t.Fatalf("competitor %d: competing chain state missing", i) + if node, err := chain.stateCache.TrieDB().Node(block.Root()); node != nil { + t.Fatalf("competitor %d: competing chain state missing, err: %v", i, err) } } } diff --git a/docker/Dockerfile.truffle b/docker/Dockerfile.truffle index 0ec7029377..28ab9da393 100644 --- a/docker/Dockerfile.truffle +++ b/docker/Dockerfile.truffle @@ -7,10 +7,7 @@ RUN git clone https://github.com/binance-chain/canonical-upgradeable-bep20.git / WORKDIR /usr/app/canonical-upgradeable-bep20 COPY docker/truffle-config.js /usr/app/canonical-upgradeable-bep20 -RUN npm install -g n -RUN n 12.18.3 && node -v - -RUN npm install -g truffle@v5.1.14 +RUN npm install -g --unsafe-perm truffle@v5.1.14 RUN npm install ENTRYPOINT [ "/bin/bash" ]