From b88d8ddb0eaf48fac1fdf10dcd7db4dc896e6538 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Fri, 10 Aug 2018 13:40:57 +0800 Subject: core: Deliver only Hash to Application. (#43) --- core/application.go | 3 +-- core/consensus.go | 8 ++++++-- core/test/app.go | 9 ++------- 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/application.go b/core/application.go index 763954d..5bd325c 100644 --- a/core/application.go +++ b/core/application.go @@ -21,7 +21,6 @@ import ( "time" "github.com/dexon-foundation/dexon-consensus-core/common" - "github.com/dexon-foundation/dexon-consensus-core/core/types" ) // Application describes the application interface that interacts with DEXON @@ -31,7 +30,7 @@ type Application interface { StronglyAcked(blockHash common.Hash) // TotalOrderingDeliver is called when the total ordering algorithm deliver // a set of block. - TotalOrderingDeliver(blocks []*types.Block, early bool) + TotalOrderingDeliver(blockHashes common.Hashes, early bool) // DeliverBlock is called when a block is add to the compaction chain. DeliverBlock(blockHash common.Hash, timestamp time.Time) diff --git a/core/consensus.go b/core/consensus.go index 6a97e9e..33f2f8b 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -22,6 +22,7 @@ import ( "time" "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -101,8 +102,11 @@ func (con *Consensus) ProcessBlock(b *types.Block) (err error) { } } // TODO(mission): handle membership events here. - // TODO(mission): return block hash instead of whole block here. - con.app.TotalOrderingDeliver(deliveredBlocks, earlyDelivered) + hashes := make(common.Hashes, len(deliveredBlocks)) + for idx := range deliveredBlocks { + hashes[idx] = deliveredBlocks[idx].Hash + } + con.app.TotalOrderingDeliver(hashes, earlyDelivered) // Perform timestamp generation. deliveredBlocks, _, err = con.ctModule.processBlocks( deliveredBlocks) diff --git a/core/test/app.go b/core/test/app.go index f596afb..55ba7c5 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -21,7 +21,6 @@ import ( "time" "github.com/dexon-foundation/dexon-consensus-core/common" - "github.com/dexon-foundation/dexon-consensus-core/core/types" ) // App implements Application interface for testing purpose. @@ -52,16 +51,12 @@ func (app *App) StronglyAcked(blockHash common.Hash) { } // TotalOrderingDeliver implements Application interface. -func (app *App) TotalOrderingDeliver(blocks []*types.Block, early bool) { - var hashes common.Hashes - for _, b := range blocks { - hashes = append(hashes, b.Hash) - } +func (app *App) TotalOrderingDeliver(blockHashes common.Hashes, early bool) { app.TotalOrdered = append(app.TotalOrdered, &struct { BlockHashes common.Hashes Early bool }{ - BlockHashes: hashes, + BlockHashes: blockHashes, Early: early, }) } -- cgit v1.2.3