aboutsummaryrefslogtreecommitdiffstats
path: root/core/lattice-data.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-01-21 17:51:26 +0800
committerGitHub <noreply@github.com>2019-01-21 17:51:26 +0800
commitca43bd9f99deead21dae71a749297dc6aa361898 (patch)
treefba6074ba79f2b037b467f2f23a440e4fe764089 /core/lattice-data.go
parentcaa9ad362b4d57bba8551be4074c86f820b7881c (diff)
downloaddexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar.gz
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar.bz2
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar.lz
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar.xz
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.tar.zst
dexon-consensus-ca43bd9f99deead21dae71a749297dc6aa361898.zip
core: fix issue (#427)
* Dropped block should not be added to db - Here "dropped" means a block is older than current tip of that chain. * "Acking blocks doesn't exist" should be treated as an error when adding a block
Diffstat (limited to 'core/lattice-data.go')
-rw-r--r--core/lattice-data.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/core/lattice-data.go b/core/lattice-data.go
index cf81a11..b9ad699 100644
--- a/core/lattice-data.go
+++ b/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 {