diff options
-rw-r--r-- | core/consensus.go | 3 | ||||
-rw-r--r-- | core/lattice-data.go | 19 | ||||
-rw-r--r-- | integration_test/node.go | 3 |
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) |