aboutsummaryrefslogtreecommitdiffstats
path: root/dex/handler.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-12-27 09:17:28 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:55 +0800
commitf79d09a12c8de2e1572292ef6bbd82352526930d (patch)
tree0ec9ce7fba237187b6d5b88b9401ad36798f7fe1 /dex/handler.go
parent509c6899caad7a66f7e64a1ef9718daa9018f7f1 (diff)
downloaddexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar.gz
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar.bz2
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar.lz
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar.xz
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.tar.zst
dexon-f79d09a12c8de2e1572292ef6bbd82352526930d.zip
dex: add pull randomness (#105)
* vendor: sync to latest core * dex: Add PullRandomness
Diffstat (limited to 'dex/handler.go')
-rw-r--r--dex/handler.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/dex/handler.go b/dex/handler.go
index ff87884d2..8a60c2a56 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -891,6 +891,21 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
return err
}
}
+ case msg.Code == PullRandomnessMsg:
+ if !pm.isBlockProposer {
+ break
+ }
+ var hashes coreCommon.Hashes
+ if err := msg.Decode(&hashes); err != nil {
+ return errResp(ErrDecode, "msg %v: %v", msg, err)
+ }
+ randomness := pm.cache.randomness(hashes)
+ log.Debug("Push randomness", "randomness", randomness)
+ for _, randomness := range randomness {
+ if err := p.SendRandomness(randomness); err != nil {
+ return err
+ }
+ }
case msg.Code == GetGovStateMsg:
var hash common.Hash
if err := msg.Decode(&hash); err != nil {
@@ -1029,6 +1044,7 @@ func (pm *ProtocolManager) BroadcastAgreementResult(
func (pm *ProtocolManager) BroadcastRandomnessResult(
randomness *coreTypes.BlockRandomnessResult) {
+ pm.cache.addRandomness(randomness)
// send to notary nodes first (direct)
label := peerLabel{
set: notaryset,
@@ -1109,6 +1125,17 @@ func (pm *ProtocolManager) BroadcastPullVotes(
}
}
+func (pm *ProtocolManager) BroadcastPullRandomness(
+ hashes coreCommon.Hashes) {
+ // TODO(jimmy-dexon): pull from dkg set only.
+ for idx, peer := range pm.peers.Peers() {
+ if idx >= maxPullPeers {
+ break
+ }
+ peer.AsyncSendPullRandomness(hashes)
+ }
+}
+
func (pm *ProtocolManager) txBroadcastLoop() {
queueSizeMax := common.StorageSize(100 * 1024) // 100 KB
currentSize := common.StorageSize(0)