diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-12-27 09:17:28 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:20 +0800 |
commit | f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5 (patch) | |
tree | 286b5ef24b81a4fc595988cfbc2d850a7b272ab4 /dex/peer.go | |
parent | e0f7ce1279a832240576e52f2417e82e3d4fc8eb (diff) | |
download | go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar.gz go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar.bz2 go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar.lz go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar.xz go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.tar.zst go-tangerine-f0405c6a1decc41a878708b0f80e4b6fd6ebbcd5.zip |
dex: add pull randomness (#105)
* vendor: sync to latest core
* dex: Add PullRandomness
Diffstat (limited to 'dex/peer.go')
-rw-r--r-- | dex/peer.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/dex/peer.go b/dex/peer.go index 49a9b64f8..aecf9dc7c 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -100,6 +100,7 @@ const ( maxQueuedDKGParitialSignature = 16 maxQueuedPullBlocks = 128 maxQueuedPullVotes = 128 + maxQueuedPullRandomness = 128 handshakeTimeout = 5 * time.Second @@ -160,6 +161,7 @@ type peer struct { queuedDKGPartialSignatures chan *dkgTypes.PartialSignature queuedPullBlocks chan coreCommon.Hashes queuedPullVotes chan coreTypes.Position + queuedPullRandomness chan coreCommon.Hashes term chan struct{} // Termination channel to stop the broadcaster } @@ -190,6 +192,7 @@ func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { queuedDKGPartialSignatures: make(chan *dkgTypes.PartialSignature, maxQueuedDKGParitialSignature), queuedPullBlocks: make(chan coreCommon.Hashes, maxQueuedPullBlocks), queuedPullVotes: make(chan coreTypes.Position, maxQueuedPullVotes), + queuedPullRandomness: make(chan coreCommon.Hashes, maxQueuedPullRandomness), term: make(chan struct{}), } } @@ -257,6 +260,11 @@ func (p *peer) broadcast() { return } p.Log().Trace("Pulling Votes", "position", pos) + case hashes := <-p.queuedPullRandomness: + if err := p.SendPullRandomness(hashes); err != nil { + return + } + p.Log().Trace("Pulling Randomness", "hashes", hashes) case <-p.term: return case <-time.After(100 * time.Millisecond): @@ -530,6 +538,18 @@ func (p *peer) AsyncSendPullVotes(pos coreTypes.Position) { } } +func (p *peer) SendPullRandomness(hashes coreCommon.Hashes) error { + return p2p.Send(p.rw, PullRandomnessMsg, hashes) +} + +func (p *peer) AsyncSendPullRandomness(hashes coreCommon.Hashes) { + select { + case p.queuedPullRandomness <- hashes: + default: + p.Log().Debug("Dropping Pull Randomness") + } +} + // SendBlockHeaders sends a batch of block headers to the remote peer. func (p *peer) SendBlockHeaders(headers []*types.HeaderWithGovState) error { return p2p.Send(p.rw, BlockHeadersMsg, headers) |