aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-04 14:56:00 +0800
committerGitHub <noreply@github.com>2018-10-04 14:56:00 +0800
commit149e918f4fc78632483bf549dd8f5ffe55366e18 (patch)
treefeabcb67103d76cc829ea81a1d57735e71db23d8 /simulation
parent519cc8a734a510f44463b8dd175b7505f0308a22 (diff)
downloaddexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.gz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.bz2
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.lz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.xz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.zst
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.zip
core: Check Witness height. Add ConsensusTime and ConsensusHeight to block. (#170)
Diffstat (limited to 'simulation')
-rw-r--r--simulation/app.go46
1 files changed, 34 insertions, 12 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 5f1a85a..a46f3a6 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -37,20 +37,23 @@ type simApp struct {
// blockSeen stores the time when block is delivered by Total Ordering.
blockSeen map[common.Hash]time.Time
// uncofirmBlocks stores the blocks whose timestamps are not ready.
- unconfirmedBlocks map[types.NodeID]common.Hashes
- blockByHash map[common.Hash]*types.Block
- blockByHashMutex sync.RWMutex
+ unconfirmedBlocks map[types.NodeID]common.Hashes
+ blockByHash map[common.Hash]*types.Block
+ blockByHashMutex sync.RWMutex
+ latestWitness types.Witness
+ latestWitnessReady *sync.Cond
}
// newSimApp returns point to a new instance of simApp.
func newSimApp(id types.NodeID, netModule *network) *simApp {
return &simApp{
- NodeID: id,
- netModule: netModule,
- DeliverID: 0,
- blockSeen: make(map[common.Hash]time.Time),
- unconfirmedBlocks: make(map[types.NodeID]common.Hashes),
- blockByHash: make(map[common.Hash]*types.Block),
+ NodeID: id,
+ netModule: netModule,
+ DeliverID: 0,
+ blockSeen: make(map[common.Hash]time.Time),
+ unconfirmedBlocks: make(map[types.NodeID]common.Hashes),
+ blockByHash: make(map[common.Hash]*types.Block),
+ latestWitnessReady: sync.NewCond(&sync.Mutex{}),
}
}
@@ -89,9 +92,19 @@ func (a *simApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) {
return
}
-// PrepareBlock implements core.Application.
-func (a *simApp) PrepareBlock(position types.Position) ([]byte, []byte) {
- return []byte{}, []byte{}
+// PreparePayload implements core.Application.
+func (a *simApp) PreparePayload(position types.Position) []byte {
+ return []byte{}
+}
+
+// PrepareWitness implements core.Application.
+func (a *simApp) PrepareWitness(height uint64) types.Witness {
+ a.latestWitnessReady.L.Lock()
+ defer a.latestWitnessReady.L.Unlock()
+ for a.latestWitness.Height < height {
+ a.latestWitnessReady.Wait()
+ }
+ return a.latestWitness
}
// StronglyAcked is called when a block is strongly acked by DEXON
@@ -120,6 +133,15 @@ func (a *simApp) BlockDelivered(block types.Block) {
// 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,
+ }
+ a.latestWitnessReady.Broadcast()
+ }()
seenTime, exist := a.blockSeen[block.Hash]
if !exist {