Skip to content

Commit

Permalink
Skip fast path for mblock if its rblock confirmation is too old (#655)
Browse files Browse the repository at this point in the history
* Skip fast path for mblock if its rblock confirmation is too old
  • Loading branch information
ping-ke authored Apr 21, 2022
1 parent 0d90301 commit 05ec7aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions cluster/sync/minor_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/QuarkChain/goquarkchain/account"
"github.com/QuarkChain/goquarkchain/cluster/rpc"
qcom "github.com/QuarkChain/goquarkchain/common"
"github.com/QuarkChain/goquarkchain/core"
"github.com/QuarkChain/goquarkchain/core/types"
"github.com/QuarkChain/goquarkchain/p2p"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -105,6 +106,26 @@ func NewMinorChainTask(
if mTask.header.NumberU64() <= b.CurrentHeader().NumberU64() || b.HasBlock(mTask.header.Hash()) {
return true
}

bc, ok := b.(*core.MinorBlockChain)
if !ok {
return false
}
// Do not download if the prev root block is not synced
rootBlockHeader := bc.GetRootBlockByHash(mTask.header.PrevRootBlockHash)
if rootBlockHeader == nil {
return true
}

// Do not download if the new header's confirmed root is lower then current root tip last header's confirmed root
// This means the minor block's root is a fork, which will be handled by master sync
if bc.GetMinorTip() == nil {
return false
}
confirmedRootHeader := bc.GetRootBlockByHash(bc.GetMinorTip().PrevRootBlockHash())
if confirmedRootHeader != nil && confirmedRootHeader.NumberU64() > rootBlockHeader.NumberU64() {
return true
}
return false
},
}
Expand Down
8 changes: 4 additions & 4 deletions cluster/sync/minor_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ func newMinorBlockChain(sz int) (blockchain, ethdb.Database) {
blocks = append(blocks, mb)
}

blockchain, err := core.NewMinorBlockChain(db, nil, params.TestChainConfig, clusterConfig, engine, vm.Config{}, nil, fullShardID)
mbc, err := core.NewMinorBlockChain(db, nil, params.TestChainConfig, clusterConfig, engine, vm.Config{}, nil, fullShardID)
if err != nil {
panic(fmt.Sprintf("failed to create minor blockchain: %v", err))
}
_, err = blockchain.InitGenesisState(rootBlock)
_, err = mbc.InitGenesisState(rootBlock)
if err != nil {
panic(fmt.Sprintf("failed to init minor blockchain: %v", err))
}
if _, err := blockchain.InsertChain(blocks, false); err != nil {
if _, err := mbc.InsertChain(blocks, false); err != nil {
panic(fmt.Sprintf("failed to insert minor blocks: %v", err))
}

return &mockblockchain{mbc: blockchain}, db
return &mockblockchain{mbc: mbc}, db
}

func TestMinorChainTask(t *testing.T) {
Expand Down

0 comments on commit 05ec7aa

Please sign in to comment.