aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-09 23:39:53 +0800
committerGitHub <noreply@github.com>2019-04-09 23:39:53 +0800
commit3a22fdf183c88a518c9836d625f2b8cf4d2baa76 (patch)
tree7a4e362c82813e8799a48a3023b00424e20e0edd
parentcb9705fc63c871fcf31b3018a328e4535ba63a28 (diff)
downloaddexon-3a22fdf183c88a518c9836d625f2b8cf4d2baa76.tar.gz
dexon-3a22fdf183c88a518c9836d625f2b8cf4d2baa76.tar.zst
dexon-3a22fdf183c88a518c9836d625f2b8cf4d2baa76.zip
dex: remove time alignment when force sync (#349)
* vendor: sync to latest core * dex: remove time alignment when force sync
-rw-r--r--dex/blockproposer.go17
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go13
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/watch-cat.go8
-rw-r--r--vendor/vendor.json42
4 files changed, 39 insertions, 41 deletions
diff --git a/dex/blockproposer.go b/dex/blockproposer.go
index 8eaeb9761..d675da4ac 100644
--- a/dex/blockproposer.go
+++ b/dex/blockproposer.go
@@ -194,7 +194,6 @@ Loop:
log.Debug("Listen chain head event until synced")
- nextDMoment := time.Now().Unix()
// Listen chain head event until synced.
ListenLoop:
for {
@@ -236,26 +235,12 @@ ListenLoop:
case <-b.watchCat.Meow():
log.Info("WatchCat signaled to stop syncing")
- // Sleep until the next consensus start time slot.
- // The interval T_i need to meet the following requirement:
- //
- // T_i > T_timeout + T_panic + T_restart
- //
- // Currently, T_timeout = 120, T_panic = 60, T_restart ~ 60
- //
- // We set T_i = 600 to be safe.
-
- interval := int64(600)
- nextDMoment = (time.Now().Unix()/interval + 1) * interval
- log.Info("Sleeping until next starting time", "time", nextDMoment)
-
b.dex.protocolManager.SetReceiveCoreMessage(true)
- consensusSync.ForceSync(true)
+ consensusSync.ForceSync(b.watchCat.LastPosition(), true)
break ListenLoop
}
}
con, err := consensusSync.GetSyncedConsensus()
- time.Sleep(time.Duration(nextDMoment-time.Now().Unix()) * time.Second)
return con, err
}
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go
index f4681a268..7db836a9a 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/consensus.go
@@ -276,17 +276,21 @@ func (con *Consensus) buildAllEmptyBlocks() {
}
// ForceSync forces syncer to become synced.
-func (con *Consensus) ForceSync(skip bool) {
+func (con *Consensus) ForceSync(lastPos types.Position, skip bool) {
if con.syncedLastBlock != nil {
return
}
- hash, _ := con.db.GetCompactionChainTipInfo()
- var block types.Block
+ hash, height := con.db.GetCompactionChainTipInfo()
+ if height < lastPos.Height {
+ panic(fmt.Errorf("compaction chain not synced height %d, tip %d",
+ lastPos.Height, height))
+ } else if height > lastPos.Height {
+ skip = false
+ }
block, err := con.db.GetBlock(hash)
if err != nil {
panic(err)
}
- con.logger.Info("Force Sync", "block", &block)
con.syncedLastBlock = &block
con.stopBuffering()
// We might call stopBuffering without calling assureBuffering.
@@ -298,6 +302,7 @@ func (con *Consensus) ForceSync(skip bool) {
})
}
con.syncedSkipNext = skip
+ con.logger.Info("Force Sync", "block", &block, "skip", skip)
}
// SyncBlocks syncs blocks from compaction chain, latest is true if the caller
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/watch-cat.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/watch-cat.go
index d08bff9e9..f2e197ebe 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/watch-cat.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/syncer/watch-cat.go
@@ -37,6 +37,7 @@ type WatchCat struct {
timeout time.Duration
configReader configReader
feed chan types.Position
+ lastPosition types.Position
polling time.Duration
ctx context.Context
cancel context.CancelFunc
@@ -69,6 +70,7 @@ func (wc *WatchCat) Feed(position types.Position) {
// Start the WatchCat.
func (wc *WatchCat) Start() {
wc.Stop()
+ wc.lastPosition = types.Position{}
wc.ctx, wc.cancel = context.WithCancel(context.Background())
go func() {
var lastPos types.Position
@@ -124,6 +126,7 @@ func (wc *WatchCat) Start() {
wc.logger.Error("Failed to get recovery votes", "height", lastPos.Height, "error", err)
} else if votes > threshold {
wc.logger.Info("Threshold for recovery reached!")
+ wc.lastPosition = lastPos
break ResetLoop
}
select {
@@ -146,3 +149,8 @@ func (wc *WatchCat) Stop() {
func (wc *WatchCat) Meow() <-chan struct{} {
return wc.ctx.Done()
}
+
+// LastPosition returns the last position for recovery.
+func (wc *WatchCat) LastPosition() types.Position {
+ return wc.lastPosition
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index bc11c9398..f98477f06 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -141,16 +141,16 @@
{
"checksumSHA1": "In6vBHYUsX7DUIGiFN2hQggBgvI=",
"path": "github.com/dexon-foundation/dexon-consensus/common",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "+omcW5A0/pD0ScXpN2SWIP6RC7A=",
"path": "github.com/dexon-foundation/dexon-consensus/core",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
@@ -165,64 +165,64 @@
{
"checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "m5lUT04qSHKtFukvxjnFX5Jo2hI=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "BhLKK8RveoLaeXc9UyUKMwQqchU=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "hj/KetWUHp+1CX+50V0QnCthfWc=",
"path": "github.com/dexon-foundation/dexon-consensus/core/db",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
- "checksumSHA1": "B+2VHG7l1JXbxjuL52d+yp54K1g=",
+ "checksumSHA1": "/OcEQKdtWDyRZibazIsAxJWHUyg=",
"path": "github.com/dexon-foundation/dexon-consensus/core/syncer",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "zIgCdN4FJiAuPGMhB+/9YGK/Wgk=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "lbG7yqVgzo2CV/CQPYjG78xp5jg=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},
{
"checksumSHA1": "1VsJIshz0loXnGwCtrMM8SuIo6Y=",
"path": "github.com/dexon-foundation/dexon-consensus/core/utils",
- "revision": "f5a753891357ce76308578234ed9edd15bf81f23",
- "revisionTime": "2019-04-09T08:31:02Z",
+ "revision": "948be08a7294e26f3b52f94f9af803f69680f9df",
+ "revisionTime": "2019-04-09T09:36:40Z",
"version": "single-chain",
"versionExact": "single-chain"
},