From faa007de15523ca4f7d1d6ec08b2baf4c45f3755 Mon Sep 17 00:00:00 2001 From: j75689 Date: Wed, 20 Oct 2021 18:29:40 +0800 Subject: [PATCH 1/5] ci: fix error on install truffle --- docker/Dockerfile.truffle | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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" ] From 100db0784a6f46487136080252f9eb3896895bdd Mon Sep 17 00:00:00 2001 From: j75689 Date: Wed, 20 Oct 2021 18:30:43 +0800 Subject: [PATCH 2/5] ci: remove unnecessary job in unit test --- .github/workflows/unit-test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 737e4928a7..e885e4acf5 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -43,10 +43,6 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Test Build - run: | - make geth - - name: Uint Test env: ANDROID_HOME: "" # Skip android test From 3e5a7c0abcc41b527580a3ff56d6e53a6581bd4e Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 21 Oct 2021 12:37:44 +0800 Subject: [PATCH 3/5] fix: unit-test failed --- core/blockchain_diff_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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()) From 87bd1b0d612163f0a31a1a7d41a3323f250a86e3 Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 21 Oct 2021 12:40:27 +0800 Subject: [PATCH 4/5] feat: time.Tick replaced with time.Ticker --- core/blockchain.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) 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)) From a9657cb0e67161514d64aa5f0e29b817f629afcb Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 21 Oct 2021 15:24:30 +0800 Subject: [PATCH 5/5] debug --- .github/workflows/unit-test.yml | 1 + core/blockchain_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index e885e4acf5..8847aeba4d 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -47,5 +47,6 @@ jobs: env: ANDROID_HOME: "" # Skip android test run: | + go clean -testcache make test 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) } } }