Skip to content

Commit

Permalink
Merge pull request #188 from XinFinOrg/gerui-gasless
Browse files Browse the repository at this point in the history
feat: Gasless
  • Loading branch information
wanwiset25 authored Nov 27, 2024
2 parents f4e45e4 + b8e72b4 commit 94d8923
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
}
if ctx.GlobalIsSet(GasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name)
if len(cfg.GasPrice.Bits()) == 0 { //IsUint64() && cfg.GasPrice.Uint64() == 0 {
common.Gasless = true
log.Info("Gasless enabled. You can run transactions with zero gas fee.")
}
}
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
// TODO(fjl): force-enable this in --dev mode
Expand Down
13 changes: 12 additions & 1 deletion common/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
var MinGasPrice50x = big.NewInt(12500000000)
var GasPrice50x = big.NewInt(12500000000)

var Gasless = false

func GetGasFee(blockNumber, gas uint64) *big.Int {
if Gasless {
return big.NewInt(0)
}
fee := new(big.Int).SetUint64(gas)
if blockNumber >= uint64(10) { //temp fix trc21issuer test fail
fee = fee.Mul(fee, GasPrice50x)
Expand All @@ -16,15 +21,21 @@ func GetGasFee(blockNumber, gas uint64) *big.Int {
}

func GetGasPrice(number *big.Int) *big.Int {
if Gasless {
return big.NewInt(0)
}
if number == nil {
return new(big.Int).Set(TRC21GasPrice)
}
return new(big.Int).Set(GasPrice50x)
}

func GetMinGasPrice(number *big.Int) *big.Int {
if Gasless {
return big.NewInt(0)
}
if number == nil {
return new(big.Int).Set(MinGasPrice)
}
return new(big.Int).Set(MinGasPrice50x)
}
}
4 changes: 3 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {

// Check zero gas price.
if tx.GasPrice().Cmp(new(big.Int).SetInt64(0)) == 0 {
return ErrZeroGasPrice
if !common.Gasless {
return ErrZeroGasPrice
}
}

// under min gas price
Expand Down
3 changes: 3 additions & 0 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {

// SuggestPrice returns the recommended gas price.
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
if common.Gasless {
return big.NewInt(0), nil
}
gpo.cacheLock.RLock()
lastHead := gpo.lastHead
lastPrice := gpo.lastPrice
Expand Down

0 comments on commit 94d8923

Please sign in to comment.