Skip to content

Commit 94d8923

Browse files
authored
Merge pull request #188 from XinFinOrg/gerui-gasless
feat: Gasless
2 parents f4e45e4 + b8e72b4 commit 94d8923

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
11441144
}
11451145
if ctx.GlobalIsSet(GasPriceFlag.Name) {
11461146
cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name)
1147+
if len(cfg.GasPrice.Bits()) == 0 { //IsUint64() && cfg.GasPrice.Uint64() == 0 {
1148+
common.Gasless = true
1149+
log.Info("Gasless enabled. You can run transactions with zero gas fee.")
1150+
}
11471151
}
11481152
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
11491153
// TODO(fjl): force-enable this in --dev mode

common/gas.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import (
77
var MinGasPrice50x = big.NewInt(12500000000)
88
var GasPrice50x = big.NewInt(12500000000)
99

10+
var Gasless = false
11+
1012
func GetGasFee(blockNumber, gas uint64) *big.Int {
13+
if Gasless {
14+
return big.NewInt(0)
15+
}
1116
fee := new(big.Int).SetUint64(gas)
1217
if blockNumber >= uint64(10) { //temp fix trc21issuer test fail
1318
fee = fee.Mul(fee, GasPrice50x)
@@ -16,15 +21,21 @@ func GetGasFee(blockNumber, gas uint64) *big.Int {
1621
}
1722

1823
func GetGasPrice(number *big.Int) *big.Int {
24+
if Gasless {
25+
return big.NewInt(0)
26+
}
1927
if number == nil {
2028
return new(big.Int).Set(TRC21GasPrice)
2129
}
2230
return new(big.Int).Set(GasPrice50x)
2331
}
2432

2533
func GetMinGasPrice(number *big.Int) *big.Int {
34+
if Gasless {
35+
return big.NewInt(0)
36+
}
2637
if number == nil {
2738
return new(big.Int).Set(MinGasPrice)
2839
}
2940
return new(big.Int).Set(MinGasPrice50x)
30-
}
41+
}

core/tx_pool.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,9 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
664664

665665
// Check zero gas price.
666666
if tx.GasPrice().Cmp(new(big.Int).SetInt64(0)) == 0 {
667-
return ErrZeroGasPrice
667+
if !common.Gasless {
668+
return ErrZeroGasPrice
669+
}
668670
}
669671

670672
// under min gas price

eth/gasprice/gasprice.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
7575

7676
// SuggestPrice returns the recommended gas price.
7777
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
78+
if common.Gasless {
79+
return big.NewInt(0), nil
80+
}
7881
gpo.cacheLock.RLock()
7982
lastHead := gpo.lastHead
8083
lastPrice := gpo.lastPrice

0 commit comments

Comments
 (0)