diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-11-02 16:01:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-02 16:01:35 +0800 |
commit | 5170bff5f5332fd7782f300cb4a1d63f3cd3664c (patch) | |
tree | c2c345bfc5553741e34165c8df13186ebb849084 | |
parent | bd5e5b4c79d990d65823b3630c0f76d21af9b52d (diff) | |
download | dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar.gz dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar.bz2 dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar.lz dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar.xz dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.tar.zst dexon-consensus-5170bff5f5332fd7782f300cb4a1d63f3cd3664c.zip |
core: block deliver with position (#289)
This info is required when application layer needs
to do something related to the underlying DAG, not
just compaction chain.
-rw-r--r-- | core/consensus.go | 2 | ||||
-rw-r--r-- | core/interfaces.go | 3 | ||||
-rw-r--r-- | core/lattice_test.go | 2 | ||||
-rw-r--r-- | core/nonblocking.go | 16 | ||||
-rw-r--r-- | core/nonblocking_test.go | 13 | ||||
-rw-r--r-- | core/test/app.go | 3 | ||||
-rw-r--r-- | core/test/app_test.go | 2 | ||||
-rw-r--r-- | core/test/stopper_test.go | 2 | ||||
-rw-r--r-- | integration_test/node.go | 2 | ||||
-rw-r--r-- | simulation/app.go | 2 |
10 files changed, 26 insertions, 21 deletions
diff --git a/core/consensus.go b/core/consensus.go index cec3c4f..0371e60 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -929,7 +929,7 @@ func (con *Consensus) preProcessBlock(b *types.Block) (err error) { func (con *Consensus) deliverBlock(b *types.Block) { // TODO(mission): clone types.FinalizationResult con.logger.Debug("Calling Application.BlockDelivered", "block", b) - con.app.BlockDelivered(b.Hash, b.Finalization) + con.app.BlockDelivered(b.Hash, b.Position, b.Finalization) if b.Position.Round+2 == con.roundToNotify { // Only the first block delivered of that round would // trigger this noitification. diff --git a/core/interfaces.go b/core/interfaces.go index 75a2fdf..3a9c075 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -42,7 +42,8 @@ type Application interface { BlockConfirmed(block types.Block) // BlockDelivered is called when a block is add to the compaction chain. - BlockDelivered(blockHash common.Hash, result types.FinalizationResult) + BlockDelivered(blockHash common.Hash, + blockPosition types.Position, result types.FinalizationResult) } // Debug describes the application interface that requires diff --git a/core/lattice_test.go b/core/lattice_test.go index ca3cfbb..b469565 100644 --- a/core/lattice_test.go +++ b/core/lattice_test.go @@ -80,7 +80,7 @@ func (mgr *testLatticeMgr) processBlock(b *types.Block) (err error) { if err = mgr.db.Update(*b); err != nil { return } - mgr.app.BlockDelivered(b.Hash, b.Finalization) + mgr.app.BlockDelivered(b.Hash, b.Position, b.Finalization) } if err = mgr.lattice.PurgeBlocks(delivered); err != nil { return diff --git a/core/nonblocking.go b/core/nonblocking.go index fafbd10..a73331f 100644 --- a/core/nonblocking.go +++ b/core/nonblocking.go @@ -39,8 +39,9 @@ type totalOrderingDeliveredEvent struct { } type blockDeliveredEvent struct { - blockHash common.Hash - result *types.FinalizationResult + blockHash common.Hash + blockPosition types.Position + result *types.FinalizationResult } // nonBlocking implements these interfaces and is a decorator for @@ -99,7 +100,7 @@ func (nb *nonBlocking) run() { case totalOrderingDeliveredEvent: nb.debug.TotalOrderingDelivered(e.blockHashes, e.mode) case blockDeliveredEvent: - nb.app.BlockDelivered(e.blockHash, *e.result) + nb.app.BlockDelivered(e.blockHash, e.blockPosition, *e.result) default: fmt.Printf("Unknown event %v.", e) } @@ -155,10 +156,11 @@ func (nb *nonBlocking) TotalOrderingDelivered( } // BlockDelivered is called when a block is add to the compaction chain. -func (nb *nonBlocking) BlockDelivered( - blockHash common.Hash, result types.FinalizationResult) { +func (nb *nonBlocking) BlockDelivered(blockHash common.Hash, + blockPosition types.Position, result types.FinalizationResult) { nb.addEvent(blockDeliveredEvent{ - blockHash: blockHash, - result: &result, + blockHash: blockHash, + blockPosition: blockPosition, + result: &result, }) } diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go index 3a4ec6c..d486ca2 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -75,8 +75,8 @@ func (app *slowApp) TotalOrderingDelivered(blockHashes common.Hashes, mode uint3 } } -func (app *slowApp) BlockDelivered( - blockHash common.Hash, _ types.FinalizationResult) { +func (app *slowApp) BlockDelivered(blockHash common.Hash, + blockPosition types.Position, _ types.FinalizationResult) { time.Sleep(app.sleep) app.blockDelivered[blockHash] = struct{}{} } @@ -111,8 +111,8 @@ func (app *noDebugApp) BlockConfirmed(block types.Block) { app.blockConfirmed[block.Hash] = struct{}{} } -func (app *noDebugApp) BlockDelivered( - blockHash common.Hash, _ types.FinalizationResult) { +func (app *noDebugApp) BlockDelivered(blockHash common.Hash, + blockPosition types.Position, _ types.FinalizationResult) { app.blockDelivered[blockHash] = struct{}{} } @@ -138,7 +138,8 @@ func (s *NonBlockingTestSuite) TestNonBlocking() { Witness: types.Witness{}, }) nbModule.StronglyAcked(hash) - nbModule.BlockDelivered(hash, types.FinalizationResult{}) + nbModule.BlockDelivered( + hash, types.Position{}, types.FinalizationResult{}) } nbModule.TotalOrderingDelivered(hashes, TotalOrderingModeEarly) @@ -161,7 +162,7 @@ func (s *NonBlockingTestSuite) TestNoDebug() { // Test BlockConfirmed. nbModule.BlockConfirmed(types.Block{Hash: hash}) // Test BlockDelivered - nbModule.BlockDelivered(hash, types.FinalizationResult{}) + nbModule.BlockDelivered(hash, types.Position{}, types.FinalizationResult{}) nbModule.wait() s.Contains(app.blockConfirmed, hash) s.Contains(app.blockDelivered, hash) diff --git a/core/test/app.go b/core/test/app.go index 228edb4..7477329 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -162,7 +162,7 @@ func (app *App) TotalOrderingDelivered(blockHashes common.Hashes, mode uint32) { // BlockDelivered implements Application interface. func (app *App) BlockDelivered( - blockHash common.Hash, result types.FinalizationResult) { + blockHash common.Hash, _ types.Position, result types.FinalizationResult) { func() { app.deliveredLock.Lock() defer app.deliveredLock.Unlock() @@ -220,6 +220,7 @@ func (app *App) Compare(other *App) error { // Verify checks the integrity of date received by this App instance. func (app *App) Verify() error { + // TODO(mission): verify blocks' position when delivered. app.deliveredLock.RLock() defer app.deliveredLock.RUnlock() diff --git a/core/test/app_test.go b/core/test/app_test.go index eb14039..4a7c4b9 100644 --- a/core/test/app_test.go +++ b/core/test/app_test.go @@ -82,7 +82,7 @@ func (s *AppTestSuite) deliverBlockWithTimeFromSequenceLength( func (s *AppTestSuite) deliverBlock( app *App, hash common.Hash, timestamp time.Time, height uint64) { - app.BlockDelivered(hash, types.FinalizationResult{ + app.BlockDelivered(hash, types.Position{}, types.FinalizationResult{ Timestamp: timestamp, Height: height, }) diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go index 3ba7db6..d823f59 100644 --- a/core/test/stopper_test.go +++ b/core/test/stopper_test.go @@ -44,7 +44,7 @@ func (s *StopperTestSuite) deliver( } app.TotalOrderingDelivered(hashes, core.TotalOrderingModeNormal) for _, h := range hashes { - app.BlockDelivered(h, types.FinalizationResult{ + app.BlockDelivered(h, types.Position{}, types.FinalizationResult{ Timestamp: time.Time{}, }) } diff --git a/integration_test/node.go b/integration_test/node.go index 0eb5345..ff58860 100644 --- a/integration_test/node.go +++ b/integration_test/node.go @@ -257,7 +257,7 @@ func (n *Node) processBlock(b *types.Block) (events []*test.Event, err error) { } b.Finalization.Height = n.prevFinalHeight + 1 b.Finalization.ParentHash = n.prevHash - n.appModule.BlockDelivered(b.Hash, b.Finalization) + n.appModule.BlockDelivered(b.Hash, b.Position, b.Finalization) n.prevFinalHeight++ n.prevHash = b.Hash events = append(events, n.checkRoundSwitch(b)...) diff --git a/simulation/app.go b/simulation/app.go index d544a59..89657a7 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -132,7 +132,7 @@ func (a *simApp) TotalOrderingDelivered( // BlockDelivered is called when a block in compaction chain is delivered. func (a *simApp) BlockDelivered( - blockHash common.Hash, result types.FinalizationResult) { + blockHash common.Hash, _ types.Position, result types.FinalizationResult) { if len(result.Randomness) == 0 && func() bool { if block, exist := a.blockByHash[blockHash]; exist { if block.Position.Round == 0 { |