diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-30 17:21:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 17:21:58 +0800 |
commit | 96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8 (patch) | |
tree | 418e2c43acf4f9c13289eaccf66f94ef46c9356b /simulation | |
parent | a4e0da981a3dfc8817d39be65cb5b24938b0761a (diff) | |
download | dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar.gz dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar.bz2 dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar.lz dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar.xz dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.tar.zst dexon-consensus-96554a3bc14030e5d0dfc9dc1ee6bcdd9a133fa8.zip |
core: Add PreparePayloads to Application and Remove blockConverter interface. (#84)
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/app.go | 5 | ||||
-rw-r--r-- | simulation/network.go | 7 | ||||
-rw-r--r-- | simulation/tcp-network.go | 6 | ||||
-rw-r--r-- | simulation/validator.go | 5 |
4 files changed, 16 insertions, 7 deletions
diff --git a/simulation/app.go b/simulation/app.go index 635b071..78e1d9a 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -88,6 +88,11 @@ func (a *simApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) { return } +// PreparePayloads implements core.Application. +func (a *simApp) PreparePayloads(shardID, chainID, height uint64) [][]byte { + return [][]byte{} +} + // StronglyAcked is called when a block is strongly acked by DEXON // Reliabe Broadcast algorithm. func (a *simApp) StronglyAcked(blockHash common.Hash) { diff --git a/simulation/network.go b/simulation/network.go index 687dd90..791790c 100644 --- a/simulation/network.go +++ b/simulation/network.go @@ -22,6 +22,7 @@ import ( "time" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -76,12 +77,10 @@ type Endpoint interface { // Network is the interface for network related functions. type Network interface { PeerServerNetwork + core.Network Start() NumPeers() int - Join(endpoint Endpoint) chan interface{} - BroadcastBlock(block *types.Block) - BroadcastNotaryAck(notaryAck *types.NotaryAck) - BroadcastVote(vote *types.Vote) + Join(endpoint Endpoint) Endpoints() types.ValidatorIDs } diff --git a/simulation/tcp-network.go b/simulation/tcp-network.go index f30284b..31c8d95 100644 --- a/simulation/tcp-network.go +++ b/simulation/tcp-network.go @@ -176,7 +176,7 @@ func (n *TCPNetwork) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Join allow a client to join the network. It reutnrs a interface{} channel for // the client to recieve information. -func (n *TCPNetwork) Join(endpoint Endpoint) chan interface{} { +func (n *TCPNetwork) Join(endpoint Endpoint) { n.endpointMutex.Lock() defer n.endpointMutex.Unlock() @@ -235,6 +235,10 @@ func (n *TCPNetwork) Join(endpoint Endpoint) chan interface{} { for key, val := range peerList { n.endpoints[key] = val } +} + +// ReceiveChan return the receive channel. +func (n *TCPNetwork) ReceiveChan() <-chan interface{} { return n.recieveChan } diff --git a/simulation/validator.go b/simulation/validator.go index 302f3af..8a672c5 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -38,7 +38,7 @@ type Validator struct { db blockdb.BlockDatabase config config.Validator - msgChannel chan interface{} + msgChannel <-chan interface{} isFinished chan struct{} ID types.ValidatorID @@ -84,7 +84,8 @@ func (v *Validator) GetID() types.ValidatorID { // Run starts the validator. func (v *Validator) Run() { - v.msgChannel = v.network.Join(v) + v.network.Join(v) + v.msgChannel = v.network.ReceiveChan() hashes := make(common.Hashes, 0, v.network.NumPeers()) for _, vID := range v.network.Endpoints() { |