Skip to content

Commit

Permalink
Merge pull request #473 from j75689/ci/fix_test_flow
Browse files Browse the repository at this point in the history
Ci/fix test flow
  • Loading branch information
yutianwu authored Nov 1, 2021
2 parents 60e92c1 + a9657cb commit 98c4e81
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 18 additions & 16 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion core/blockchain_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions docker/Dockerfile.truffle
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

0 comments on commit 98c4e81

Please sign in to comment.