aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--core/consensus.go3
-rw-r--r--core/lattice-data.go19
-rw-r--r--integration_test/node.go3
3 files changed, 12 insertions, 13 deletions
diff --git a/core/consensus.go b/core/consensus.go
index 2cef6bc..afc8973 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -1244,9 +1244,6 @@ func (con *Consensus) deliverFinalizedBlocksWithoutLock() (err error) {
// processBlock is the entry point to submit one block to a Consensus instance.
func (con *Consensus) processBlock(block *types.Block) (err error) {
- if err = con.db.PutBlock(*block); err != nil && err != db.ErrBlockExists {
- return
- }
con.lock.Lock()
defer con.lock.Unlock()
// Block processed by lattice can be out-of-order. But the output of lattice
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 {
diff --git a/integration_test/node.go b/integration_test/node.go
index c2bb806..c5109af 100644
--- a/integration_test/node.go
+++ b/integration_test/node.go
@@ -254,9 +254,6 @@ func (n *Node) processBlock(b *types.Block) (events []*test.Event, err error) {
}
// Deliver blocks.
for _, b = range delivered {
- if err = n.dbModule.PutBlock(*b); err != nil {
- panic(err)
- }
b.Finalization.Height = n.prevFinalHeight + 1
b.Finalization.ParentHash = n.prevHash
n.appModule.BlockDelivered(b.Hash, b.Position, b.Finalization)