aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-28 18:21:00 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:59 +0800
commit3cb8ea02990fe36da2498f5df736e2eb1d0f43b2 (patch)
treebafe34fe0dc4424ee830801aa336289f03d26dff
parent08c893f4942ea84ed13ecdd6058bcf39585a4566 (diff)
downloaddexon-3cb8ea02990fe36da2498f5df736e2eb1d0f43b2.tar.gz
dexon-3cb8ea02990fe36da2498f5df736e2eb1d0f43b2.tar.zst
dexon-3cb8ea02990fe36da2498f5df736e2eb1d0f43b2.zip
dex: rebuild connection if dkg reset, core/vm: fix gov (#308)
* dex: rebuild connection if dkg reset * core: vm: fix governance contract
-rw-r--r--core/governance.go4
-rw-r--r--core/vm/oracle_contracts.go12
-rw-r--r--dex/handler.go13
-rw-r--r--dex/helper_test.go6
-rw-r--r--dex/protocol.go4
5 files changed, 37 insertions, 2 deletions
diff --git a/core/governance.go b/core/governance.go
index b39fdc3c6..d40432301 100644
--- a/core/governance.go
+++ b/core/governance.go
@@ -170,6 +170,10 @@ func (d *Governance) NodeSet(round uint64) []coreCrypto.PublicKey {
return pks
}
+func (d *Governance) PurgeNotarySet(round uint64) {
+ d.nodeSetCache.Purge(round)
+}
+
func (d *Governance) NotarySet(round uint64) (map[string]struct{}, error) {
notarySet, err := d.nodeSetCache.GetNotarySet(round)
if err != nil {
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index dc09df194..3da5e3335 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -2349,6 +2349,18 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
+ case "notaryParamAlpha":
+ res, err := method.Outputs.Pack(g.state.NotaryParamAlpha())
+ if err != nil {
+ return nil, errExecutionReverted
+ }
+ return res, nil
+ case "notaryParamBeta":
+ res, err := method.Outputs.Pack(g.state.NotaryParamBeta())
+ if err != nil {
+ return nil, errExecutionReverted
+ }
+ return res, nil
case "owner":
res, err := method.Outputs.Pack(g.state.Owner())
if err != nil {
diff --git a/dex/handler.go b/dex/handler.go
index 8971ad500..6d0746d2f 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -1320,6 +1320,7 @@ func (pm *ProtocolManager) peerSetLoop() {
pm.peers.BuildConnection(CRSRound)
round = CRSRound
}
+ resetCount := uint64(0)
for {
select {
@@ -1334,9 +1335,12 @@ func (pm *ProtocolManager) peerSetLoop() {
if newRound == 0 {
break
}
+ reset := pm.gov.DKGResetCount(round)
- log.Debug("ProtocolManager: new round", "round", newRound)
- if newRound <= round {
+ log.Debug("ProtocolManager: new round",
+ "round", newRound,
+ "reset", reset)
+ if newRound <= round && resetCount == reset {
break
}
@@ -1345,6 +1349,10 @@ func (pm *ProtocolManager) peerSetLoop() {
if round >= 1 {
pm.peers.ForgetConnection(round - 1)
}
+ } else if newRound == round && resetCount+1 == reset {
+ pm.peers.ForgetConnection(newRound)
+ pm.gov.PurgeNotarySet(newRound)
+ pm.peers.BuildConnection(newRound)
} else {
// just forget all network connection and rebuild.
pm.peers.ForgetConnection(round)
@@ -1355,6 +1363,7 @@ func (pm *ProtocolManager) peerSetLoop() {
pm.peers.BuildConnection(newRound)
}
round = newRound
+ resetCount = reset
case <-pm.chainHeadSub.Err():
return
}
diff --git a/dex/helper_test.go b/dex/helper_test.go
index 1d903a907..1d267d9ae 100644
--- a/dex/helper_test.go
+++ b/dex/helper_test.go
@@ -221,6 +221,12 @@ func (g *testGovernance) CRSRound() uint64 {
return g.lenCRSFunc()
}
+func (g *testGovernance) DKGResetCount(uint64) uint64 {
+ return 0
+}
+
+func (g *testGovernance) PurgeNotarySet(uint64) {}
+
func (g *testGovernance) NotarySet(
round uint64) (map[string]struct{}, error) {
return g.notarySetFunc(round)
diff --git a/dex/protocol.go b/dex/protocol.go
index 2bcb57506..4da64b604 100644
--- a/dex/protocol.go
+++ b/dex/protocol.go
@@ -156,6 +156,10 @@ type governance interface {
CRSRound() uint64
NotarySet(uint64) (map[string]struct{}, error)
+
+ PurgeNotarySet(uint64)
+
+ DKGResetCount(uint64) uint64
}
type dexconApp interface {