aboutsummaryrefslogtreecommitdiffstats
path: root/dex
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-03-12 12:19:09 +0800
commit5539dc25cee34d9018d789deed68c3b1ae8f3d47 (patch)
tree046c4c8ef89c9f393afa96e9a1e23b053b86b527 /dex
parent40b1f02b48cd275b878e9c4308c4373f2c6329e2 (diff)
downloaddexon-5539dc25cee34d9018d789deed68c3b1ae8f3d47.tar.gz
dexon-5539dc25cee34d9018d789deed68c3b1ae8f3d47.tar.zst
dexon-5539dc25cee34d9018d789deed68c3b1ae8f3d47.zip
dex: bug fix to allow running geth without crashing
Diffstat (limited to 'dex')
-rw-r--r--dex/backend.go9
-rw-r--r--dex/config.go5
-rw-r--r--dex/governance.go82
3 files changed, 51 insertions, 45 deletions
diff --git a/dex/backend.go b/dex/backend.go
index 2b4db94c4..d01ab8040 100644
--- a/dex/backend.go
+++ b/dex/backend.go
@@ -108,11 +108,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
}
dex := &Dexon{
config: config,
+ chainDb: chainDb,
+ chainConfig: chainConfig,
eventMux: ctx.EventMux,
accountManager: ctx.AccountManager,
shutdownChan: make(chan bool),
networkID: config.NetworkId,
bloomRequests: make(chan chan *bloombits.Retrieval),
+ bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
network: network,
blockdb: db,
engine: dexcon.New(&params.DexconConfig{}),
@@ -143,9 +146,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
dex.APIBackend = &DexAPIBackend{dex, nil}
gpoParams := config.GPO
- //if gpoParams.Default == nil {
- // gpoParams.Default = config.MinerGasPrice
- //}
+ if gpoParams.Default == nil {
+ gpoParams.Default = config.DefaultGasPrice
+ }
dex.APIBackend.gpo = gasprice.NewOracle(dex.APIBackend, gpoParams)
dex.governance = NewDexconGovernance(dex.APIBackend, dex.chainConfig, config.PrivateKey)
diff --git a/dex/config.go b/dex/config.go
index 3afbf5db1..507ccf5e3 100644
--- a/dex/config.go
+++ b/dex/config.go
@@ -18,6 +18,7 @@ package dex
import (
"crypto/ecdsa"
+ "math/big"
"os"
"os/user"
"path/filepath"
@@ -28,6 +29,7 @@ import (
"github.com/dexon-foundation/dexon/core"
"github.com/dexon-foundation/dexon/dex/gasprice"
"github.com/dexon-foundation/dexon/eth/downloader"
+ "github.com/dexon-foundation/dexon/params"
)
// DefaultConfig contains default settings for use on the Ethereum main net.
@@ -46,7 +48,7 @@ var DefaultConfig = Config{
Blocks: 20,
Percentile: 60,
},
-
+ DefaultGasPrice: big.NewInt(params.GWei),
GasFloor: 8000000,
GasCeil: 8000000,
GasLimitTolerance: 1000000,
@@ -95,6 +97,7 @@ type Config struct {
TrieTimeout time.Duration
// For calculate gas limit
+ DefaultGasPrice *big.Int
GasFloor uint64
GasCeil uint64
GasLimitTolerance uint64
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)
}
}