aboutsummaryrefslogtreecommitdiffstats
path: root/dex/sync.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-12-04 16:13:41 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:19 +0800
commit5d031e08ed2758eb7fa9c2d9c107204f93ae0733 (patch)
tree3a7ed42404b9b9ace5424578c7b2753444014417 /dex/sync.go
parent122e398cd89925216226f8f5a194c93bf8921897 (diff)
downloadgo-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar.gz
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar.bz2
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar.lz
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar.xz
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.tar.zst
go-tangerine-5d031e08ed2758eb7fa9c2d9c107204f93ae0733.zip
dex: replace total difficulty with block number (#73)
In dexon, we don't "mine" and the blockchain won't and shouldn't fork, so there is no difficulty concept, just replace it with block number. Note: this commit only replace total difficulty related logic and code in dex, dex/downloader package.
Diffstat (limited to 'dex/sync.go')
-rw-r--r--dex/sync.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/dex/sync.go b/dex/sync.go
index b6a8035d4..43f1291ff 100644
--- a/dex/sync.go
+++ b/dex/sync.go
@@ -257,12 +257,13 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
if peer == nil {
return
}
- // Make sure the peer's TD is higher than our own
+ // Make sure the peer's number is higher than our own
currentBlock := pm.blockchain.CurrentBlock()
- td := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
+ number := currentBlock.NumberU64()
- pHead, pTd := peer.Head()
- if pTd.Cmp(td) <= 0 {
+ pHead, pNumber := peer.Head()
+
+ if pNumber <= number {
return
}
// Otherwise try to sync with the downloader
@@ -282,13 +283,13 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
if mode == downloader.FastSync {
// Make sure the peer's total difficulty we are synchronizing is higher.
- if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
+ if pm.blockchain.CurrentFastBlock().NumberU64() >= pNumber {
return
}
}
// Run the sync cycle, and disable fast sync if we've went past the pivot block
- if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
+ if err := pm.downloader.Synchronise(peer.id, pHead, pNumber, mode); err != nil {
return
}
if atomic.LoadUint32(&pm.fastSync) == 1 {
@@ -302,7 +303,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
// all its out-of-date peers of the availability of a new block. This failure
// scenario will most often crop up in private and hackathon networks with
// degenerate connectivity, but it should be healthy for the mainnet too to
- // more reliably update peers or the local TD state.
+ // more reliably update peers or the local number state.
go pm.BroadcastBlock(head, false)
}
}