diff options
author | haoping-ku <haoping.ku@dexon.org> | 2018-12-05 17:38:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-05 17:38:03 +0800 |
commit | 4eb02f1dd96e136b0f7cf7eff792da1e44176713 (patch) | |
tree | 3757739bff31ce4b9cb7ff45be572f9858fc19e9 /core | |
parent | 1f48b590f6e9a6d3fd773846a3d8ba1b7f0419e6 (diff) | |
download | dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.gz dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.bz2 dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.lz dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.xz dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.zst dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.zip |
Haoping fix simulation (#356)
* simulation: add benchmark features
* tmp
* simulation: modify Debug interface
* Added BlockReceived and BlockReady function to Debug interface.
* Added Benchmark features.
* fix
* fix typos
Diffstat (limited to 'core')
-rw-r--r-- | core/consensus.go | 21 | ||||
-rw-r--r-- | core/interfaces.go | 6 | ||||
-rw-r--r-- | core/nonblocking_test.go | 4 | ||||
-rw-r--r-- | core/test/app.go | 6 |
4 files changed, 31 insertions, 6 deletions
diff --git a/core/consensus.go b/core/consensus.go index bfe893c..6ca54e0 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -340,10 +340,11 @@ type Consensus struct { toSyncer *totalOrderingSyncer // Interfaces. - db blockdb.BlockDatabase - app Application - gov Governance - network Network + db blockdb.BlockDatabase + app Application + debugApp Debug + gov Governance + network Network // Misc. dMoment time.Time @@ -372,7 +373,10 @@ func NewConsensus( // Setup auth module. authModule := NewAuthenticator(prv) // Check if the application implement Debug interface. - debugApp, _ := app.(Debug) + var debugApp Debug + if a, ok := app.(Debug); ok { + debugApp = a + } // Get configuration for genesis round. var round uint64 logger.Debug("Calling Governance.Configuration", "round", round) @@ -407,6 +411,7 @@ func NewConsensus( ccModule: newCompactionChain(gov), lattice: lattice, app: newNonBlocking(app, debugApp), + debugApp: debugApp, gov: gov, db: db, network: network, @@ -961,6 +966,9 @@ func (con *Consensus) ProcessBlockRandomnessResult( // preProcessBlock performs Byzantine Agreement on the block. func (con *Consensus) preProcessBlock(b *types.Block) (err error) { err = con.baMgr.processBlock(b) + if err == nil && con.debugApp != nil { + con.debugApp.BlockReceived(b.Hash) + } return } @@ -1027,6 +1035,9 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { } con.cfgModule.untouchTSigHash(b.Hash) con.deliverBlock(b) + if con.debugApp != nil { + con.debugApp.BlockReady(b.Hash) + } } if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil { return diff --git a/core/interfaces.go b/core/interfaces.go index 6979854..2ebfe86 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -41,7 +41,7 @@ type Application interface { // BlockConfirmed is called when a block is confirmed and added to lattice. BlockConfirmed(block types.Block) - // BlockDelivered is called when a block is add to the compaction chain. + // BlockDelivered is called when a block is added to the compaction chain. BlockDelivered(blockHash common.Hash, blockPosition types.Position, result types.FinalizationResult) } @@ -49,9 +49,13 @@ type Application interface { // Debug describes the application interface that requires // more detailed consensus execution. type Debug interface { + // BlockReceived is called when the block received in agreement. + BlockReceived(common.Hash) // TotalOrderingDelivered is called when the total ordering algorithm deliver // a set of block. TotalOrderingDelivered(common.Hashes, uint32) + // BlockReady is called when the block's randomness is ready. + BlockReady(common.Hash) } // Network describs the network interface that interacts with DEXON consensus diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go index cec1d8d..542382c 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -74,6 +74,10 @@ func (app *slowApp) BlockDelivered(blockHash common.Hash, app.blockDelivered[blockHash] = struct{}{} } +func (app *slowApp) BlockReceived(hash common.Hash) {} + +func (app *slowApp) BlockReady(hash common.Hash) {} + // noDebugApp is to make sure nonBlocking works when Debug interface // is not implemented by the provided Application instance. type noDebugApp struct { diff --git a/core/test/app.go b/core/test/app.go index 9f030e9..d26784e 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -280,6 +280,12 @@ Loop: return nil } +// BlockReceived implements interface Debug. +func (app *App) BlockReceived(hash common.Hash) {} + +// BlockReady implements interface Debug. +func (app *App) BlockReady(hash common.Hash) {} + // WithLock provides a backdoor to check status of App with reader lock. func (app *App) WithLock(function func(*App)) { app.confirmedLock.RLock() |