From 56b4620af7150935b75434ac9bf608dd157fdc52 Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 6 Nov 2024 11:12:36 +0800 Subject: [PATCH 1/4] handle GetMiningReward err --- ethstorage/miner/l1_mining_api.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index fd6601e5..94c72299 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -112,8 +112,7 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add reward, err := m.GetMiningReward(rst.startShardId, rst.blockNumber.Int64()) if err != nil { - m.lg.Error("Query mining reward failed", "error", err.Error()) - return common.Hash{}, err + m.lg.Warn("Query mining reward failed", "error", err.Error()) } profitableGasFeeCap := new(big.Int).Div(new(big.Int).Sub(reward, cfg.MinimumProfit), new(big.Int).SetUint64(estimatedGas)) m.lg.Info("Minimum profitable gas fee cap", "gasFeeCap", profitableGasFeeCap) @@ -123,8 +122,14 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add return common.Hash{}, errDropped } if !useConfig { - gasFeeCap = profitableGasFeeCap - m.lg.Info("Using profitable gas fee cap", "gasFeeCap", gasFeeCap) + if reward == nil { + // (tip + 2*baseFee) to ensure the tx to be marketable for six consecutive 100% full blocks. + gasFeeCap = new(big.Int).Add(new(big.Int).Mul(new(big.Int).Sub(gasFeeCap, tip), big.NewInt(2)), tip) + m.lg.Info("Using marketable gas fee cap", "gasFeeCap", gasFeeCap) + } else { + gasFeeCap = profitableGasFeeCap + m.lg.Info("Using profitable gas fee cap", "gasFeeCap", gasFeeCap) + } } sign := cfg.SignerFnFactory(m.NetworkID) nonce, err := m.NonceAt(ctx, cfg.SignerAddr, big.NewInt(rpc.LatestBlockNumber.Int64())) From c72d913fce318559ff5a848d6b3802a37c57f08c Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 6 Nov 2024 14:12:29 +0800 Subject: [PATCH 2/4] fix --- ethstorage/miner/l1_mining_api.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 94c72299..81d8176c 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -110,25 +110,25 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add } m.lg.Info("Estimated gas done", "gas", estimatedGas) - reward, err := m.GetMiningReward(rst.startShardId, rst.blockNumber.Int64()) - if err != nil { - m.lg.Warn("Query mining reward failed", "error", err.Error()) - } - profitableGasFeeCap := new(big.Int).Div(new(big.Int).Sub(reward, cfg.MinimumProfit), new(big.Int).SetUint64(estimatedGas)) - m.lg.Info("Minimum profitable gas fee cap", "gasFeeCap", profitableGasFeeCap) - if gasFeeCap.Cmp(profitableGasFeeCap) == 1 { - profit := new(big.Int).Sub(reward, new(big.Int).Mul(new(big.Int).SetUint64(estimatedGas), gasFeeCap)) - m.lg.Warn("Mining tx dropped: the profit will not meet expectation", "estimatedProfit", fmtEth(profit), "minimumProfit", fmtEth(cfg.MinimumProfit)) - return common.Hash{}, errDropped - } if !useConfig { - if reward == nil { + reward, err := m.GetMiningReward(rst.startShardId, rst.blockNumber.Int64()) + if err != nil { + m.lg.Warn("Query mining reward failed", "error", err.Error()) + } + if reward != nil { + profitableGasFeeCap := new(big.Int).Div(new(big.Int).Sub(reward, cfg.MinimumProfit), new(big.Int).SetUint64(estimatedGas)) + m.lg.Info("Minimum profitable gas fee cap", "gasFeeCap", profitableGasFeeCap) + if gasFeeCap.Cmp(profitableGasFeeCap) == 1 { + profit := new(big.Int).Sub(reward, new(big.Int).Mul(new(big.Int).SetUint64(estimatedGas), gasFeeCap)) + m.lg.Warn("Mining tx dropped: the profit will not meet expectation", "estimatedProfit", fmtEth(profit), "minimumProfit", fmtEth(cfg.MinimumProfit)) + return common.Hash{}, errDropped + } + gasFeeCap = profitableGasFeeCap + m.lg.Info("Using profitable gas fee cap", "gasFeeCap", gasFeeCap) + } else { // (tip + 2*baseFee) to ensure the tx to be marketable for six consecutive 100% full blocks. gasFeeCap = new(big.Int).Add(new(big.Int).Mul(new(big.Int).Sub(gasFeeCap, tip), big.NewInt(2)), tip) m.lg.Info("Using marketable gas fee cap", "gasFeeCap", gasFeeCap) - } else { - gasFeeCap = profitableGasFeeCap - m.lg.Info("Using profitable gas fee cap", "gasFeeCap", gasFeeCap) } } sign := cfg.SignerFnFactory(m.NetworkID) From c2c7563c482891d6b443c75df1a5760784ef58a7 Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 6 Nov 2024 14:36:43 +0800 Subject: [PATCH 3/4] fix --- ethstorage/miner/l1_mining_api.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 81d8176c..1873a2c2 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -110,27 +110,30 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add } m.lg.Info("Estimated gas done", "gas", estimatedGas) - if !useConfig { - reward, err := m.GetMiningReward(rst.startShardId, rst.blockNumber.Int64()) - if err != nil { - m.lg.Warn("Query mining reward failed", "error", err.Error()) + reward, err := m.GetMiningReward(rst.startShardId, rst.blockNumber.Int64()) + if err != nil { + m.lg.Warn("Query mining reward failed", "error", err.Error()) + } + if reward != nil { + profitableGasFeeCap := new(big.Int).Div(new(big.Int).Sub(reward, cfg.MinimumProfit), new(big.Int).SetUint64(estimatedGas)) + m.lg.Info("Minimum profitable gas fee cap", "gasFeeCap", profitableGasFeeCap) + if gasFeeCap.Cmp(profitableGasFeeCap) == 1 { + profit := new(big.Int).Sub(reward, new(big.Int).Mul(new(big.Int).SetUint64(estimatedGas), gasFeeCap)) + m.lg.Warn("Mining tx dropped: the profit will not meet expectation", "estimatedProfit", fmtEth(profit), "minimumProfit", fmtEth(cfg.MinimumProfit)) + return common.Hash{}, errDropped } - if reward != nil { - profitableGasFeeCap := new(big.Int).Div(new(big.Int).Sub(reward, cfg.MinimumProfit), new(big.Int).SetUint64(estimatedGas)) - m.lg.Info("Minimum profitable gas fee cap", "gasFeeCap", profitableGasFeeCap) - if gasFeeCap.Cmp(profitableGasFeeCap) == 1 { - profit := new(big.Int).Sub(reward, new(big.Int).Mul(new(big.Int).SetUint64(estimatedGas), gasFeeCap)) - m.lg.Warn("Mining tx dropped: the profit will not meet expectation", "estimatedProfit", fmtEth(profit), "minimumProfit", fmtEth(cfg.MinimumProfit)) - return common.Hash{}, errDropped - } + if !useConfig { gasFeeCap = profitableGasFeeCap m.lg.Info("Using profitable gas fee cap", "gasFeeCap", gasFeeCap) - } else { + } + } else { + if !useConfig { // (tip + 2*baseFee) to ensure the tx to be marketable for six consecutive 100% full blocks. gasFeeCap = new(big.Int).Add(new(big.Int).Mul(new(big.Int).Sub(gasFeeCap, tip), big.NewInt(2)), tip) m.lg.Info("Using marketable gas fee cap", "gasFeeCap", gasFeeCap) } } + sign := cfg.SignerFnFactory(m.NetworkID) nonce, err := m.NonceAt(ctx, cfg.SignerAddr, big.NewInt(rpc.LatestBlockNumber.Int64())) if err != nil { From 3335bb959a6248774d78bb436d5a84ad15d3dc5a Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 6 Nov 2024 18:03:24 +0800 Subject: [PATCH 4/4] add log --- ethstorage/miner/l1_mining_api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 1873a2c2..0e5cb625 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" @@ -90,6 +91,7 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add m.lg.Error("Failed to compose calldata", "error", err) return common.Hash{}, err } + m.lg.Info("Composed calldata", "calldata", hexutil.Encode(calldata)) tip, gasFeeCap, useConfig, err := m.suggestGasPrices(ctx, cfg) if err != nil { @@ -249,6 +251,8 @@ func (m *l1MiningAPI) suggestGasPrices(ctx context.Context, cfg Config) (*big.In } gasFeeCap = new(big.Int).Add(blockHeader.BaseFee, tip) m.lg.Info("Suggested gas fee cap", "gasFeeCap", gasFeeCap) + } else { + m.lg.Info("Using configured gas price", "gasFeeCap", gasFeeCap, "tip", tip) } return tip, gasFeeCap, useConfig, nil }