OSDN Git Service

get maxTxFee by config (#1292)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Fri, 31 Aug 2018 06:01:46 +0000 (14:01 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 31 Aug 2018 06:01:46 +0000 (14:01 +0800)
* add tx fee max limit

* optimise

* get maxTxFee by config

* move tx_fee to wallet

* optimise

blockchain/txbuilder/finalize.go
config/config.go
node/node.go

index 9344c85..3aaa7cb 100644 (file)
@@ -4,6 +4,7 @@ import (
        "bytes"
        "context"
 
+       cfg "github.com/bytom/config"
        "github.com/bytom/consensus"
        "github.com/bytom/errors"
        "github.com/bytom/protocol"
@@ -28,9 +29,7 @@ var (
 // assembles a fully signed tx, and stores the effects of
 // its changes on the UTXO set.
 func FinalizeTx(ctx context.Context, c *protocol.Chain, tx *types.Tx) error {
-       // maxTxFee means max transaction fee, maxTxFee = 0.4BTM * 25 = 10BTM
-       maxTxFee := consensus.MaxGasAmount * consensus.VMGasRate * 25
-       if fee := calculateTxFee(tx); fee > uint64(maxTxFee) {
+       if fee := calculateTxFee(tx); fee > cfg.CommonConfig.Wallet.MaxTxFee {
                return ErrExtTxFee
        }
 
index 199f0e0..2bae894 100644 (file)
@@ -8,6 +8,11 @@ import (
        "time"
 )
 
+var (
+       // CommonConfig means config object
+       CommonConfig *Config
+)
+
 type Config struct {
        // Top level options use an anonymous struct
        BaseConfig `mapstructure:",squash"`
@@ -152,8 +157,9 @@ func (p *P2PConfig) AddrBookFile() string {
 
 //-----------------------------------------------------------------------------
 type WalletConfig struct {
-       Disable bool `mapstructure:"disable"`
-       Rescan  bool `mapstructure:"rescan"`
+       Disable  bool   `mapstructure:"disable"`
+       Rescan   bool   `mapstructure:"rescan"`
+       MaxTxFee uint64 `mapstructure:"max_tx_fee"`
 }
 
 type RPCAuthConfig struct {
@@ -185,8 +191,9 @@ func DefaultWebConfig() *WebConfig {
 // Default configurable wallet parameters.
 func DefaultWalletConfig() *WalletConfig {
        return &WalletConfig{
-               Disable: false,
-               Rescan:  false,
+               Disable:  false,
+               Rescan:   false,
+               MaxTxFee: uint64(1000000000),
        }
 }
 
index 2c85351..dab4cd6 100644 (file)
@@ -65,6 +65,8 @@ func NewNode(config *cfg.Config) *Node {
        }
        initLogFile(config)
        initActiveNetParams(config)
+       initCommonConfig(config)
+
        // Get store
        coreDB := dbm.NewDB("core", config.DBBackend, config.DBDir())
        store := leveldb.NewStore(coreDB)
@@ -205,6 +207,10 @@ func initLogFile(config *cfg.Config) {
 
 }
 
+func initCommonConfig(config *cfg.Config) {
+       cfg.CommonConfig = config
+}
+
 // Lanch web broser or not
 func launchWebBrowser(port string) {
        webAddress := webHost + ":" + port