diff options
-rw-r--r-- | core/genesis.go | 8 | ||||
-rw-r--r-- | core/vm/governance.go | 2 | ||||
-rw-r--r-- | dex/backend.go | 9 | ||||
-rw-r--r-- | dex/config.go | 4 | ||||
-rw-r--r-- | dex/governance.go | 82 |
5 files changed, 51 insertions, 54 deletions
diff --git a/core/genesis.go b/core/genesis.go index 149241cf5..043a9f428 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -32,7 +32,6 @@ import ( "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/core/vm" - "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" @@ -248,13 +247,6 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { // Stake in governance state. if account.Staked.Cmp(big.NewInt(0)) > 0 { - pk, err := crypto.DecompressPubkey(account.PublicKey) - if err != nil { - panic(err) - } - if crypto.PubkeyToAddress(*pk) != addr { - panic(fmt.Errorf("public key does not belones to %s", addr)) - } govStateHelper.Stake(addr, account.PublicKey, account.Staked) } } diff --git a/core/vm/governance.go b/core/vm/governance.go index 5bbb5a1ec..0cca0f409 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -1041,7 +1041,7 @@ func (s *GovernanceStateHelper) Node(index *big.Int) *nodeInfo { loc = new(big.Int).Add(elementBaseLoc, big.NewInt(2)) node.Staked = s.getStateBigInt(loc) - return nil + return node } func (s *GovernanceStateHelper) PushNode(n *nodeInfo) { // increase length by 1 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(¶ms.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 7e33ae05f..a3b682de0 100644 --- a/dex/config.go +++ b/dex/config.go @@ -29,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. @@ -47,7 +48,7 @@ var DefaultConfig = Config{ Blocks: 20, Percentile: 60, }, - + DefaultGasPrice: big.NewInt(params.GWei), GasFloor: 8000000, GasCeil: 8000000, GasLimitTolerance: 1000000, @@ -96,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) } } |