diff --git a/l2geth/internal/ethapi/api.go b/l2geth/internal/ethapi/api.go index 6c384955ce1..710460736c4 100644 --- a/l2geth/internal/ethapi/api.go +++ b/l2geth/internal/ethapi/api.go @@ -1008,24 +1008,25 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash // 1. get the gas that would be used by the transaction gasUsed, err := legacyDoEstimateGas(ctx, b, args, blockNrOrHash, gasCap) if err != nil { - return 0, err + return 0, fmt.Errorf("execution gas used error: %w", err) } // 2a. fetch the data price, depends on how the sequencer has chosen to update their values based on the // l1 gas prices dataPrice, err := b.SuggestDataPrice(ctx) if err != nil { - return 0, err + return 0, fmt.Errorf("data gas pricing error: %w", err) } // 2b. fetch the execution gas price, by the typical mempool dynamics executionPrice, err := b.SuggestPrice(ctx) if err != nil { - return 0, err + return 0, fmt.Errorf("unknown gas price: %w", err) } // 3. calculate the fee and normalize by the default gas price fee := core.CalculateRollupFee(*args.Data, uint64(gasUsed), dataPrice, executionPrice).Uint64() / defaultGasPrice + log.Debug("Estimate Gas", "gas-used", uint64(gasUsed), "data-price", dataPrice.Uint64(), "execution-price", executionPrice.Uint64(), "fee", fee, "default-gas-price", defaultGasPrice) return (hexutil.Uint64)(fee), nil } @@ -1065,19 +1066,20 @@ func legacyDoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrO args.From = &common.Address{} } // Create a helper to check if a gas allowance results in an executable transaction - executable := func(gas uint64) bool { + executable := func(gas uint64) (uint64, bool) { args.Gas = (*hexutil.Uint64)(&gas) - _, _, failed, err := DoCall(ctx, b, args, blockNrOrHash, nil, vm.Config{}, 0, gasCap) + _, gas, failed, err := DoCall(ctx, b, args, blockNrOrHash, nil, vm.Config{}, 0, gasCap) if err != nil || failed { - return false + return gas, false } - return true + return gas, true } // Execute the binary search and hone in on an executable gas limit for lo+1 < hi { mid := (hi + lo) / 2 - if !executable(mid) { + _, executed := executable(mid) + if !executed { lo = mid } else { hi = mid @@ -1085,8 +1087,9 @@ func legacyDoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrO } // Reject the transaction as invalid if it still fails at the highest allowance if hi == cap { - if !executable(hi) { - return 0, fmt.Errorf("gas required exceeds allowance (%d) or always failing transaction", cap) + gas, executed := executable(hi) + if !executed { + return 0, fmt.Errorf("gas required (%d) exceeds allowance (%d) or always failing transaction", gas, cap) } } return hexutil.Uint64(hi), nil diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 4a8864e5bc5..9a883c4a6a5 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -296,6 +296,9 @@ func (s *SyncService) Stop() error { func (s *SyncService) VerifierLoop() { log.Info("Starting Verifier Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { + if err := s.updateL1GasPrice(); err != nil { + log.Error("Cannot update L1 gas price", "msg", err) + } if err := s.verify(); err != nil { log.Error("Could not verify", "error", err) } @@ -344,8 +347,13 @@ func (s *SyncService) verify() error { func (s *SyncService) SequencerLoop() { log.Info("Starting Sequencer Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { + err := s.updateL1GasPrice() + if err != nil { + log.Error("Cannot update L1 gas price", "msg", err) + continue + } s.txLock.Lock() - err := s.sequence() + err = s.sequence() if err != nil { log.Error("Could not sequence", "error", err) } @@ -360,14 +368,6 @@ func (s *SyncService) SequencerLoop() { } func (s *SyncService) sequence() error { - // Update to the latest L1 gas price - l1GasPrice, err := s.client.GetL1GasPrice() - if err != nil { - return err - } - s.L1gpo.SetL1GasPrice(l1GasPrice) - log.Info("Adjusted L1 Gas Price", "gasprice", l1GasPrice) - // Only the sequencer needs to poll for enqueue transactions // and then can choose when to apply them. We choose to apply // transactions such that it makes for efficient batch submitting. @@ -445,6 +445,17 @@ func (s *SyncService) sequence() error { return nil } +func (s *SyncService) updateL1GasPrice() error { + // Update to the latest L1 gas price + l1GasPrice, err := s.client.GetL1GasPrice() + if err != nil { + return err + } + s.L1gpo.SetL1GasPrice(l1GasPrice) + log.Info("Adjusted L1 Gas Price", "gasprice", l1GasPrice) + return nil +} + /// Update the execution context's timestamp and blocknumber /// over time. This is only necessary for the sequencer. func (s *SyncService) updateContext() error {