Bläddra i källkod

Merge pull request #473 from j75689/ci/fix_test_flow

Ci/fix test flow
yutianwu 4 år sedan
förälder
incheckning
98c4e81643

+ 1 - 4
.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
 

+ 18 - 16
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))

+ 5 - 1
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())

+ 2 - 2
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)
 		}
 	}
 }

+ 1 - 4
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" ]