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

Fix config initialization failure on start up, clean up configs #53

Merged
merged 7 commits into from
Jul 8, 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
15 changes: 9 additions & 6 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ type APIImpl struct {
MaxGasPrice uint64
GasPriceFactor float64
L1GasPrice L1GasPrice
L2GasPircer gasprice.L2GasPricer
EnableInnerTx bool // XLayer

// For X Layer
L2GasPricer gasprice.L2GasPricer
EnableInnerTx bool
}

// NewEthAPI returns APIImpl instance
Expand All @@ -376,12 +378,13 @@ func NewEthAPI(base *BaseAPI, db kv.RoDB, eth rpchelper.ApiBackend, txPool txpoo
MaxGasPrice: ethCfg.MaxGasPrice,
GasPriceFactor: ethCfg.GasPriceFactor,
L1GasPrice: L1GasPrice{},
L2GasPircer: gasprice.NewL2GasPriceSuggester(context.Background(), ethconfig.Defaults.GPO),
EnableInnerTx: ethCfg.EnableInnerTx,
// For X Layer
L2GasPricer: gasprice.NewL2GasPriceSuggester(context.Background(), ethCfg.GPO),
EnableInnerTx: ethCfg.XLayer.EnableInnerTx,
}

// set default gas price
apii.gasCache.SetLatest(common.Hash{}, apii.L2GasPircer.GetConfig().Default)
// For X Layer. Set default gas price
apii.gasCache.SetLatest(common.Hash{}, apii.L2GasPricer.GetConfig().Default)
go apii.runL2GasPriceSuggester()

return apii
Expand Down
18 changes: 9 additions & 9 deletions cmd/rpcdaemon/commands/eth_system_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (api *APIImpl) gasPriceXL(ctx context.Context) (*hexutil.Big, error) {
price, err := api.getGPFromTrustedNode()
if err != nil {
log.Error("eth_gasPrice error: ", err)
return (*hexutil.Big)(api.L2GasPircer.GetConfig().Default), nil
return (*hexutil.Big)(api.L2GasPricer.GetConfig().Default), nil
}

return (*hexutil.Big)(price), nil
Expand All @@ -62,7 +62,7 @@ func (api *APIImpl) gasPriceNonRedirectedXL(ctx context.Context) (*hexutil.Big,
gasResult.Add(tipcap, head.BaseFee)
}

rgp := api.L2GasPircer.GetLastRawGP()
rgp := api.L2GasPricer.GetLastRawGP()
if gasResult.Cmp(rgp) < 0 {
gasResult = new(big.Int).Set(rgp)
}
Expand All @@ -87,7 +87,7 @@ func (api *APIImpl) isCongested(ctx context.Context) bool {
return false
}

isPendingTxCongested := int(poolStatus.PendingCount) >= api.L2GasPircer.GetConfig().CongestionThreshold
isPendingTxCongested := int(poolStatus.PendingCount) >= api.L2GasPricer.GetConfig().XLayer.CongestionThreshold

return !isLatestBlockEmpty && isPendingTxCongested
}
Expand Down Expand Up @@ -125,16 +125,16 @@ func (api *APIImpl) getGPFromTrustedNode() (*big.Int, error) {
}

