Skip to content

Commit 05ec7aa

Browse files
authored
Skip fast path for mblock if its rblock confirmation is too old (#655)
* Skip fast path for mblock if its rblock confirmation is too old
1 parent 0d90301 commit 05ec7aa

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

cluster/sync/minor_task.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/QuarkChain/goquarkchain/account"
77
"github.com/QuarkChain/goquarkchain/cluster/rpc"
88
qcom "github.com/QuarkChain/goquarkchain/common"
9+
"github.com/QuarkChain/goquarkchain/core"
910
"github.com/QuarkChain/goquarkchain/core/types"
1011
"github.com/QuarkChain/goquarkchain/p2p"
1112
"github.com/ethereum/go-ethereum/common"
@@ -105,6 +106,26 @@ func NewMinorChainTask(
105106
if mTask.header.NumberU64() <= b.CurrentHeader().NumberU64() || b.HasBlock(mTask.header.Hash()) {
106107
return true
107108
}
109+
110+
bc, ok := b.(*core.MinorBlockChain)
111+
if !ok {
112+
return false
113+
}
114+
// Do not download if the prev root block is not synced
115+
rootBlockHeader := bc.GetRootBlockByHash(mTask.header.PrevRootBlockHash)
116+
if rootBlockHeader == nil {
117+
return true
118+
}
119+
120+
// Do not download if the new header's confirmed root is lower then current root tip last header's confirmed root
121+
// This means the minor block's root is a fork, which will be handled by master sync
122+
if bc.GetMinorTip() == nil {
123+
return false
124+
}
125+
confirmedRootHeader := bc.GetRootBlockByHash(bc.GetMinorTip().PrevRootBlockHash())
126+
if confirmedRootHeader != nil && confirmedRootHeader.NumberU64() > rootBlockHeader.NumberU64() {
127+
return true
128+
}
108129
return false
109130
},
110131
}

cluster/sync/minor_task_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ func newMinorBlockChain(sz int) (blockchain, ethdb.Database) {
100100
blocks = append(blocks, mb)
101101
}
102102

103-
blockchain, err := core.NewMinorBlockChain(db, nil, params.TestChainConfig, clusterConfig, engine, vm.Config{}, nil, fullShardID)
103+
mbc, err := core.NewMinorBlockChain(db, nil, params.TestChainConfig, clusterConfig, engine, vm.Config{}, nil, fullShardID)
104104
if err != nil {
105105
panic(fmt.Sprintf("failed to create minor blockchain: %v", err))
106106
}
107-
_, err = blockchain.InitGenesisState(rootBlock)
107+
_, err = mbc.InitGenesisState(rootBlock)
108108
if err != nil {
109109
panic(fmt.Sprintf("failed to init minor blockchain: %v", err))
110110
}
111-
if _, err := blockchain.InsertChain(blocks, false); err != nil {
111+
if _, err := mbc.InsertChain(blocks, false); err != nil {
112112
panic(fmt.Sprintf("failed to insert minor blocks: %v", err))
113113
}
114114

115-
return &mockblockchain{mbc: blockchain}, db
115+
return &mockblockchain{mbc: mbc}, db
116116
}
117117

118118
func TestMinorChainTask(t *testing.T) {

0 commit comments

Comments
 (0)