feat: Add Support for Zero Fee Addresses (#53)

* feat: adds zero-fee addresses

* feat: uses command line flag for zerofeeaddress

* chore: cleanup

* chore: remove comment
This commit is contained in:
Kartik Chopra 2024-11-25 13:49:58 -05:00 committed by GitHub
parent a9bcf58160
commit dd8d982cac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 6 deletions

View file

@ -497,6 +497,12 @@ var (
Category: flags.VMCategory, Category: flags.VMCategory,
} }
ZeroFeeAddressesFlag = &cli.StringFlag{
Name: "zeroofeeaddresses",
Usage: "Comma separated list of addresses that are allowed to send transactions with zero fees",
Value: "",
Category: flags.VMCategory,
}
// API options. // API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{ RPCGlobalGasCapFlag = &cli.Uint64Flag{
Name: "rpc.gascap", Name: "rpc.gascap",
@ -2119,8 +2125,14 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheGCFlag.Name) { if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheGCFlag.Name) {
cache.TrieDirtyLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheGCFlag.Name) / 100 cache.TrieDirtyLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheGCFlag.Name) / 100
} }
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
if ctx.IsSet(ZeroFeeAddressesFlag.Name) {
addressStrings := strings.Split(ctx.String(ZeroFeeAddressesFlag.Name), ",")
for _, addr := range addressStrings {
vmcfg.ZeroFeeAddresses = append(vmcfg.ZeroFeeAddresses, common.HexToAddress(strings.TrimSpace(addr)))
}
}
// Disable transaction indexing/unindexing by default. // Disable transaction indexing/unindexing by default.
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil) chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
if err != nil { if err != nil {

View file

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"math" "math"
"math/big" "math/big"
"slices"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math" cmath "github.com/ethereum/go-ethereum/common/math"
@ -464,7 +465,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// Send both base and prio fee to preconf.eth address // Send both base and prio fee to preconf.eth address
treasuryAccount := common.HexToAddress("0xfA0B0f5d298d28EFE4d35641724141ef19C05684") treasuryAccount := common.HexToAddress("0xfA0B0f5d298d28EFE4d35641724141ef19C05684")
bothFees := baseFee.Add(baseFee, priorityFee) bothFees := baseFee.Add(baseFee, priorityFee)
st.state.AddBalance(treasuryAccount, bothFees)
if slices.Contains(st.evm.Config.ZeroFeeAddresses, sender.Address()) {
st.state.AddBalance(sender.Address(), bothFees)
} else {
st.state.AddBalance(treasuryAccount, bothFees)
}
} }
return &ExecutionResult{ return &ExecutionResult{

View file

@ -35,10 +35,11 @@ const (
// Config are the configuration options for the Interpreter // Config are the configuration options for the Interpreter
type Config struct { type Config struct {
Tracer EVMLogger // Opcode logger Tracer EVMLogger // Opcode logger
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls) NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled ExtraEips []int // Additional EIPS that are to be enabled
ZeroFeeAddresses []common.Address // Addresses that are allowed to send transactions with zero fees
} }
// ScopeContext contains the things that are per-call, such as stack and memory, // ScopeContext contains the things that are per-call, such as stack and memory,