diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-22 11:33:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-22 11:33:39 +0800 |
commit | 89a65a152ae7956bcf6d241eb15d66e6d955b819 (patch) | |
tree | ec157eab266cf3dd76a94cfdbe90d35a08a2e492 /simulation | |
parent | 2c816b5d636b8f7decd234582470a3d4c6b4a93a (diff) | |
download | dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.gz dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.bz2 dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.lz dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.xz dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.zst dexon-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.zip |
core: Notary ack application. (#70)
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/fake-network.go | 10 | ||||
-rw-r--r-- | simulation/network.go | 1 | ||||
-rw-r--r-- | simulation/tcp-network.go | 14 | ||||
-rw-r--r-- | simulation/validator.go | 4 |
4 files changed, 29 insertions, 0 deletions
diff --git a/simulation/fake-network.go b/simulation/fake-network.go index 99c504a..fc8764a 100644 --- a/simulation/fake-network.go +++ b/simulation/fake-network.go @@ -93,6 +93,16 @@ func (n *FakeNetwork) BroadcastBlock(block *types.Block) { } } +// BroadcastNotaryAck broadcast notaryAck into the network. +func (n *FakeNetwork) BroadcastNotaryAck(notaryAck *types.NotaryAck) { + n.endpointMutex.Lock() + defer n.endpointMutex.Unlock() + + for endpoint := range n.endpoints { + n.Send(endpoint, notaryAck) + } +} + // DeliverBlocks sends blocks to peerServer. func (n *FakeNetwork) DeliverBlocks(blocks BlockList) { // TODO(jimmy-dexon): Implement this method. diff --git a/simulation/network.go b/simulation/network.go index 672a664..f08b638 100644 --- a/simulation/network.go +++ b/simulation/network.go @@ -80,6 +80,7 @@ type Network interface { NumPeers() int Join(endpoint Endpoint) chan interface{} BroadcastBlock(block *types.Block) + BroadcastNotaryAck(notaryAck *types.NotaryAck) Endpoints() types.ValidatorIDs } diff --git a/simulation/tcp-network.go b/simulation/tcp-network.go index c606daf..2da9e3a 100644 --- a/simulation/tcp-network.go +++ b/simulation/tcp-network.go @@ -254,6 +254,9 @@ func (n *TCPNetwork) Send(destID types.ValidatorID, msg interface{}) { case *types.Block: message.Type = "block" message.Payload = v + case *types.NotaryAck: + message.Type = "notaryAck" + message.Payload = v default: fmt.Println("error: invalid message type") return @@ -304,6 +307,17 @@ func (n *TCPNetwork) BroadcastBlock(block *types.Block) { } } +// BroadcastNotaryAck broadcast notaryAck into the network. +func (n *TCPNetwork) BroadcastNotaryAck(notaryAck *types.NotaryAck) { + notaryAck = notaryAck.Clone() + for endpoint := range n.endpoints { + if endpoint == notaryAck.ProposerID { + continue + } + n.Send(endpoint, notaryAck) + } +} + // DeliverBlocks sends blocks to peerServer. func (n *TCPNetwork) DeliverBlocks(blocks BlockList) { messageJSON, err := json.Marshal(blocks) diff --git a/simulation/validator.go b/simulation/validator.go index 1912bf6..fb5f6cd 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -155,6 +155,10 @@ func (v *Validator) MsgServer( fmt.Println(err) //panic(err) } + case *types.NotaryAck: + if err := v.consensus.ProcessNotaryAck(val); err != nil { + fmt.Println(err) + } } } } |