aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-11 19:33:25 +0800
committerGitHub <noreply@github.com>2018-10-11 19:33:25 +0800
commit490fa1e9ce2b661e4c8b612bd53f20123346353b (patch)
tree2ef4a4fabb1e21d46ef3e47538dadfeecdf2cf4d /simulation
parentf3e9eb613c7e8dec6b8c6b1b0a20ddbec4e91a9c (diff)
downloaddexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar.gz
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar.bz2
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar.lz
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar.xz
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.tar.zst
dexon-consensus-490fa1e9ce2b661e4c8b612bd53f20123346353b.zip
core: change interface (#193)
* Extract types.FinalizationResult * Change interface: - Application.BlockConfirmed returns whole block. - Application.BlockDelivered returns partial result.
Diffstat (limited to 'simulation')
-rw-r--r--simulation/app.go31
1 files changed, 15 insertions, 16 deletions
diff --git a/simulation/app.go b/simulation/app.go
index e88f956..0e3e184 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -58,7 +58,12 @@ func newSimApp(id types.NodeID, netModule *network) *simApp {
}
// BlockConfirmed implements core.Application.
-func (a *simApp) BlockConfirmed(_ common.Hash) {
+func (a *simApp) BlockConfirmed(block types.Block) {
+ a.blockByHashMutex.Lock()
+ defer a.blockByHashMutex.Unlock()
+
+ // TODO(jimmy-dexon) : Remove block in this hash if it's no longer needed.
+ a.blockByHash[block.Hash] = &block
}
// VerifyBlock implements core.Application.
@@ -125,40 +130,34 @@ func (a *simApp) TotalOrderingDelivered(blockHashes common.Hashes, early bool) {
}
// BlockDelivered is called when a block in compaction chain is delivered.
-func (a *simApp) BlockDelivered(block types.Block) {
- if len(block.Randomness) == 0 {
- panic(fmt.Errorf("Block %s randomness is empty", block.Hash))
+func (a *simApp) BlockDelivered(
+ blockHash common.Hash, result types.FinalizationResult) {
+ if len(result.Randomness) == 0 {
+ panic(fmt.Errorf("Block %s randomness is empty", blockHash))
}
func() {
- a.blockByHashMutex.Lock()
- defer a.blockByHashMutex.Unlock()
-
- // TODO(jimmy-dexon) : Remove block in this hash if it's no longer needed.
- a.blockByHash[block.Hash] = &block
- }()
- func() {
a.latestWitnessReady.L.Lock()
defer a.latestWitnessReady.L.Unlock()
a.latestWitness = types.Witness{
- Timestamp: block.ConsensusTimestamp,
- Height: block.ConsensusHeight,
+ Timestamp: result.Timestamp,
+ Height: result.Height,
}
a.latestWitnessReady.Broadcast()
}()
- seenTime, exist := a.blockSeen[block.Hash]
+ seenTime, exist := a.blockSeen[blockHash]
if !exist {
return
}
now := time.Now()
payload := []timestampMessage{
{
- BlockHash: block.Hash,
+ BlockHash: blockHash,
Event: blockSeen,
Timestamp: seenTime,
},
{
- BlockHash: block.Hash,
+ BlockHash: blockHash,
Event: timestampConfirm,
Timestamp: now,
},