From 1937b89d1d2d868003f8eabd70cdfe85d7d2fd3c Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 18 Mar 2026 10:54:28 +0800 Subject: [PATCH 1/3] estimate gas at pending block --- ethstorage/miner/l1_mining_api.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 48410f2b..961af2ed 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -147,20 +147,30 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add return common.Hash{}, errDropped{reason: errMessage} } - estimatedGas, err := m.EstimateGas(ctx, ethereum.CallMsg{ + estimatedGas, err := m.EstimateGasAtBlock(ctx, ethereum.CallMsg{ From: cfg.SignerAddr, To: &contract, GasTipCap: tip, GasFeeCap: gasFeeCap, Value: common.Big0, Data: calldata, - }) + }, big.NewInt(rpc.PendingBlockNumber.Int64())) if err != nil { errMessage := parseErr(err) m.lg.Error("Estimate gas failed", "error", errMessage) return common.Hash{}, fmt.Errorf("failed to estimate gas: %v", errMessage) } m.lg.Info("Estimated gas done", "gas", estimatedGas) + // query current block number for debug + currentBlock, err := m.BlockNumber(ctx) + if err != nil { + m.lg.Warn("Failed to query current block number", "error", err) + } else { + m.lg.Info("Current block number", "blockNumber", currentBlock) + } + if currentBlock == rst.blockNumber.Uint64() { + m.lg.Warn("Current block number is the same as the mined block number, the tx might fail due to empty blockhash, consider to wait for next block", "blockNumber", currentBlock) + } nonce, err := m.PendingNonceAt(ctx, cfg.SignerAddr) if err != nil { From 08db302e3237c7d2914f1af9213c38ab148db840 Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 18 Mar 2026 15:49:49 +0800 Subject: [PATCH 2/3] rm debug --- ethstorage/miner/l1_mining_api.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 961af2ed..d91f55f7 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -161,16 +161,6 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add return common.Hash{}, fmt.Errorf("failed to estimate gas: %v", errMessage) } m.lg.Info("Estimated gas done", "gas", estimatedGas) - // query current block number for debug - currentBlock, err := m.BlockNumber(ctx) - if err != nil { - m.lg.Warn("Failed to query current block number", "error", err) - } else { - m.lg.Info("Current block number", "blockNumber", currentBlock) - } - if currentBlock == rst.blockNumber.Uint64() { - m.lg.Warn("Current block number is the same as the mined block number, the tx might fail due to empty blockhash, consider to wait for next block", "blockNumber", currentBlock) - } nonce, err := m.PendingNonceAt(ctx, cfg.SignerAddr) if err != nil { From 4212c5d46066f0be236ebf0a30e96f5b103e990e Mon Sep 17 00:00:00 2001 From: syntrust Date: Wed, 18 Mar 2026 17:55:11 +0800 Subject: [PATCH 3/3] rm old fix --- ethstorage/miner/worker.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ethstorage/miner/worker.go b/ethstorage/miner/worker.go index f3ae5fc0..caf7d0d8 100644 --- a/ethstorage/miner/worker.go +++ b/ethstorage/miner/worker.go @@ -426,13 +426,6 @@ func (w *worker) resultLoop() { continue } w.lg.Info("Mining result loop get result", "shard", result.startShardId, "block", result.blockNumber, "nonce", result.nonce) - - // Mining result comes within the same block time window - if tillNextSlot := int64(result.timestamp) + int64(w.config.Slot) - time.Now().Unix(); tillNextSlot > 0 { - // Wait until next block comes to avoid empty blockhash on gas estimation - w.lg.Info("Hold on submitting mining result till block+1", "block", result.blockNumber, "secondsToWait", tillNextSlot) - time.Sleep(time.Duration(tillNextSlot) * time.Second) - } txHash, err := w.l1API.SubmitMinedResult( context.Background(), w.storageMgr.ContractAddress(),