aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/application.go3
-rw-r--r--core/consensus.go8
-rw-r--r--core/test/app.go9
-rw-r--r--simulation/app.go24
-rw-r--r--simulation/validator.go2
5 files changed, 26 insertions, 20 deletions
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,
})
}
diff --git a/simulation/app.go b/simulation/app.go
index 797ab91..2d09f2a 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -37,7 +37,7 @@ type SimApp struct {
blockSeen map[common.Hash]time.Time
// uncofirmBlocks stores the blocks whose timestamps are not ready.
unconfirmedBlocks map[types.ValidatorID]common.Hashes
- blockHash map[common.Hash]*types.Block
+ blockByHash map[common.Hash]*types.Block
}
// NewSimApp returns point to a new instance of SimApp.
@@ -48,15 +48,19 @@ func NewSimApp(id types.ValidatorID, Network PeerServerNetwork) *SimApp {
DeliverID: 0,
blockSeen: make(map[common.Hash]time.Time),
unconfirmedBlocks: make(map[types.ValidatorID]common.Hashes),
- blockHash: make(map[common.Hash]*types.Block),
+ blockByHash: make(map[common.Hash]*types.Block),
}
}
+func (a *SimApp) addBlock(block *types.Block) {
+ a.blockByHash[block.Hash] = block
+}
+
// getAckedBlocks will return all unconfirmed blocks' hash with lower Height
// than the block with ackHash.
func (a *SimApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) {
// TODO(jimmy-dexon): Why there are some acks never seen?
- ackBlock, exist := a.blockHash[ackHash]
+ ackBlock, exist := a.blockByHash[ackHash]
if !exist {
return
}
@@ -65,7 +69,7 @@ func (a *SimApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) {
return
}
for i, blockHash := range hashes {
- if a.blockHash[blockHash].Height > ackBlock.Height {
+ if a.blockByHash[blockHash].Height > ackBlock.Height {
output, a.unconfirmedBlocks[ackBlock.ProposerID] = hashes[:i], hashes[i:]
break
}
@@ -84,24 +88,26 @@ func (a *SimApp) StronglyAcked(blockHash common.Hash) {
// TotalOrderingDeliver is called when blocks are delivered by the total
// ordering algorithm.
-func (a *SimApp) TotalOrderingDeliver(blocks []*types.Block, early bool) {
+func (a *SimApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
now := time.Now()
+ blocks := make([]*types.Block, len(blockHashes))
+ for idx := range blockHashes {
+ blocks[idx] = a.blockByHash[blockHashes[idx]]
+ }
a.Outputs = blocks
a.Early = early
fmt.Println("OUTPUT", a.ValidatorID, a.Early, a.Outputs)
- blockHash := common.Hashes{}
confirmLatency := []time.Duration{}
payload := []TimestampMessage{}
for _, block := range blocks {
- blockHash = append(blockHash, block.Hash)
if block.ProposerID == a.ValidatorID {
confirmLatency = append(confirmLatency,
now.Sub(block.Timestamps[a.ValidatorID]))
}
// TODO(jimmy-dexon) : Remove block in this hash if it's no longer needed.
- a.blockHash[block.Hash] = block
+ a.blockByHash[block.Hash] = block
for hash := range block.Acks {
for _, blockHash := range a.getAckedBlocks(hash) {
payload = append(payload, TimestampMessage{
@@ -128,7 +134,7 @@ func (a *SimApp) TotalOrderingDeliver(blocks []*types.Block, early bool) {
blockList := BlockList{
ID: a.DeliverID,
- BlockHash: blockHash,
+ BlockHash: blockHashes,
ConfirmLatency: confirmLatency,
}
a.Network.DeliverBlocks(blockList)
diff --git a/simulation/validator.go b/simulation/validator.go
index b4e6127..8b59247 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -128,6 +128,7 @@ func (v *Validator) MsgServer(isStopped chan struct{}) {
switch val := msg.(type) {
case *types.Block:
+ v.app.addBlock(val)
if v.consensus != nil {
if err := v.consensus.ProcessBlock(val); err != nil {
fmt.Println(err)
@@ -196,6 +197,7 @@ ProposingBlockLoop:
if err := v.consensus.PrepareBlock(block); err != nil {
panic(err)
}
+ v.app.addBlock(block)
if err := v.consensus.ProcessBlock(block); err != nil {
fmt.Println(err)
//panic(err)