Skip to content

Commit

Permalink
Merge pull request #600 from lochjin/dev1.2
Browse files Browse the repository at this point in the history
BUG:The issue of block dag synchronization
  • Loading branch information
dindinw authored Jan 29, 2024
2 parents 69b151a + 27a4545 commit d606bb4
Show file tree
Hide file tree
Showing 10 changed files with 1,543 additions and 1,152 deletions.
8 changes: 7 additions & 1 deletion core/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ const (
// network.
InitialProcotolVersion uint32 = 42

// Support check data consistency
ConsistencyProtocolVersion uint32 = 43

// Support continue block sync for DAG search
ConSyncDAGProtocolVersion uint32 = 44

// ProtocolVersion is the latest protocol version this package supports.
ProtocolVersion uint32 = 43
ProtocolVersion uint32 = ConSyncDAGProtocolVersion
)

// Network represents which qitmeer network a message belongs to.
Expand Down
38 changes: 21 additions & 17 deletions meerdag/dagsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const MaxMainLocatorNum = 32
type SyncMode byte

const (
DirectMode SyncMode = 0
SubDAGMode SyncMode = 1
DirectMode SyncMode = 0
SubDAGMode SyncMode = 1
ContinueMode SyncMode = 2
)

type DAGSync struct {
Expand All @@ -37,6 +38,23 @@ func (ds *DAGSync) CalcSyncBlocks(gs *GraphState, locator []*hash.Hash, mode Syn
return result, nil
}
return ds.bd.sortBlock(locator), nil
} else if mode == ContinueMode {
result := []*hash.Hash{}
if len(locator) <= 0 {
return result, nil
}
point := ds.bd.getBlock(locator[0])
if point == nil {
return result, nil
}
if !ds.bd.isOnMainChain(point.GetID()) {
return result, nil
}
startBlock := ds.bd.getBlock(locator[1])
if startBlock == nil {
return result, nil
}
return ds.getBlockChainFromMain(startBlock, maxHashes), point.GetHash()
}

var point IBlock
Expand Down Expand Up @@ -71,21 +89,7 @@ func (ds *DAGSync) CalcSyncBlocks(gs *GraphState, locator []*hash.Hash, mode Syn
if point == nil {
point = ds.bd.getGenesis()
}
syncPoint := point
for _, t := range gs.tips {
tip := ds.bd.getBlock(&t)
if tip == nil {
continue
}
if !tip.IsOrdered() {
continue
}
if tip.GetOrder() > syncPoint.GetOrder() {
syncPoint = tip
}
}
log.Trace("CalcSyncBlocks", "point", point.GetHash().String(), "syncPoint", syncPoint.GetHash().String())
return ds.getBlockChainFromMain(syncPoint, maxHashes), point.GetHash()
return ds.getBlockChainFromMain(point, maxHashes), point.GetHash()
}

// GetMainLocator
Expand Down
6 changes: 2 additions & 4 deletions meerdag/tips.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ func (bd *MeerDAG) getValidTips(limit bool) []IBlock {
continue
}
block := bd.getBlockById(parents[i])
if limit {
if math.Abs(float64(block.GetLayer())-float64(mainParent.GetLayer())) > MaxTipLayerGap {
continue
}
if math.Abs(float64(block.GetLayer())-float64(mainParent.GetLayer())) > MaxTipLayerGap {
continue
}
_, exist := tipsM[block.GetHash().String()]
if exist {
Expand Down
Loading

0 comments on commit d606bb4

Please sign in to comment.