diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go index 134a75fc2c7..2a58df91f13 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go @@ -13,6 +13,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" httypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" @@ -43,10 +44,12 @@ type BlockSubscriber struct { mu sync.RWMutex hb httypes.HeadBroadcaster lp logpoller.LogPoller + ge gas.EvmFeeEstimator headC chan *evmtypes.Head unsubscribe func() subscribers map[int]chan ocr2keepers.BlockHistory blocks map[int64]string + fastGas map[int64]int64 maxSubId int lastClearedBlock int64 lastSentBlock int64 @@ -71,6 +74,7 @@ func NewBlockSubscriber(hb httypes.HeadBroadcaster, lp logpoller.LogPoller, fina headC: make(chan *evmtypes.Head, channelSize), subscribers: map[int]chan ocr2keepers.BlockHistory{}, blocks: map[int64]string{}, + fastGas: map[int64]int64{}, blockHistorySize: blockHistorySize, blockSize: lookbackDepth, finalityDepth: finalityDepth, @@ -274,6 +278,15 @@ func (bs *BlockSubscriber) processHead(h *evmtypes.Head) { } } + //fee, _, err := bs.ge.GetFee(ctx, _, feeLimit, maxFeeWei) + //var fg int64 + //if fee.ValidDynamic() { + // fg = fee.DynamicFeeCap.Int64() + fee.DynamicTipCap.Int64() + //} else { + // fg = fee.Legacy.Int64() + //} + //bs.fastGas[h.Number] = fg + bs.lggr.Debugf("published block history with length %d and latestBlock %d to %d subscriber(s)", len(history), bs.latestBlock.Load(), len(bs.subscribers)) } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go index bdaf3bd07ef..538d777dacc 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go @@ -191,17 +191,14 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, payloads []ocr2keepers.U continue } - // estimated_tx_call_data is not needed to estimate fast gas except for Arbitrum. - //fee, _, _ := r.gasEstimator.GetFee(ctx, estimated_tx_call_data, feeLimit, maxFeePrice) - //fastGas := new(big.Int) - //if fee.ValidDynamic() { - // fastGas = fee.DynamicFeeCap.ToInt() // should we consider tipping?? - //} else { - // fastGas = fee.Legacy.ToInt() - //} - // //// this block will be updated by plug-in to keep it relatively new. e.g. within 2 min from block height //// call gas estimator (GE) component to get L2 gas cost + //// estimated_tx_call_data is not needed to estimate fast gas except for Arbitrum. + //fg, ok := r.bs.fastGas[block.Int64()] + //if !ok { + // // if fast gas at this block does not exist, use the latest + // fg, _, _ = r.gasEstimator.GetFee(...) + //} // //var estimatedL1GasCost uint256 //var err error @@ -227,7 +224,7 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, payloads []ocr2keepers.U } // check data will include the log trigger config - payload, err = r.abi.Pack("checkUpkeep", upkeepId, p.CheckData /* ChainConfig(estimatedL1GasCost, fastGas) */) + payload, err = r.abi.Pack("checkUpkeep", upkeepId, p.CheckData /* ChainConfig(estimatedL1GasCost, fg) */) if err != nil { // pack error, no retryable r.lggr.Warnf("failed to pack log trigger checkUpkeep data for upkeepId %s with check data %s: %s", upkeepId, hexutil.Encode(p.CheckData), err) @@ -237,7 +234,7 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, payloads []ocr2keepers.U default: // checkUpkeep is overloaded on the contract for conditionals and log upkeeps // Need to use the first function (checkUpkeep0) for conditionals - payload, err = r.abi.Pack("checkUpkeep0", upkeepId /* ChainConfig(estimatedL1GasCost, fastGas) */) + payload, err = r.abi.Pack("checkUpkeep0", upkeepId /* ChainConfig(estimatedL1GasCost, fg) */) if err != nil { // pack error, no retryable r.lggr.Warnf("failed to pack conditional checkUpkeep data for upkeepId %s with check data %s: %s", upkeepId, hexutil.Encode(p.CheckData), err) @@ -389,20 +386,17 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ } else { // at this point, the core node knows the exact perform data of the upkeep and the call data to L1. // it can calculate a relatively accurate L1 gas cost - - //actual_tx_call_data := checkResults[performToKeyIdx[i]].PerformData + byte padding; - //fee, _, _ := r.gasEstimator.GetFee(ctx, actual_tx_call_data, feeLimit, maxFeePrice) - //fastGas := new(big.Int) - //if fee.ValidDynamic() { - // fastGas = fee.DynamicFeeCap.ToInt() // should we consider tipping?? - //} else { - // fastGas = fee.Legacy.ToInt() + //fg, ok := r.bs.fastGas[block.Int64()] + //if !ok { + // // if fast gas at this block does not exist, use the latest + // fg, _, _ = r.gasEstimator.GetFee(...) //} // //// this block will be updated by plug-in to keep it relatively new. e.g. within 2 min from block height //// call gas estimator (GE) component to get L2 gas cost // //// can we estimate this L1GasCost by comparing estimated call data and actual call data?? + //actual_tx_call_data := checkResults[performToKeyIdx[i]].PerformData + byte padding; //var executionL1GasCost uint256 //var err error //// if L1 oracle is configured, it's a L2 @@ -412,7 +406,7 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ // // handle error // } //} - //checkResults[performToKeyIdx[i]].FastGasWei = fastGas + //checkResults[performToKeyIdx[i]].FastGasWei = fg //checkResults[performToKeyIdx[i]].L1GasCost = executionL1GasCost } }