Skip to content

Commit ab4ab29

Browse files
authored
Merge pull request #5 from node-real/netmarble_v2.0_dev
fix:fncy2 gpo.DefaultPrice causes the bug that suggestPrice is unreas…
2 parents 4bbc033 + b90fcd5 commit ab4ab29

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

core/tx_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
13161316
log.Warn("Failed to get gasPrice", "err", err)
13171317
} else {
13181318
if gasPrice != nil && gasPrice.Cmp(common.Big0) > 0 {
1319-
if pool.gasPrice.Cmp(gasPrice) != 0 {
1319+
if pool.gasPrice == nil || pool.gasPrice.Cmp(gasPrice) != 0 {
13201320
log.Debug("Set gasPrice ", " old gasPrice", pool.gasPrice, " new gasPrice", gasPrice)
13211321
pool.SetGasPriceWithoutLock(gasPrice)
13221322
}

eth/backend.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import (
6464
"github.com/ethereum/go-ethereum/rpc"
6565
)
6666

67+
var maxPrice = big.NewInt(1200000 * params.GWei)
68+
6769
// Config contains the configuration options of the ETH protocol.
6870
// Deprecated: use ethconfig.Config instead.
6971
type Config = ethconfig.Config
@@ -226,7 +228,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
226228
config.TxPool.Journal = stack.ResolvePath(config.TxPool.Journal)
227229
}
228230
//getCurrentGasPriceFunc
229-
eth.txPool = core.NewEnhanceTxPool(config.TxPool, chainConfig, eth.blockchain, getCurrentGasFreeAddressMapFunc(ethAPI), getCurrentGasPriceFunc(ethAPI))
231+
eth.txPool = core.NewEnhanceTxPool(config.TxPool, chainConfig, eth.blockchain, getCurrentGasFreeAddressMapFunc(ethAPI), getCurrentGasPriceFunc(eth, ethAPI))
230232

231233
// Permit the downloader to use the trie cache allowance during fast sync
232234
cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit + cacheConfig.SnapshotLimit
@@ -600,7 +602,7 @@ func (s *Ethereum) Stop() error {
600602

601603
return nil
602604
}
603-
func getCurrentGasPriceFunc(ee *ethapi.PublicBlockChainAPI) func(common.Hash) (*big.Int, error) {
605+
func getCurrentGasPriceFunc(eth *Ethereum, ee *ethapi.PublicBlockChainAPI) func(common.Hash) (*big.Int, error) {
604606
return func(blockHash common.Hash) (*big.Int, error) {
605607
// block
606608
blockNr := rpc.BlockNumberOrHashWithHash(blockHash, false)
@@ -631,11 +633,24 @@ func getCurrentGasPriceFunc(ee *ethapi.PublicBlockChainAPI) func(common.Hash) (*
631633
if err != nil {
632634
return nil, err
633635
}
634-
out := big.NewInt(0)
635-
if err := chainConfig.UnpackIntoInterface(&out, method, result); err != nil {
636+
gasPrice := big.NewInt(0)
637+
if err := chainConfig.UnpackIntoInterface(&gasPrice, method, result); err != nil {
636638
return nil, err
637639
}
638-
return out, nil
640+
if gasPrice != nil && eth.APIBackend.gpo != nil && gasPrice.Cmp(common.Big0) > 0 {
641+
if eth.APIBackend.gpo.GetDefaultPrice() == nil || eth.APIBackend.gpo.GetDefaultPrice().Cmp(gasPrice) != 0 {
642+
eth.APIBackend.gpo.SetDefaultPrice(gasPrice)
643+
}
644+
if eth.APIBackend.gpo.GetMaxPrice() == nil || eth.APIBackend.gpo.GetMaxPrice().Cmp(maxPrice) != 0 {
645+
eth.APIBackend.gpo.SetMaxPrice(maxPrice)
646+
}
647+
if eth.gasPrice == nil || eth.gasPrice.Cmp(gasPrice) != 0 {
648+
eth.lock.Lock()
649+
eth.gasPrice = gasPrice
650+
eth.lock.Unlock()
651+
}
652+
}
653+
return gasPrice, nil
639654
}
640655
}
641656

eth/gasprice/gasprice.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
9898
}
9999
}
100100

101+
func (gpo *Oracle) SetDefaultPrice(defaultPrice *big.Int) {
102+
gpo.defaultPrice = defaultPrice
103+
}
104+
func (gpo *Oracle) GetDefaultPrice() *big.Int {
105+
return gpo.defaultPrice
106+
}
107+
108+
func (gpo *Oracle) SetMaxPrice(maxPrice *big.Int) {
109+
gpo.maxPrice = maxPrice
110+
}
111+
func (gpo *Oracle) GetMaxPrice() *big.Int {
112+
return gpo.maxPrice
113+
}
114+
101115
// SuggestPrice returns a gasprice so that newly created transaction can
102116
// have a very high chance to be included in the following blocks.
103117
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {

0 commit comments

Comments
 (0)