aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-09-20 16:08:08 +0800
committerGitHub <noreply@github.com>2018-09-20 16:08:08 +0800
commita4b6b9e6a28a4d8fc49ee76c191454a819265713 (patch)
tree716e5724b182b8dccb01a49faec4c163f1fafdb0 /simulation
parent2f1e71d9d298d1f6ade8d17a1db7a657b0223872 (diff)
downloaddexon-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 'simulation')
-rw-r--r--simulation/app.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 9c5619a..d00cf19 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -40,6 +40,7 @@ type simApp struct {
unconfirmedBlocks map[types.NodeID]common.Hashes
blockByHash map[common.Hash]*types.Block
blockByHashMutex sync.RWMutex
+ witnessResultChan chan types.WitnessResult
}
// newSimApp returns point to a new instance of simApp.
@@ -51,6 +52,7 @@ func newSimApp(id types.NodeID, netModule *network) *simApp {
blockSeen: make(map[common.Hash]time.Time),
unconfirmedBlocks: make(map[types.NodeID]common.Hashes),
blockByHash: make(map[common.Hash]*types.Block),
+ witnessResultChan: make(chan types.WitnessResult),
}
}
@@ -193,6 +195,19 @@ func (a *simApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
Payload: jsonPayload,
}
a.netModule.report(msg)
+
+ go func() {
+ a.witnessResultChan <- types.WitnessResult{
+ BlockHash: blockHash,
+ Data: []byte(fmt.Sprintf("Block %s", blockHash)),
+ }
+ }()
+}
+
+// BlockProcessedChan returns a channel to receive the block hashes that have
+// finished processing by the application.
+func (a *simApp) BlockProcessedChan() <-chan types.WitnessResult {
+ return a.witnessResultChan
}
// WitnessAckDeliver is called when a witness ack is created.