Skip to content

Commit

Permalink
Merge pull request bnb-chain#7 from Ankr-network/zero-gas
Browse files Browse the repository at this point in the history
Gas free transactions
  • Loading branch information
dmitry123 authored May 10, 2022
2 parents 12c9651 + 7bf7232 commit 052a3b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ var (
Usage: "Duration for announcing local pending transactions again (default = 10 years, minimum = 1 minute)",
Value: ethconfig.Defaults.TxPool.ReannounceTime,
}
TxPoolGasFreeContracts = cli.DurationFlag{
Name: "txpool.gasfreecontracts",
Usage: "Comma delimited list of the gas free smart contracts",
}
// Performance tuning settings
CacheFlag = cli.IntFlag{
Name: "cache",
Expand Down Expand Up @@ -1327,6 +1331,16 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
if ctx.GlobalIsSet(TxPoolReannounceTimeFlag.Name) {
cfg.ReannounceTime = ctx.GlobalDuration(TxPoolReannounceTimeFlag.Name)
}
if ctx.GlobalIsSet(TxPoolGasFreeContracts.Name) {
cfg.GasFreeContracts = make(map[common.Address]bool)
for _, rawAddress := range ctx.GlobalStringSlice(TxPoolGasFreeContracts.Name) {
address := common.HexToAddress(rawAddress)
if address == (common.Address{}) {
Fatalf("Unable to parse address for the [%s], failed on address (%s)", TxPoolGasFreeContracts.Name, rawAddress)
}
cfg.GasFreeContracts[address] = true
}
}
}

func setMiner(ctx *cli.Context, cfg *miner.Config) {
Expand Down
5 changes: 4 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ type TxPoolConfig struct {

Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
ReannounceTime time.Duration // Duration for announcing local pending transactions again

GasFreeContracts map[common.Address]bool
}

// DefaultTxPoolConfig contains the default configurations for the transaction
Expand Down Expand Up @@ -592,7 +594,8 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInvalidSender
}
// Drop non-local transactions under our own minimal accepted gas price
if !local && tx.GasPriceIntCmp(pool.gasPrice) < 0 {
isGasFree := pool.config.GasFreeContracts != nil && pool.config.GasFreeContracts[*tx.To()]
if !local && tx.GasPriceIntCmp(pool.gasPrice) < 0 && !isGasFree {
return ErrUnderpriced
}
// Ensure the transaction adheres to nonce ordering
Expand Down
2 changes: 1 addition & 1 deletion genesis

0 comments on commit 052a3b8

Please sign in to comment.