diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-09-20 16:08:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 16:08:08 +0800 |
commit | a4b6b9e6a28a4d8fc49ee76c191454a819265713 (patch) | |
tree | 716e5724b182b8dccb01a49faec4c163f1fafdb0 /core/test | |
parent | 2f1e71d9d298d1f6ade8d17a1db7a657b0223872 (diff) | |
download | dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar.gz dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar.bz2 dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar.lz dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar.xz dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.tar.zst dexon-consensus-a4b6b9e6a28a4d8fc49ee76c191454a819265713.zip |
core: refactor witness data processing flow (#124)
Since witness data need to include data from application after it
processed a block (e.g. stateRoot). We should make the process of
witness data asynchronous.
An interface `BlockProcessedChan()` is added to the application
interface to return a channel for notifying the consensus core when a
block is processed. The notification object includes a byte slice
(witenss data) which will be include in the final witness data object.
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/app.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/core/test/app.go b/core/test/app.go index e9ef871..617bc38 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -89,6 +89,7 @@ type App struct { deliveredLock sync.RWMutex WitnessAckSequence []*types.WitnessAck witnessAckLock sync.RWMutex + witnessResultChan chan types.WitnessResult } // NewApp constructs a TestApp instance. @@ -99,6 +100,7 @@ func NewApp() *App { TotalOrderedByHash: make(map[common.Hash]*AppTotalOrderRecord), Delivered: make(map[common.Hash]*AppDeliveredRecord), DeliverSequence: common.Hashes{}, + witnessResultChan: make(chan types.WitnessResult), } } @@ -155,6 +157,12 @@ func (app *App) DeliverBlock(blockHash common.Hash, timestamp time.Time) { app.DeliverSequence = append(app.DeliverSequence, blockHash) } +// BlockProcessedChan returns a channel to receive the block hashes that have +// finished processing by the application. +func (app *App) BlockProcessedChan() <-chan types.WitnessResult { + return app.witnessResultChan +} + // WitnessAckDeliver implements Application interface. func (app *App) WitnessAckDeliver(witnessAck *types.WitnessAck) { app.witnessAckLock.Lock() |