Skip to content

Commit

Permalink
feature(op-geth): add opbnb gasless solution (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
redhdx authored Aug 5, 2024
1 parent 0c45fd0 commit 7fd1790
Show file tree
Hide file tree
Showing 27 changed files with 1,700 additions and 28 deletions.
4 changes: 4 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var (
utils.TxPoolLifetimeFlag,
utils.TxPoolReannounceTimeFlag,
utils.TxPoolReannounceRemotesFlag,
utils.BundlePoolGlobalSlotsFlag,
utils.BlobPoolDataDirFlag,
utils.BlobPoolDataCapFlag,
utils.BlobPoolPriceBumpFlag,
Expand Down Expand Up @@ -135,6 +136,9 @@ var (
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNewPayloadTimeout,
utils.MevEnabledFlag,
utils.MevBundleReceiverUrlFlag,
utils.MevBundleGasPriceFloorFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
utils.DiscoveryV4Flag,
Expand Down
41 changes: 41 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/txpool/bundlepool"
"math"
"math/big"
"net"
Expand Down Expand Up @@ -440,6 +441,13 @@ var (
Value: ethconfig.Defaults.TxPool.ReannounceRemotes,
Category: flags.TxPoolCategory,
}
// bundle pool settings
BundlePoolGlobalSlotsFlag = &cli.Uint64Flag{
Name: "bundlepool.globalslots",
Usage: "Maximum number of executable bundle slots for all accounts",
Value: ethconfig.Defaults.BundlePool.GlobalSlots,
Category: flags.BundlePoolCategory,
}
// Blob transaction pool settings
BlobPoolDataDirFlag = &cli.StringFlag{
Name: "blobpool.datadir",
Expand Down Expand Up @@ -558,6 +566,22 @@ var (
Value: ethconfig.Defaults.Miner.NewPayloadTimeout,
Category: flags.MinerCategory,
}
MevEnabledFlag = &cli.BoolFlag{
Name: "mev.enable",
Usage: "Enable mev",
Category: flags.MEVCategory,
}
MevBundleReceiverUrlFlag = &cli.StringFlag{
Name: "mev.bundle.receiver.url",
Usage: "Url of bundle receiver endpoint to use. Multiple urls are supported, separated by commas",
Category: flags.MEVCategory,
}
MevBundleGasPriceFloorFlag = &cli.Int64Flag{
Name: "mev.bundle.gasprice.floor",
Usage: "Minimum bundle gas price for mev",
Value: ethconfig.Defaults.Miner.Mev.MevBundleGasPriceFloor,
Category: flags.MEVCategory,
}

// Account settings
UnlockedAccountFlag = &cli.StringFlag{
Expand Down Expand Up @@ -1699,6 +1723,12 @@ func setTxPool(ctx *cli.Context, cfg *legacypool.Config) {
}
}

func setBundlePool(ctx *cli.Context, cfg *bundlepool.Config) {
if ctx.IsSet(BundlePoolGlobalSlotsFlag.Name) {
cfg.GlobalSlots = ctx.Uint64(BundlePoolGlobalSlotsFlag.Name)
}
}

func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.IsSet(MinerExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.String(MinerExtraDataFlag.Name))
Expand All @@ -1718,6 +1748,16 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.IsSet(RollupComputePendingBlock.Name) {
cfg.RollupComputePendingBlock = ctx.Bool(RollupComputePendingBlock.Name)
}
if ctx.IsSet(MevEnabledFlag.Name) {
cfg.Mev.MevEnabled = ctx.Bool(MevEnabledFlag.Name)
}
if ctx.IsSet(MevBundleReceiverUrlFlag.Name) {
url := ctx.String(MevBundleReceiverUrlFlag.Name)
cfg.Mev.MevReceivers = strings.Split(url, ",")
}
if ctx.IsSet(MevBundleGasPriceFloorFlag.Name) {
cfg.Mev.MevBundleGasPriceFloor = ctx.Int64(MevBundleGasPriceFloorFlag.Name)
}
}

func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down Expand Up @@ -1799,6 +1839,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool)
setBundlePool(ctx, &cfg.BundlePool)
setMiner(ctx, &cfg.Miner)
setRequiredBlocks(ctx, cfg)
setLes(ctx, cfg)
Expand Down
3 changes: 3 additions & 0 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
// CalcBaseFee calculates the basefee of the header.
// The time belongs to the new block to check if Canyon is activted or not
func CalcBaseFee(config *params.ChainConfig, parent *types.Header, time uint64) *big.Int {
if config.IsWright(time) {
return new(big.Int).SetUint64(params.OpBNBBaseFeeForGasLess)
}
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return new(big.Int).SetUint64(params.InitialBaseFee)
Expand Down
16 changes: 13 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ func (st *StateTransition) buyGas() error {
mgval = mgval.Mul(mgval, st.msg.GasPrice)
var l1Cost *big.Int
if st.evm.Context.L1CostFunc != nil && !st.msg.SkipAccountChecks {
l1Cost = st.evm.Context.L1CostFunc(st.msg.RollupCostData, st.evm.Context.Time)
if st.msg.GasPrice.Cmp(big.NewInt(0)) == 0 && st.evm.ChainConfig().IsWright(st.evm.Context.Time) {
l1Cost = big.NewInt(0)
} else {
l1Cost = st.evm.Context.L1CostFunc(st.msg.RollupCostData, st.evm.Context.Time)
}
if l1Cost != nil {
mgval = mgval.Add(mgval, l1Cost)
}
Expand Down Expand Up @@ -546,8 +550,14 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) {
// Note optimismConfig will not be nil if rules.IsOptimismBedrock is true
if optimismConfig := st.evm.ChainConfig().Optimism; optimismConfig != nil && rules.IsOptimismBedrock && !st.msg.IsDepositTx {
st.state.AddBalance(params.OptimismBaseFeeRecipient, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee))
if cost := st.evm.Context.L1CostFunc(st.msg.RollupCostData, st.evm.Context.Time); cost != nil {
st.state.AddBalance(params.OptimismL1FeeRecipient, cost)
var l1Cost *big.Int
if st.msg.GasPrice.Cmp(big.NewInt(0)) == 0 && st.evm.ChainConfig().IsWright(st.evm.Context.Time) {
l1Cost = big.NewInt(0)
} else {
l1Cost = st.evm.Context.L1CostFunc(st.msg.RollupCostData, st.evm.Context.Time)
}
if l1Cost != nil {
st.state.AddBalance(params.OptimismL1FeeRecipient, l1Cost)
}
}

Expand Down
Loading

0 comments on commit 7fd1790

Please sign in to comment.