diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-28 11:21:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-28 11:21:48 +0800 |
commit | 9c8f9a447bfd768a7b29db904bd604410ec66a09 (patch) | |
tree | 76495e11738e24e4ff3f27d647509f29012eea6f /simulation | |
parent | e122cb236312e0ca3ef6e0207a20890ec1e7bfaf (diff) | |
download | dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.gz dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.bz2 dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.lz dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.xz dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.zst dexon-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.zip |
core: Add vote type and add field to block. (#76)
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/network.go | 1 | ||||
-rw-r--r-- | simulation/tcp-network.go | 14 | ||||
-rw-r--r-- | simulation/validator.go | 4 |
3 files changed, 19 insertions, 0 deletions
diff --git a/simulation/network.go b/simulation/network.go index f08b638..687dd90 100644 --- a/simulation/network.go +++ b/simulation/network.go @@ -81,6 +81,7 @@ type Network interface { Join(endpoint Endpoint) chan interface{} BroadcastBlock(block *types.Block) BroadcastNotaryAck(notaryAck *types.NotaryAck) + BroadcastVote(vote *types.Vote) Endpoints() types.ValidatorIDs } diff --git a/simulation/tcp-network.go b/simulation/tcp-network.go index 2da9e3a..bb63bd1 100644 --- a/simulation/tcp-network.go +++ b/simulation/tcp-network.go @@ -257,6 +257,9 @@ func (n *TCPNetwork) Send(destID types.ValidatorID, msg interface{}) { case *types.NotaryAck: message.Type = "notaryAck" message.Payload = v + case *types.Vote: + message.Type = "vote" + message.Payload = v default: fmt.Println("error: invalid message type") return @@ -318,6 +321,17 @@ func (n *TCPNetwork) BroadcastNotaryAck(notaryAck *types.NotaryAck) { } } +// BroadcastVote broadcast vote into the network. +func (n *TCPNetwork) BroadcastVote(vote *types.Vote) { + vote = vote.Clone() + for endpoint := range n.endpoints { + if endpoint == vote.ProposerID { + continue + } + n.Send(endpoint, vote) + } +} + // 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 fb5f6cd..b26603a 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -159,6 +159,10 @@ func (v *Validator) MsgServer( if err := v.consensus.ProcessNotaryAck(val); err != nil { fmt.Println(err) } + case *types.Vote: + if err := v.consensus.ProcessVote(val); err != nil { + fmt.Println(err) + } } } } |