aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go
index cf81a1161..0bbe8902a 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice-data.go
@@ -106,7 +106,7 @@ func newLatticeDataConfig(
// latticeData is a module for storing lattice.
type latticeData struct {
// DB for getting blocks purged in memory.
- db db.Reader
+ db db.Database
// chains stores chains' blocks and other info.
chains []*chainStatus
// blockByHash stores blocks, indexed by block hash.
@@ -119,7 +119,7 @@ type latticeData struct {
// newLatticeData creates a new latticeData instance.
func newLatticeData(
- db db.Reader,
+ db db.Database,
dMoment time.Time,
round uint64,
config *types.Config) (data *latticeData) {
@@ -291,21 +291,26 @@ func (data *latticeData) addBlock(
bAck *types.Block
updated bool
)
+ if err = data.db.PutBlock(*block); err != nil {
+ if err == db.ErrBlockExists {
+ // If a node is crashed and restarted, we might encounter some
+ // blocks that already confirmed but not delivered yet. Then
+ // syncer might still try to add that block in this way.
+ err = nil
+ } else {
+ return
+ }
+ }
data.chains[block.Position.ChainID].addBlock(block)
data.blockByHash[block.Hash] = block
// Update lastAckPos.
for _, ack := range block.Acks {
if bAck, err = data.findBlock(ack); err != nil {
- if err == db.ErrBlockDoesNotExist {
- err = nil
- continue
- }
return
}
data.chains[bAck.Position.ChainID].lastAckPos[block.Position.ChainID] =
bAck.Position.Clone()
}
-
// Extract deliverable blocks to total ordering. A block is deliverable to
// total ordering iff all its ackings blocks were delivered to total ordering.
for {
@@ -382,6 +387,19 @@ func (data *latticeData) addFinalizedBlock(block *types.Block) (err error) {
return
}
+func (data *latticeData) tipRound(chainID uint32) uint64 {
+ if tip := data.chains[chainID].tip; tip != nil {
+ tipConfig := data.getConfig(tip.Position.Round)
+ offset := uint64(0)
+ if tip.Timestamp.After(tipConfig.roundEndTime) {
+ offset++
+ }
+ return tip.Position.Round + offset
+ }
+ return uint64(0)
+
+}
+
// isBindTip checks if a block's fields should follow up its parent block.
func (data *latticeData) isBindTip(
pos types.Position, tip *types.Block) (bindTip bool, err error) {