func (api *APIImpl) runL2GasPriceSuggester() {
cfg := api.L2GasPircer.GetConfig()
ctx := api.L2GasPircer.GetCtx()
cfg := api.L2GasPricer.GetConfig()
ctx := api.L2GasPricer.GetCtx()

//todo: apollo
l1gp, err := gasprice.GetL1GasPrice(api.L1RpcUrl)
// if err != nil, do nothing
if err == nil {
api.L2GasPircer.UpdateGasPriceAvg(l1gp)
api.L2GasPricer.UpdateGasPriceAvg(l1gp)
}
updateTimer := time.NewTimer(cfg.UpdatePeriod)
updateTimer := time.NewTimer(cfg.XLayer.UpdatePeriod)
for {
select {
case <-ctx.Done():
Expand All @@ -143,9 +143,9 @@ func (api *APIImpl) runL2GasPriceSuggester() {
case <-updateTimer.C:
l1gp, err := gasprice.GetL1GasPrice(api.L1RpcUrl)
if err == nil {
api.L2GasPircer.UpdateGasPriceAvg(l1gp)
api.L2GasPricer.UpdateGasPriceAvg(l1gp)
}
updateTimer.Reset(cfg.UpdatePeriod)
updateTimer.Reset(cfg.XLayer.UpdatePeriod)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/eth_system_zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type L1GasPrice struct {
}

func (api *APIImpl) GasPrice(ctx context.Context) (*hexutil.Big, error) {
// xlayer handler
if api.L2GasPircer.GetConfig().Type != "" {
// X Layer handler
if api.L2GasPricer.GetConfig().XLayer.Type != "" {
return api.gasPriceXL(ctx)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (

commitEvery time.Duration

// For X Layer
enableWhiteList bool
whiteList []string
blockList []string
Expand Down Expand Up @@ -162,7 +163,7 @@ func doTxpool(ctx context.Context) error {
cfg.TracedSenders[i] = string(sender[:])
}

// XLayer tx pool access
// For X Layer tx pool access
ethCfg := &ethconfig.Defaults
ethCfg.DeprecatedTxPool.EnableWhitelist = enableWhiteList
ethCfg.DeprecatedTxPool.WhiteList = make([]string, len(whiteList))
Expand Down
229 changes: 3 additions & 226 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,6 @@ var (
Usage: "How often transactions should be committed to the storage",
Value: txpoolcfg.DefaultConfig.CommitEvery,
}
TxPoolEnableWhitelistFlag = cli.BoolFlag{
Name: "txpool.enable.whitelist",
Usage: "Enable or disable tx sender white list",
Value: false,
}
TxPoolWhiteList = cli.StringFlag{
Name: "txpool.whitelist",
Usage: "Comma separated list of addresses, who can send transactions",
Value: "",
}
TxPoolBlockedList = cli.StringFlag{
Name: "txpool.blockedlist",
Usage: "Comma separated list of addresses, who can't send and receive transactions",
Value: "",
}
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
Expand Down Expand Up @@ -644,27 +629,6 @@ var (
Name: "debug.step-after",
Usage: "Start incrementing by debug.step after this block",
}
// XLayer nacos
NacosURLsFlag = cli.StringFlag{
Name: "zkevm.nacos-urls",
Usage: "Nacos urls.",
Value: "",
}
NacosNamespaceIdFlag = cli.StringFlag{
Name: "zkevm.nacos-namespace-id",
Usage: "Nacos namespace Id.",
Value: "",
}
NacosApplicationNameFlag = cli.StringFlag{
Name: "zkevm.nacos-application-name",
Usage: "Nacos application name",
Value: "",
}
NacosExternalListenAddrFlag = cli.StringFlag{
Name: "zkevm.nacos-external-listen-addr",
Usage: "Nacos external listen addr.",
Value: "",
}
RpcBatchConcurrencyFlag = cli.UintFlag{
Name: "rpc.batch.concurrency",
Usage: "Does limit amount of goroutines to process 1 batch request. Means 1 bach request can't overload server. 1 batch still can have unlimited amount of request",
Expand Down Expand Up @@ -910,108 +874,6 @@ var (
Usage: "Maximum gas price will be recommended by gpo",
Value: ethconfig.Defaults.GPO.MaxPrice.Int64(),
}

GpoDefaultGasPriceFlag = cli.Int64Flag{
Name: "gpo.default-price",
Usage: "Default gas price will be recommended by gpo",
Value: ethconfig.Defaults.GPO.Default.Int64(),
}

GpoTypeFlag = cli.StringFlag{
Name: "gpo.type",
Usage: "raw gas price strategy type: default, follower, fixed",
Value: "default",
}

GpoUpdatePeriodFlag = cli.StringFlag{
Name: "gpo.update-period",
Usage: "raw gas price update period",
Value: "10s",
}

GpoFactorFlag = cli.Float64Flag{
Name: "gpo.factor",
Usage: "raw gas price facotr",
Value: 0.15,
}

GpoKafkaURLFlag = cli.StringFlag{
Name: "gpo.kafka-url",
Usage: "raw gas price kafka url",
Value: "",
}

GpoTopicFlag = cli.StringFlag{
Name: "gpo.topic",
Usage: "raw gas price topic",
Value: "",
}

GpoGroupIDFlag = cli.StringFlag{
Name: "gpo.group-id",
Usage: "raw gas price group id",
Value: "",
}

GpoUsernameFlag = cli.StringFlag{
Name: "gpo.username",
Usage: "raw gas price username",
Value: "",
}

GpoPasswordFlag = cli.StringFlag{
Name: "gpo.password",
Usage: "raw gas price password",
Value: "",
}

GpoRootCAPathFlag = cli.StringFlag{
Name: "gpo.root-ca-path",
Usage: "raw gas price root ca path",
Value: "",
}

GpoL1CoinIdFlag = cli.IntFlag{
Name: "gpo.l1-coin-id",
Usage: "raw gas price l1 coin id",
Value: 0,
}

GpoL2CoinIdFlag = cli.IntFlag{
Name: "gpo.l2-coin-id",
Usage: "raw gas price l2 coin id",
Value: 0,
}

GpoDefaultL1CoinPriceFlag = cli.Float64Flag{
Name: "gpo.default-l1-coin-price",
Usage: "raw gas price default l1 coin price",
Value: 0,
}

GpoDefaultL2CoinPriceFlag = cli.Float64Flag{
Name: "gpo.default-l2-coin-price",
Usage: "raw gas price default l2 coin price",
Value: 0,
}

GpoGasPriceUsdtFlag = cli.Float64Flag{
Name: "gpo.gas-price-usdt",
Usage: "raw gas price usdt",
Value: 0,
}

GpoEnableFollowerAdjustByL2L1PriceFlag = cli.BoolFlag{
Name: "gpo.enable-follower-adjust",
Usage: "enable dynamic adjust the factor through the L1 and L2 coins price in follower strategy",
Value: true,
}

GpoCongestionThresholdFlag = cli.IntFlag{
Name: "gpo.congestion-threshold",
Usage: "Used to determine whether pending tx has reached the threshold for congestion",
Value: 0,
}
// Metrics flags
MetricsEnabledFlag = cli.BoolFlag{
Name: "metrics",
Expand Down Expand Up @@ -1626,73 +1488,8 @@ func setGPO(ctx *cli.Context, cfg *gaspricecfg.Config) {
cfg.Default = big.NewInt(ctx.Int64(GpoDefaultGasPriceFlag.Name))
}

if ctx.IsSet(GpoTypeFlag.Name) {
cfg.Type = ctx.String(GpoTypeFlag.Name)
}

if ctx.IsSet(GpoUpdatePeriodFlag.Name) {
period, err := time.ParseDuration(ctx.String(GpoUpdatePeriodFlag.Name))
if err != nil {
panic(fmt.Sprintf("could not parse GpoUpdatePeriodFlag value %s", ctx.String(GpoUpdatePeriodFlag.Name)))
}
cfg.UpdatePeriod = period
}

if ctx.IsSet(GpoFactorFlag.Name) {
cfg.Factor = ctx.Float64(GpoFactorFlag.Name)
}

if ctx.IsSet(GpoKafkaURLFlag.Name) {
cfg.KafkaURL = ctx.String(GpoKafkaURLFlag.Name)
}

if ctx.IsSet(GpoTopicFlag.Name) {
cfg.Topic = ctx.String(GpoTopicFlag.Name)
}

if ctx.IsSet(GpoGroupIDFlag.Name) {
cfg.GroupID = ctx.String(GpoGroupIDFlag.Name)
}

if ctx.IsSet(GpoUsernameFlag.Name) {
cfg.Username = ctx.String(GpoUsernameFlag.Name)
}

if ctx.IsSet(GpoPasswordFlag.Name) {
cfg.Password = ctx.String(GpoPasswordFlag.Name)
}

if ctx.IsSet(GpoRootCAPathFlag.Name) {
cfg.RootCAPath = ctx.String(GpoRootCAPathFlag.Name)
}

if ctx.IsSet(GpoL1CoinIdFlag.Name) {
cfg.L1CoinId = ctx.Int(GpoL1CoinIdFlag.Name)
}

if ctx.IsSet(GpoL2CoinIdFlag.Name) {
cfg.L2CoinId = ctx.Int(GpoL2CoinIdFlag.Name)
}

if ctx.IsSet(GpoDefaultL1CoinPriceFlag.Name) {
cfg.DefaultL1CoinPrice = ctx.Float64(GpoDefaultL1CoinPriceFlag.Name)
}

if ctx.IsSet(GpoDefaultL2CoinPriceFlag.Name) {
cfg.DefaultL2CoinPrice = ctx.Float64(GpoDefaultL2CoinPriceFlag.Name)
}

if ctx.IsSet(GpoGasPriceUsdtFlag.Name) {
cfg.GasPriceUsdt = ctx.Float64(GpoGasPriceUsdtFlag.Name)
}

if ctx.IsSet(GpoEnableFollowerAdjustByL2L1PriceFlag.Name) {
cfg.EnableFollowerAdjustByL2L1Price = ctx.Bool(GpoEnableFollowerAdjustByL2L1PriceFlag.Name)
}

if ctx.IsSet(GpoCongestionThresholdFlag.Name) {
cfg.CongestionThreshold = ctx.Int(GpoCongestionThresholdFlag.Name)
}
// For X Layer
setGPOXLayer(ctx, &cfg.XLayer)
}

// nolint
Expand Down Expand Up @@ -1762,27 +1559,7 @@ func setTxPool(ctx *cli.Context, cfg *ethconfig.DeprecatedTxPoolConfig) {
cfg.CommitEvery = common2.RandomizeDuration(ctx.Duration(TxPoolCommitEveryFlag.Name))

// XLayer config
if ctx.IsSet(TxPoolEnableWhitelistFlag.Name) {
cfg.EnableWhitelist = ctx.Bool(TxPoolEnableWhitelistFlag.Name)
}
if ctx.IsSet(TxPoolWhiteList.Name) {
// Parse the command separated flag
addrHexes := SplitAndTrim(ctx.String(TxPoolWhiteList.Name))
cfg.WhiteList = make([]string, len(addrHexes))
for i, senderHex := range addrHexes {
sender := libcommon.HexToAddress(senderHex)
cfg.WhiteList[i] = sender.String()
}
}
if ctx.IsSet(TxPoolBlockedList.Name) {
// Parse the command separated flag
addrHexes := SplitAndTrim(ctx.String(TxPoolBlockedList.Name))
cfg.BlockedList = make([]string, len(addrHexes))
for i, senderHex := range addrHexes {
sender := libcommon.HexToAddress(senderHex)
cfg.BlockedList[i] = sender.String()
}
}
setTxPoolXLayer(ctx, cfg)
}

func setEthash(ctx *cli.Context, datadir string, cfg *ethconfig.Config) {
Expand Down
Loading
Loading