Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support priority processing claim tx #29

Merged
merged 27 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ var (
commitEvery time.Duration

// For X Layer
enableWhiteList bool
whiteList []string
blockList []string
enableWhiteList bool
whiteList []string
blockList []string
freeClaimGasAddr []string
gasPriceMultiple uint64
)

func init() {
Expand All @@ -83,6 +85,9 @@ func init() {
rootCmd.PersistentFlags().Uint64Var(&priceBump, "txpool.pricebump", txpoolcfg.DefaultConfig.PriceBump, "Price bump percentage to replace an already existing transaction")
rootCmd.PersistentFlags().DurationVar(&commitEvery, utils.TxPoolCommitEveryFlag.Name, utils.TxPoolCommitEveryFlag.Value, utils.TxPoolCommitEveryFlag.Usage)
rootCmd.Flags().StringSliceVar(&traceSenders, utils.TxPoolTraceSendersFlag.Name, []string{}, utils.TxPoolTraceSendersFlag.Usage)
// For X Layer
rootCmd.Flags().StringSliceVar(&freeClaimGasAddr, utils.TxPoolPackBatchSpecialList.Name, []string{"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}, utils.TxPoolPackBatchSpecialList.Usage)
rootCmd.Flags().Uint64Var(&gasPriceMultiple, utils.TxPoolGasPriceMultiple.Name, 2, utils.TxPoolGasPriceMultiple.Usage)
rootCmd.Flags().BoolVar(&enableWhiteList, utils.TxPoolEnableWhitelistFlag.Name, false, utils.TxPoolEnableWhitelistFlag.Usage)
rootCmd.Flags().StringSliceVar(&whiteList, utils.TxPoolWhiteList.Name, []string{}, utils.TxPoolWhiteList.Usage)
rootCmd.Flags().StringSliceVar(&blockList, utils.TxPoolBlockedList.Name, []string{}, utils.TxPoolBlockedList.Usage)
Expand Down Expand Up @@ -176,6 +181,15 @@ func doTxpool(ctx context.Context) error {
addr := common.HexToAddress(addrHex)
ethCfg.DeprecatedTxPool.BlockedList[i] = addr.String()
}
ethCfg.DeprecatedTxPool.FreeClaimGasAddr = make([]string, len(freeClaimGasAddr))
for i, addrHex := range freeClaimGasAddr {
addr := common.HexToAddress(addrHex)
ethCfg.DeprecatedTxPool.FreeClaimGasAddr[i] = addr.String()
chengzhinei marked this conversation as resolved.
Show resolved Hide resolved
}
if len(ethCfg.DeprecatedTxPool.FreeClaimGasAddr) == 0 {
ethCfg.DeprecatedTxPool.FreeClaimGasAddr = []string{"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
}
ethCfg.DeprecatedTxPool.GasPriceMultiple = gasPriceMultiple

newTxs := make(chan types.Announcements, 1024)
defer close(newTxs)
Expand Down
25 changes: 25 additions & 0 deletions cmd/utils/flags_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ var (
Usage: "Comma separated list of addresses, who can't send and receive transactions",
Value: "",
}
TxPoolPackBatchSpecialList = cli.StringFlag{
Name: "txpool.packbatchspeciallist",
Usage: "support free gas for claim addrs",
Value: "",
}
TxPoolGasPriceMultiple = cli.StringFlag{
Name: "txpool.gaspricemultiple",
Usage: "GasPriceMultiple is the factor claim tx gas price should mul",
Value: "",
}
// Gas Price
GpoTypeFlag = cli.StringFlag{
Name: "gpo.type",
Expand Down Expand Up @@ -240,4 +250,19 @@ func setTxPoolXLayer(ctx *cli.Context, cfg *ethconfig.DeprecatedTxPoolConfig) {
cfg.BlockedList[i] = sender.String()
}
}
if ctx.IsSet(TxPoolPackBatchSpecialList.Name) {
addrHexes := SplitAndTrim(ctx.String(TxPoolPackBatchSpecialList.Name))

cfg.FreeClaimGasAddr = make([]string, len(addrHexes))
for i, senderHex := range addrHexes {
sender := libcommon.HexToAddress(senderHex)
cfg.FreeClaimGasAddr[i] = sender.String()
}
}
if len(cfg.FreeClaimGasAddr) == 0 {
cfg.FreeClaimGasAddr = []string{"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
}
if ctx.IsSet(TxPoolGasPriceMultiple.Name) {
cfg.GasPriceMultiple = ctx.Uint64(TxPoolGasPriceMultiple.Name)
}
}
4 changes: 4 additions & 0 deletions eth/ethconfig/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type DeprecatedTxPoolConfig struct {
EnableWhitelist bool
// WhiteList is the white address list
WhiteList []string
// FreeClaimGasAddr is the address list for claim
FreeClaimGasAddr []string
// GasPriceMultiple is the factor claim tx gas price should mul
GasPriceMultiple uint64
}

// DeprecatedDefaultTxPoolConfig contains the default configurations for the transaction
Expand Down
4 changes: 3 additions & 1 deletion test/config/test.erigon.seq.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ db.read.concurrency: 20000
txpool.globalslots: 100000
txpool.globalbasefeeslots: 100000
txpool.globalqueue: 100000
txpool.packbatchspeciallist : ["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"]
txpool.gaspricemultiple : 2

gpo.type: "follower"
gpo.update-period: "10s"
Expand All @@ -75,4 +77,4 @@ gpo.default-l1-coin-price: 2000
gpo.default-l2-coin-price: 50
gpo.gas-price-usdt: 0.000000476190476
gpo.enable-follower-adjust: true
gpo.congestion-threshold: 0
gpo.congestion-threshold: 0
2 changes: 2 additions & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var DefaultFlags = []cli.Flag{
&utils.TxPoolLifetimeFlag,
&utils.TxPoolTraceSendersFlag,
&utils.TxPoolCommitEveryFlag,
&utils.TxPoolPackBatchSpecialList,
&utils.TxPoolGasPriceMultiple,
&PruneFlag,
&PruneHistoryFlag,
&PruneReceiptFlag,
Expand Down
8 changes: 5 additions & 3 deletions zk/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ func New(newTxs chan types.Announcements, coreDB kv.RoDB, cfg txpoolcfg.Config,
allowFreeTransactions: ethCfg.AllowFreeTransactions,
flushMtx: &sync.Mutex{},
wbCfg: WBConfig{ // XLayer config
EnableWhitelist: ethCfg.DeprecatedTxPool.EnableWhitelist,
WhiteList: ethCfg.DeprecatedTxPool.WhiteList,
BlockedList: ethCfg.DeprecatedTxPool.BlockedList,
EnableWhitelist: ethCfg.DeprecatedTxPool.EnableWhitelist,
WhiteList: ethCfg.DeprecatedTxPool.WhiteList,
BlockedList: ethCfg.DeprecatedTxPool.BlockedList,
FreeClaimGasAddr: ethCfg.DeprecatedTxPool.FreeClaimGasAddr,
GasPriceMultiple: ethCfg.DeprecatedTxPool.GasPriceMultiple,
},
aclDB: aclDB,
}, nil
Expand Down
17 changes: 17 additions & 0 deletions zk/txpool/pool_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type WBConfig struct {
EnableWhitelist bool
// WhiteList is the white address list
WhiteList []string
// FreeClaimGasAddr is the address list for free claimTx
FreeClaimGasAddr []string
// GasPriceMultiple is the factor claim tx gas price should mul
GasPriceMultiple uint64
}

type GPCache interface {
Expand Down Expand Up @@ -41,6 +45,19 @@ func (p *TxPool) checkWhiteAddr(addr common.Address) bool {
return false
}

func (p *TxPool) isFreeClaimAddr(senderID uint64) bool {
addr, ok := p.senders.senderID2Addr[senderID]
if !ok {
return false
}
for _, e := range p.wbCfg.FreeClaimGasAddr {
if common.HexToAddress(e) == addr {
return true
}
}
return false
}

func (p *TxPool) SetGpCacheForXLayer(gpCache GPCache) {
p.gpCache = gpCache
}
12 changes: 12 additions & 0 deletions zk/txpool/pool_zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package txpool
import (
"bytes"
"fmt"
"math/big"

mapset "github.com/deckarep/golang-set/v2"
libcommon "github.com/gateway-fm/cdk-erigon-lib/common"
Expand Down Expand Up @@ -69,6 +70,17 @@ func (p *TxPool) onSenderStateChange(senderID uint64, senderNonce uint64, sender
minTip = cmp.Min(minTip, mt.Tx.Tip.Uint64())
}
mt.minTip = minTip
// For X Layer
isClaimAddr := p.isFreeClaimAddr(senderID)
if isClaimAddr {
_, dGp := p.gpCache.GetLatest()
if dGp != nil {
newGp := new(big.Int).Mul(dGp, big.NewInt(int64(p.wbCfg.GasPriceMultiple)))
//newGp := dGp.Mul(dGp, big.NewInt(int64(p.wbCfg.GasPriceMultiple)))
mt.minTip = newGp.Uint64()
mt.minFeeCap = *uint256.NewInt(mt.minTip)
}
}

mt.nonceDistance = 0
if mt.Tx.Nonce > senderNonce { // no uint underflow
Expand Down
2 changes: 1 addition & 1 deletion zk/txpool/txpooluitl/all_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"time"

"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
"github.com/gateway-fm/cdk-erigon-lib/txpool/txpoolcfg"
"github.com/holiman/uint256"
chengzhinei marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ledgerwatch/log/v3"
mdbx2 "github.com/torquem-ch/mdbx-go/mdbx"

Expand Down
Loading