diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-25 14:10:16 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-09-25 14:10:16 +0800 |
commit | 6c8d26d2e797e8420fc3de4b15e4c556f968aba0 (patch) | |
tree | 22beecc01da7a9ce5cac36135a89010d6d4ed4f2 /core/consensus.go | |
parent | ca935bdbac190766f29fb73433a82ee5806bc8f9 (diff) | |
download | tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.gz tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.bz2 tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.lz tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.xz tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.zst tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.zip |
core: add debug (#133)
* Split interface
* Rename nonblocking-application to nonblocking
Parts needs nonblocking gets more.
* Implement core.nonBlocking based on interface split
* Fix: the witness parent hash could be parent on compaction chain.
* Rename Application.DeliverBlock to BlockDeliver
To sync with naming of other methods.
* Change methods' fingerprint
- BlockConfirmed provides block hash only.
- BlockDeliver provde a whole block.
Diffstat (limited to 'core/consensus.go')
-rw-r--r-- | core/consensus.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/core/consensus.go b/core/consensus.go index dc5bbba..1758507 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -172,7 +172,7 @@ func (recv *consensusDKGReceiver) ProposeDKGAntiNackComplaint( // Consensus implements DEXON Consensus algorithm. type Consensus struct { ID types.NodeID - app Application + nbModule *nonBlocking gov Governance config *types.Config baModules []*agreement @@ -239,13 +239,15 @@ func NewConsensus( len(gov.GetNotarySet())/3, sigToPub) + // Check if the application implement Debug interface. + debug, _ := app.(Debug) con := &Consensus{ ID: ID, rbModule: rb, toModule: to, ctModule: newConsensusTimestamp(), ccModule: newCompactionChain(db, sigToPub), - app: newNonBlockingApplication(app), + nbModule: newNonBlocking(app, debug), gov: gov, config: config, db: db, @@ -530,7 +532,7 @@ func (con *Consensus) ProcessVote(vote *types.Vote) (err error) { // processWitnessData process witness acks. func (con *Consensus) processWitnessData() { - ch := con.app.BlockProcessedChan() + ch := con.nbModule.BlockProcessedChan() for { select { @@ -541,14 +543,10 @@ func (con *Consensus) processWitnessData() { if err != nil { panic(err) } - - if err = con.ccModule.processWitnessResult(&block, result); err != nil { - panic(err) - } + block.Witness.Data = result.Data if err := con.db.Update(block); err != nil { panic(err) } - // TODO(w): move the acking interval into governance. if block.Witness.Height%5 != 0 { continue @@ -562,7 +560,7 @@ func (con *Consensus) processWitnessData() { if err != nil { panic(err) } - con.app.WitnessAckDeliver(witnessAck) + con.nbModule.WitnessAckDeliver(witnessAck) } } } @@ -625,10 +623,10 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { if err = con.rbModule.processBlock(b); err != nil { return err } - con.app.BlockConfirmed(block) + con.nbModule.BlockConfirmed(block.Hash) for _, b := range con.rbModule.extractBlocks() { // Notify application layer that some block is strongly acked. - con.app.StronglyAcked(b.Hash) + con.nbModule.StronglyAcked(b.Hash) // Perform total ordering. deliveredBlocks, earlyDelivered, err = con.toModule.processBlock(b) if err != nil { @@ -647,7 +645,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { for idx := range deliveredBlocks { hashes[idx] = deliveredBlocks[idx].Hash } - con.app.TotalOrderingDeliver(hashes, earlyDelivered) + con.nbModule.TotalOrderingDeliver(hashes, earlyDelivered) // Perform timestamp generation. err = con.ctModule.processBlocks(deliveredBlocks) if err != nil { @@ -660,10 +658,10 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { if err = con.db.Update(*b); err != nil { return } - con.app.DeliverBlock(b.Hash, b.Witness.Timestamp) + con.nbModule.BlockDeliver(*b) // TODO(mission): Find a way to safely recycle the block. // We should deliver block directly to - // nonBlockingApplication and let them recycle the + // nonBlocking and let them recycle the // block. } } @@ -690,7 +688,7 @@ func (con *Consensus) prepareBlock(b *types.Block, con.rbModule.prepareBlock(b) b.Timestamp = proposeTime - b.Payload = con.app.PreparePayload(b.Position) + b.Payload = con.nbModule.PreparePayload(b.Position) b.Hash, err = hashBlock(b) if err != nil { return |