diff options
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) + } } } } |