aboutsummaryrefslogtreecommitdiffstats
path: root/dex/governance.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-10-13 16:21:51 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:49 +0800
commit902f6508b7655cee0231bc5bd2ade9261f79f6f1 (patch)
treed2eb99c1a0da59d5c56b559ac2ec8b839eda403a /dex/governance.go
parent66f5c9d6b502bdf49d9888f328e07e7d860bd3b4 (diff)
downloaddexon-902f6508b7655cee0231bc5bd2ade9261f79f6f1.tar.gz
dexon-902f6508b7655cee0231bc5bd2ade9261f79f6f1.tar.zst
dexon-902f6508b7655cee0231bc5bd2ade9261f79f6f1.zip
dex: bug fix to allow running geth without crashing
Diffstat (limited to 'dex/governance.go')
-rw-r--r--dex/governance.go82
1 files changed, 41 insertions, 41 deletions
diff --git a/dex/governance.go b/dex/governance.go
index 3f50ae408..369cc2f0c 100644
--- a/dex/governance.go
+++ b/dex/governance.go
@@ -92,6 +92,34 @@ func (d *DexconGovernance) Configuration(round uint64) *coreTypes.Config {
}
}
+func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error {
+ gasPrice, err := d.b.SuggestPrice(ctx)
+ if err != nil {
+ return err
+ }
+
+ nonce, err := d.b.GetPoolNonce(ctx, d.address)
+ if err != nil {
+ return err
+ }
+
+ tx := types.NewTransaction(
+ nonce,
+ vm.GovernanceContractAddress,
+ big.NewInt(0),
+ uint64(200000),
+ gasPrice,
+ data)
+
+ signer := types.NewEIP155Signer(d.chainConfig.ChainID)
+
+ tx, err = types.SignTx(tx, signer, d.privateKey)
+ if err != nil {
+ return err
+ }
+ return d.b.SendTx(ctx, tx)
+}
+
// CRS returns the CRS for a given round.
func (d *DexconGovernance) CRS(round uint64) coreCommon.Hash {
s := d.getGovStateAtRound(round)
@@ -104,14 +132,14 @@ func (d *DexconGovernance) ProposeCRS(signedCRS []byte) {
res, err := method.Inputs.Pack(signedCRS)
if err != nil {
- log.Error("failed to pack proposeCRS input: %s", err)
+ log.Error("failed to pack proposeCRS input", "err", err)
return
}
data := append(method.Id(), res...)
err = d.sendGovTx(context.Background(), data)
if err != nil {
- log.Error("failed to send proposeCRS tx: %s", err)
+ log.Error("failed to send proposeCRS tx", "err", err)
}
}
@@ -126,34 +154,6 @@ func (d *DexconGovernance) NodeSet(round uint64) []coreCrypto.PublicKey {
return pks
}
-func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error {
- gasPrice, err := d.b.SuggestPrice(ctx)
- if err != nil {
- return err
- }
-
- nonce, err := d.b.GetPoolNonce(ctx, d.address)
- if err != nil {
- return err
- }
-
- tx := types.NewTransaction(
- nonce,
- vm.GovernanceContractAddress,
- big.NewInt(0),
- uint64(200000),
- gasPrice,
- data)
-
- signer := types.NewEIP155Signer(d.chainConfig.ChainID)
-
- tx, err = types.SignTx(tx, signer, d.privateKey)
- if err != nil {
- return err
- }
- return d.b.SendTx(ctx, tx)
-}
-
// NotifyRoundHeight register the mapping between round and height.
func (d *DexconGovernance) NotifyRoundHeight(targetRound, consensusHeight uint64) {
method := vm.GovernanceContractName2Method["snapshotRound"]
@@ -161,14 +161,14 @@ func (d *DexconGovernance) NotifyRoundHeight(targetRound, consensusHeight uint64
res, err := method.Inputs.Pack(
big.NewInt(int64(targetRound)), big.NewInt(int64(consensusHeight)))
if err != nil {
- log.Error("failed to pack snapshotRound input: %s", err)
+ log.Error("failed to pack snapshotRound input", "err", err)
return
}
data := append(method.Id(), res...)
err = d.sendGovTx(context.Background(), data)
if err != nil {
- log.Error("failed to send snapshotRound tx: %s", err)
+ log.Error("failed to send snapshotRound tx", "err", err)
}
}
@@ -178,20 +178,20 @@ func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *coreTypes.DK
encoded, err := rlp.EncodeToBytes(complaint)
if err != nil {
- log.Error("failed to RLP encode complaint to bytes: %s", err)
+ log.Error("failed to RLP encode complaint to bytes", "err", err)
return
}
res, err := method.Inputs.Pack(big.NewInt(int64(round)), encoded)
if err != nil {
- log.Error("failed to pack addDKGComplaint input: %s", err)
+ log.Error("failed to pack addDKGComplaint input", "err", err)
return
}
data := append(method.Id(), res...)
err = d.sendGovTx(context.Background(), data)
if err != nil {
- log.Error("failed to send addDKGComplaint tx: %s", err)
+ log.Error("failed to send addDKGComplaint tx", "err", err)
}
}
@@ -215,20 +215,20 @@ func (d *DexconGovernance) AddDKGMasterPublicKey(round uint64, masterPublicKey *
encoded, err := rlp.EncodeToBytes(masterPublicKey)
if err != nil {
- log.Error("failed to RLP encode mpk to bytes: %s", err)
+ log.Error("failed to RLP encode mpk to bytes", "err", err)
return
}
res, err := method.Inputs.Pack(big.NewInt(int64(round)), encoded)
if err != nil {
- log.Error("failed to pack addDKGMasterPublicKey input: %s", err)
+ log.Error("failed to pack addDKGMasterPublicKey input", "err", err)
return
}
data := append(method.Id(), res...)
err = d.sendGovTx(context.Background(), data)
if err != nil {
- log.Error("failed to send addDKGMasterPublicKey tx: %s", err)
+ log.Error("failed to send addDKGMasterPublicKey tx", "err", err)
}
}
@@ -252,20 +252,20 @@ func (d *DexconGovernance) AddDKGFinalize(round uint64, final *coreTypes.DKGFina
encoded, err := rlp.EncodeToBytes(final)
if err != nil {
- log.Error("failed to RLP encode finalize to bytes: %s", err)
+ log.Error("failed to RLP encode finalize to bytes", "err", err)
return
}
res, err := method.Inputs.Pack(big.NewInt(int64(round)), encoded)
if err != nil {
- log.Error("failed to pack addDKGFinalize input: %s", err)
+ log.Error("failed to pack addDKGFinalize input", "err", err)
return
}
data := append(method.Id(), res...)
err = d.sendGovTx(context.Background(), data)
if err != nil {
- log.Error("failed to send addDKGFinalize tx: %s", err)
+ log.Error("failed to send addDKGFinalize tx", "err", err)
}
}