aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-28 11:21:48 +0800
committerGitHub <noreply@github.com>2018-08-28 11:21:48 +0800
commit9c8f9a447bfd768a7b29db904bd604410ec66a09 (patch)
tree76495e11738e24e4ff3f27d647509f29012eea6f /simulation
parente122cb236312e0ca3ef6e0207a20890ec1e7bfaf (diff)
downloadtangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.gz
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.bz2
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.lz
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.xz
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.tar.zst
tangerine-consensus-9c8f9a447bfd768a7b29db904bd604410ec66a09.zip
core: Add vote type and add field to block. (#76)
Diffstat (limited to 'simulation')
-rw-r--r--simulation/network.go1
-rw-r--r--simulation/tcp-network.go14
-rw-r--r--simulation/validator.go4
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)
+ }
}
}
}