From 0b283c9401d9ea8764ff86a81895816dc118eda1 Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Sat, 29 Aug 2020 15:48:44 +0800 Subject: [PATCH] add gas price to config --- config/config.go | 3 ++- config/config.json | 1 + executor/bsc_executor.go | 11 +++++------ executor/bsc_executor_test.go | 12 ++++++------ executor/const.go | 2 ++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index a8339e2..4e62285 100644 --- a/config/config.go +++ b/config/config.go @@ -90,6 +90,7 @@ type BSCConfig struct { PrivateKey string `json:"private_key"` Provider string `json:"provider"` GasLimit uint64 `json:"gas_limit"` + GasPrice uint64 `json:"gas_price"` MonitorDataSeedList []string `json:"monitor_data_seed_list"` } @@ -113,7 +114,7 @@ func (cfg *BSCConfig) Validate() { if cfg.KeyType != KeyTypeAWSPrivateKey && cfg.PrivateKey == "" { panic(fmt.Sprintf("privateKey of Binance Smart Chain should not be empty")) } - if cfg.GasLimit <= 0 { + if cfg.GasLimit == 0 { panic(fmt.Sprintf("gas_limit of Binance Smart Chain should be larger than 0")) } } diff --git a/config/config.json b/config/config.json index 7470c2d..4eb99b5 100644 --- a/config/config.json +++ b/config/config.json @@ -23,6 +23,7 @@ "private_key": "", "provider": "https://data-seed-prebsc-1-s1.binance.org:8545", "gas_limit": 4700000, + "gas_price": 20000000000, "monitor_data_seed_list": [] }, "log_config": { diff --git a/executor/bsc_executor.go b/executor/bsc_executor.go index e3f96fb..196abc5 100644 --- a/executor/bsc_executor.go +++ b/executor/bsc_executor.go @@ -95,16 +95,15 @@ func (executor *BSCExecutor) getTransactor() (*bind.TransactOpts, error) { return nil, err } - gasPrice, err := executor.bscClient.SuggestGasPrice(context.Background()) - if err != nil { - return nil, err - } - txOpts := bind.NewKeyedTransactor(executor.privateKey) txOpts.Nonce = big.NewInt(int64(nonce)) txOpts.Value = big.NewInt(0) txOpts.GasLimit = executor.bscConfig.GasLimit - txOpts.GasPrice = gasPrice + if executor.bscConfig.GasPrice == 0 { + txOpts.GasPrice = big.NewInt(DefaultGasPrice) + } else { + txOpts.GasPrice = big.NewInt(int64(executor.bscConfig.GasPrice)) + } return txOpts, nil } diff --git a/executor/bsc_executor_test.go b/executor/bsc_executor_test.go index 09a408f..4e3c06b 100644 --- a/executor/bsc_executor_test.go +++ b/executor/bsc_executor_test.go @@ -16,21 +16,21 @@ import ( ) const ( - BBCRpc = "http://dex-qa-s1-bsc-dev-validator-alb-501442930.ap-northeast-1.elb.amazonaws.com:27147" - provider = "http://dex-qa-s1-bsc-dev-validator-alb-501442930.ap-northeast-1.elb.amazonaws.com:8545" + BBCRpc = "tcp://seed-pre-s3.binance.org:80" + provider = "http://data-seed-prebsc-1-s1.binance.org:8545" privateKey = "EB19E69C9EBF9737FCB41AFFF5D6E3B3711E15579E5FA89F03DC4656EEC34E4D" ) var ( cfg = &config.Config{ - CrossChainConfig: &config.CrossChainConfig{ + CrossChainConfig: config.CrossChainConfig{ SourceChainID: 1, - DestChainID: 96, + DestChainID: 97, }, - BBCConfig: &config.BBCConfig{ + BBCConfig: config.BBCConfig{ RpcAddr: BBCRpc, }, - BSCConfig: &config.BSCConfig{ + BSCConfig: config.BSCConfig{ GasLimit: 4700000, Provider: provider, PrivateKey: privateKey, diff --git a/executor/const.go b/executor/const.go index 998739c..488afd7 100644 --- a/executor/const.go +++ b/executor/const.go @@ -21,6 +21,8 @@ const ( CrossChainPackageEventType = "IBCPackage" CorssChainPackageInfoAttributeKey = "IBCPackageInfo" CorssChainPackageInfoAttributeValue = "%d" + separator + "%d" + separator + "%d" // destChainID channelID sequence + + DefaultGasPrice = 20000000000 // 20 GWei ) var (