From 2c808da2a4e8b7c4801efef67a5b4bb91e392357 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Sat, 13 Oct 2018 16:21:51 +0800 Subject: dex: bug fix to allow running geth without crashing --- dex/governance.go | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'dex/governance.go') 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) } } -- cgit v1.2.3