diff options
author | Sonic <sonic@dexon.org> | 2018-12-05 15:17:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 13:49:59 +0800 |
commit | e9215a6b296c009f150f29b8881282c5c82b4fca (patch) | |
tree | 454515e4980c71a80ce10add40d202d1aa712b4a /dex/sync.go | |
parent | a5ab05bc54d3f257e4cf950a047d97de3a18828d (diff) | |
download | dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar.gz dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar.bz2 dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar.lz dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar.xz dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.tar.zst dexon-e9215a6b296c009f150f29b8881282c5c82b4fca.zip |
core, dex: polish sync (#75)
- Broadcasting blocks at chain head event is not correct when the full
node is not running in block proposer mode. Introduce NewFinalizedBlockEvent,
this event is post by the full node which runs in block proposer mode when a
block is witnessed and resulting in some blocks are considered finalized.
- Non block proposer node will still broadcast blocks
at the following moment (same as ethereum):
1. a sync with a peer is terminated successfully
2. a block passes the fetcher's header check during inserting blocks
3. a block is successfully inserted by fetcher
- Don't trigger a sync when we are not behind other peers more than
acceptable distance. Fetcher is able to cover this.
Diffstat (limited to 'dex/sync.go')
-rw-r--r-- | dex/sync.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/dex/sync.go b/dex/sync.go index 43f1291ff..1e35faf21 100644 --- a/dex/sync.go +++ b/dex/sync.go @@ -32,6 +32,10 @@ const ( forceSyncCycle = 10 * time.Second // Time interval to force syncs, even if few peers are available minDesiredPeerCount = 5 // Amount of peers desired to start syncing + // The distance between us and peer that we can accept. + // This distance is related to numChains and lambdaBA dexcon config. + acceptableDist = 16 + // This is the target size for the packs of transactions sent by txsyncLoop. // A pack can get larger than this if a single transactions exceeds this size. txsyncPackSize = 100 * 1024 @@ -263,7 +267,9 @@ func (pm *ProtocolManager) synchronise(peer *peer) { pHead, pNumber := peer.Head() - if pNumber <= number { + // If we are behind the peer, but not more than acceptable distance, don't + // trigger a sync. Fetcher is able to cover this. + if pNumber <= number+acceptableDist { return } // Otherwise try to sync with the downloader |