diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-10-13 16:21:51 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:39 +0800 |
commit | 2c808da2a4e8b7c4801efef67a5b4bb91e392357 (patch) | |
tree | 5b0ed7f4ac291c33f976266f270ad1c37e4cf76b /dex/governance.go | |
parent | e06704eba85a4c6136b024d636012259a3f9952a (diff) | |
download | go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar.gz go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar.bz2 go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar.lz go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar.xz go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.tar.zst go-tangerine-2c808da2a4e8b7c4801efef67a5b4bb91e392357.zip |
dex: bug fix to allow running geth without crashing
Diffstat (limited to 'dex/governance.go')
-rw-r--r-- | dex/governance.go | 82 |
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) } } |