aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-25 10:06:35 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:20 +0800
commit9437d34cb57503309b25ea92808705da1d78ac44 (patch)
treecd29048f0829b03f956832e270ac1aec5ce7d96a /vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go
parent5e165d3cd5393492321dc598f6e595be4c4d21e4 (diff)
downloadgo-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.gz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.bz2
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.lz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.xz
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.tar.zst
go-tangerine-9437d34cb57503309b25ea92808705da1d78ac44.zip
vendor: sync DEXON core and fix conflicts/missings (#101)
Merging these commits in DEXON consensus core: - https://github.com/dexon-foundation/dexon-consensus/commit/dce509a13ef5873b9cae3c1cabdb97e219b6fb7d - https://github.com/dexon-foundation/dexon-consensus/commit/6d1c1aeea0d3e75d10cbb2712c68b4c422ba8ba6 - https://github.com/dexon-foundation/dexon-consensus/commit/c1ed57c4abaf1f4758e52f082bb7114ad00c8b39
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go
index 3bf6946ae..744471a84 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/total-ordering.go
@@ -19,6 +19,7 @@ package core
import (
"errors"
+ "fmt"
"math"
"sort"
"sync"
@@ -1017,7 +1018,7 @@ func (to *totalOrdering) generateDeliverSet() (
chainID, otherChainID uint32
info, otherInfo *totalOrderingCandidateInfo
precedings = make(map[uint32]struct{})
- cfg = to.configs[to.curRound-to.configs[0].roundID]
+ cfg = to.getCurrentConfig()
)
mode = TotalOrderingModeNormal
to.globalVector.updateCandidateInfo(to.dirtyChainIDs, to.objCache)
@@ -1162,7 +1163,7 @@ func (to *totalOrdering) flushBlocks(
b *types.Block) (flushed []*types.Block, mode uint32, err error) {
mode = TotalOrderingModeFlush
- cfg := to.configs[to.curRound-to.configs[0].roundID]
+ cfg := to.getCurrentConfig()
if cfg.isLastBlock(b) {
to.flushReadyChains[b.Position.ChainID] = struct{}{}
}
@@ -1216,7 +1217,7 @@ func (to *totalOrdering) flushBlocks(
to.globalVector.cachedCandidateInfo = nil
to.switchRound()
// Force picking new candidates.
- numChains := to.configs[to.curRound-to.configs[0].roundID].numChains
+ numChains := to.getCurrentConfig().numChains
to.output(map[common.Hash]struct{}{}, numChains)
return
}
@@ -1226,7 +1227,7 @@ func (to *totalOrdering) deliverBlocks() (
delivered []*types.Block, mode uint32, err error) {
hashes, mode := to.generateDeliverSet()
- cfg := to.configs[to.curRound-to.configs[0].roundID]
+ cfg := to.getCurrentConfig()
// Output precedings.
delivered = to.output(hashes, cfg.numChains)
// Check if any block in delivered set is the last block in this round, if
@@ -1271,12 +1272,21 @@ func (to *totalOrdering) deliverBlocks() (
return
}
+func (to *totalOrdering) getCurrentConfig() *totalOrderingConfig {
+ cfgIdx := to.curRound - to.configs[0].roundID
+ if cfgIdx >= uint64(len(to.configs)) {
+ panic(fmt.Errorf("total ordering config is not ready: %v, %v, %v",
+ to.curRound, to.configs[0].roundID, len(to.configs)))
+ }
+ return to.configs[cfgIdx]
+}
+
// processBlock is the entry point of totalOrdering.
func (to *totalOrdering) processBlock(
b *types.Block) ([]*types.Block, uint32, error) {
// NOTE: Block b is assumed to be in topologically sorted, i.e., all its
// acking blocks are during or after total ordering stage.
- cfg := to.configs[to.curRound-to.configs[0].roundID]
+ cfg := to.getCurrentConfig()
to.pendings[b.Hash] = b
to.buildBlockRelation(b)
isOldest, err := to.updateVectors(b)