From 6f95b09e1bf497012a24810fe7830b7f0f2e93cf Mon Sep 17 00:00:00 2001 From: nogo <110664798+0xnogo@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:27:35 +0400 Subject: [PATCH] gas estimator + fee boosting integ test (#15208) * initial test * gomodtidy * merge and fix * price updates * adding price in integ-test helpers * commong bump * messageMaxGas update * remodelling of fee boosting test * gomodtidy * fixing * fixes * reset gomod * update cl-ccip * smoke test * change timeout * skip * reset go.mod * addressing comments * go mod cl-ccip * adding comments * update after last rebase --- .github/e2e-tests.yml | 14 ++ core/capabilities/ccip/ccipevm/gas_helpers.go | 7 +- .../ccip/ccipevm/gas_helpers_test.go | 18 +- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- deployment/ccip/add_lane.go | 35 ++-- deployment/ccip/add_lane_test.go | 4 +- .../ccip/changeset/active_candidate_test.go | 2 +- deployment/ccip/changeset/add_chain_test.go | 2 +- .../ccip/changeset/initial_deploy_test.go | 5 +- deployment/ccip/deploy_test.go | 2 +- deployment/ccip/test_assertions.go | 11 +- deployment/ccip/test_helpers.go | 51 ++++-- deployment/go.mod | 2 +- deployment/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- .../ccip-tests/testsetups/test_helpers.go | 15 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- .../smoke/ccip_messaging_test.go | 4 +- integration-tests/smoke/ccip_test.go | 4 +- integration-tests/smoke/fee_boosting_test.go | 158 ++++++++++++++++++ 25 files changed, 296 insertions(+), 66 deletions(-) create mode 100644 integration-tests/smoke/fee_boosting_test.go diff --git a/.github/e2e-tests.yml b/.github/e2e-tests.yml index 87e7b07af5b..5c4f7e6c82e 100644 --- a/.github/e2e-tests.yml +++ b/.github/e2e-tests.yml @@ -963,6 +963,20 @@ runner-test-matrix: E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 E2E_JD_VERSION: 0.4.0 + - id: smoke/fee_boosting_test.go:* + path: integration-tests/smoke/fee_boosting_test.go + test_env_type: docker + runs_on: ubuntu-latest + triggers: + - PR E2E Core Tests + - Merge Queue E2E Core Tests + - Nightly E2E Tests + test_cmd: cd integration-tests/ && go test smoke/fee_boosting_test.go -timeout 15m -test.parallel=1 -count=1 -json + pyroscope_env: ci-smoke-ccipv1_6-evm-simulated + test_env_vars: + E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + E2E_JD_VERSION: 0.4.0 + # END: CCIPv1.6 tests # START: CCIP tests diff --git a/core/capabilities/ccip/ccipevm/gas_helpers.go b/core/capabilities/ccip/ccipevm/gas_helpers.go index 52e3d033d2a..2706650f48e 100644 --- a/core/capabilities/ccip/ccipevm/gas_helpers.go +++ b/core/capabilities/ccip/ccipevm/gas_helpers.go @@ -27,6 +27,8 @@ const ( ExecutionStateProcessingOverheadGas = 2_100 + // COLD_SLOAD_COST for first reading the state 20_000 + // SSTORE_SET_GAS for writing from 0 (untouched) to non-zero (in-progress) 100 //# SLOAD_GAS = WARM_STORAGE_READ_COST for rewriting from non-zero (in-progress) to non-zero (success/failure) + // TODO: investigate the write overhead for v1.6 + DestGasOverhead = 110_000 + 110_000 + 130_000 // 110K for commit, 110K for RMN, 130K for Exec ) func NewGasEstimateProvider() EstimateProvider { @@ -61,8 +63,6 @@ func (gp EstimateProvider) CalculateMessageMaxGas(msg cciptypes.Message) uint64 } // CalculateMessageMaxGasWithError computes the maximum gas overhead for a message. -// TODO: Add destGasOverhead, see: -// https://github.com/smartcontractkit/chainlink/blob/23452266132228234312947660374fb393e96f1a/contracts/src/v0.8/ccip/FeeQuoter.sol#L97 func (gp EstimateProvider) CalculateMessageMaxGasWithError(msg cciptypes.Message) (uint64, error) { numTokens := len(msg.TokenAmounts) var data []byte = msg.Data @@ -98,7 +98,8 @@ func (gp EstimateProvider) CalculateMessageMaxGasWithError(msg cciptypes.Message adminRegistryOverhead = TokenAdminRegistryWarmupCost } - return messageGasLimit.Uint64() + + return DestGasOverhead + + messageGasLimit.Uint64() + messageCallDataGas + ExecutionStateProcessingOverheadGas + SupportsInterfaceCheck + diff --git a/core/capabilities/ccip/ccipevm/gas_helpers_test.go b/core/capabilities/ccip/ccipevm/gas_helpers_test.go index bcc87867407..570e7377d34 100644 --- a/core/capabilities/ccip/ccipevm/gas_helpers_test.go +++ b/core/capabilities/ccip/ccipevm/gas_helpers_test.go @@ -26,17 +26,17 @@ func Test_calculateMessageMaxGas(t *testing.T) { { name: "base", args: args{dataLen: 5, numTokens: 2, extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 10}, - want: 1_022_284, + want: 1_372_284, }, { name: "large", args: args{dataLen: 1000, numTokens: 1000, extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 1}, - want: 346_678_520, + want: 347_028_520, }, { name: "overheadGas test 1", args: args{dataLen: 0, numTokens: 0, extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 100}, - want: 319_920, + want: 669_920, }, { name: "overheadGas test 2", @@ -46,7 +46,7 @@ func Test_calculateMessageMaxGas(t *testing.T) { extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 2, }, - want: 675_950, + want: 1_025_950, }, { name: "allowOOO set to true makes no difference to final gas estimate", @@ -56,7 +56,7 @@ func Test_calculateMessageMaxGas(t *testing.T) { extraArgs: makeExtraArgsV2(200_000, true), tokenGasOverhead: 100, }, - want: 1_022_464, + want: 1_372_464, }, { name: "allowOOO set to false makes no difference to final gas estimate", @@ -66,7 +66,7 @@ func Test_calculateMessageMaxGas(t *testing.T) { extraArgs: makeExtraArgsV2(200_000, false), tokenGasOverhead: 100, }, - want: 1_022_464, + want: 1_372_464, }, } @@ -104,7 +104,7 @@ func TestCalculateMaxGas(t *testing.T) { numberOfTokens: 0, extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 10, - want: 322_992, + want: 672_992, }, { name: "maxGasOverheadGas 2", @@ -113,7 +113,7 @@ func TestCalculateMaxGas(t *testing.T) { numberOfTokens: 1, extraArgs: makeExtraArgsV1(200_000), tokenGasOverhead: 10, - want: 678_518, + want: 1_028_518, }, { name: "v2 extra args", @@ -122,7 +122,7 @@ func TestCalculateMaxGas(t *testing.T) { numberOfTokens: 1, extraArgs: makeExtraArgsV2(200_000, true), tokenGasOverhead: 10, - want: 678_518, + want: 1_028_518, }, } diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 028eb9fac9e..12e12a1156e 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -294,7 +294,7 @@ require ( github.com/shirou/gopsutil/v3 v3.24.3 // indirect github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86 // indirect github.com/smartcontractkit/chain-selectors v1.0.29 // indirect - github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b // indirect + github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 // indirect github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f // indirect github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241018134907-a00ba3729b5e // indirect github.com/smartcontractkit/chainlink-feeds v0.1.1 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index bdf3511c482..a123ae602d7 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1092,8 +1092,8 @@ github.com/smartcontractkit/chain-selectors v1.0.29 h1:aZ9+OoUSMn4nqnissHtDvDoKR github.com/smartcontractkit/chain-selectors v1.0.29/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8= github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU= github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b h1:4kmZtaQ4fXwduHnw9xk5VmiIOW4nHg/Mx6iidlZJt5o= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 h1:n3wy96cqxsaJGoCDbFulFPHind6Etq0tiWZcwAnTs3Q= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 h1:2llRW4Tn9W/EZp2XvXclQ9IjeTBwwxVPrrqaerX+vCE= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068/go.mod h1:ny87uTW6hLjCTLiBqBRNFEhETSXhHWevYlPclT5lSco= github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw= diff --git a/deployment/ccip/add_lane.go b/deployment/ccip/add_lane.go index 9d09a56444c..8af96277fc2 100644 --- a/deployment/ccip/add_lane.go +++ b/deployment/ccip/add_lane.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" @@ -14,13 +15,23 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" ) -var ( - InitialLinkPrice = deployment.E18Mult(20) - InitialWethPrice = deployment.E18Mult(4000) - InitialGasPrice = big.NewInt(2e12) -) +type InitialPrices struct { + LinkPrice *big.Int // USD to the power of 18 (e18) per LINK + WethPrice *big.Int // USD to the power of 18 (e18) per WETH + GasPrice *big.Int // uint224 packed gas price in USD (112 for exec // 112 for da) +} + +var DefaultInitialPrices = InitialPrices{ + LinkPrice: deployment.E18Mult(20), + WethPrice: deployment.E18Mult(4000), + GasPrice: ToPackedFee(big.NewInt(8e14), big.NewInt(0)), +} + +func AddLaneWithDefaultPrices(e deployment.Environment, state CCIPOnChainState, from, to uint64) error { + return AddLane(e, state, from, to, DefaultInitialPrices) +} -func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64) error { +func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64, initialPrices InitialPrices) error { // TODO: Batch tx, err := state.Chains[from].Router.ApplyRampUpdates(e.Chains[from].DeployerKey, []router.RouterOnRamp{ { @@ -47,17 +58,17 @@ func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64) TokenPriceUpdates: []fee_quoter.InternalTokenPriceUpdate{ { SourceToken: state.Chains[from].LinkToken.Address(), - UsdPerToken: InitialLinkPrice, + UsdPerToken: initialPrices.LinkPrice, }, { SourceToken: state.Chains[from].Weth9.Address(), - UsdPerToken: InitialWethPrice, + UsdPerToken: initialPrices.WethPrice, }, }, GasPriceUpdates: []fee_quoter.InternalGasPriceUpdate{ { DestChainSelector: to, - UsdPerUnitGas: InitialGasPrice, + UsdPerUnitGas: initialPrices.GasPrice, }, }}) if _, err := deployment.ConfirmIfNoError(e.Chains[from], tx, err); err != nil { @@ -112,15 +123,15 @@ func DefaultFeeQuoterDestChainConfig() fee_quoter.FeeQuoterDestChainConfig { MaxNumberOfTokensPerMsg: 10, MaxDataBytes: 256, MaxPerMsgGasLimit: 3_000_000, - DestGasOverhead: 50_000, + DestGasOverhead: ccipevm.DestGasOverhead, DefaultTokenFeeUSDCents: 1, - DestGasPerPayloadByte: 10, + DestGasPerPayloadByte: ccipevm.CalldataGasPerByte, DestDataAvailabilityOverheadGas: 100, DestGasPerDataAvailabilityByte: 100, DestDataAvailabilityMultiplierBps: 1, DefaultTokenDestGasOverhead: 125_000, DefaultTxGasLimit: 200_000, - GasMultiplierWeiPerEth: 1, + GasMultiplierWeiPerEth: 11e17, // Gas multiplier in wei per eth is scaled by 1e18, so 11e17 is 1.1 = 110% NetworkFeeUSDCents: 1, ChainFamilySelector: [4]byte(evmFamilySelector), } diff --git a/deployment/ccip/add_lane_test.go b/deployment/ccip/add_lane_test.go index 1d7ab18bf34..5edfdae1ab0 100644 --- a/deployment/ccip/add_lane_test.go +++ b/deployment/ccip/add_lane_test.go @@ -64,7 +64,7 @@ func TestAddLane(t *testing.T) { require.NoError(t, err) // Add one lane from chain1 to chain 2 and send traffic. - require.NoError(t, AddLane(e.Env, state, chain1, chain2)) + require.NoError(t, AddLaneWithDefaultPrices(e.Env, state, chain1, chain2)) ReplayLogs(t, e.Env.Offchain, replayBlocks) time.Sleep(30 * time.Second) @@ -110,7 +110,7 @@ func TestAddLane(t *testing.T) { require.Equal(t, uint64(1), msgSentEvent1.SequenceNumber) // Add another lane - require.NoError(t, AddLane(e.Env, state, chain2, chain1)) + require.NoError(t, AddLaneWithDefaultPrices(e.Env, state, chain2, chain1)) // Send traffic on the second lane and it should succeed latesthdr, err = e.Env.Chains[chain1].Client.HeaderByNumber(testcontext.Get(t), nil) diff --git a/deployment/ccip/changeset/active_candidate_test.go b/deployment/ccip/changeset/active_candidate_test.go index c64f7bf8c9f..6403981a675 100644 --- a/deployment/ccip/changeset/active_candidate_test.go +++ b/deployment/ccip/changeset/active_candidate_test.go @@ -28,7 +28,7 @@ func TestActiveCandidate(t *testing.T) { lggr := logger.TestLogger(t) ctx := ccdeploy.Context(t) - tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 5) + tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 5, ccdeploy.MockLinkPrice, ccdeploy.MockWethPrice) e := tenv.Env state, err := ccdeploy.LoadOnchainState(tenv.Env) diff --git a/deployment/ccip/changeset/add_chain_test.go b/deployment/ccip/changeset/add_chain_test.go index 51972c6dd2e..2d79a76005d 100644 --- a/deployment/ccip/changeset/add_chain_test.go +++ b/deployment/ccip/changeset/add_chain_test.go @@ -60,7 +60,7 @@ func TestAddChainInbound(t *testing.T) { for _, source := range initialDeploy { for _, dest := range initialDeploy { if source != dest { - require.NoError(t, ccipdeployment.AddLane(e.Env, state, source, dest)) + require.NoError(t, ccipdeployment.AddLaneWithDefaultPrices(e.Env, state, source, dest)) } } } diff --git a/deployment/ccip/changeset/initial_deploy_test.go b/deployment/ccip/changeset/initial_deploy_test.go index 0d43a78b878..a3756022245 100644 --- a/deployment/ccip/changeset/initial_deploy_test.go +++ b/deployment/ccip/changeset/initial_deploy_test.go @@ -21,7 +21,7 @@ import ( func TestInitialDeploy(t *testing.T) { lggr := logger.TestLogger(t) ctx := ccdeploy.Context(t) - tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 4) + tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 4, ccdeploy.MockLinkPrice, ccdeploy.MockWethPrice) e := tenv.Env state, err := ccdeploy.LoadOnchainState(tenv.Env) @@ -93,7 +93,8 @@ func TestInitialDeploy(t *testing.T) { ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) // Confirm token and gas prices are updated - ccdeploy.ConfirmTokenPriceUpdatedForAll(t, e, state, startBlocks) + ccdeploy.ConfirmTokenPriceUpdatedForAll(t, e, state, startBlocks, + ccdeploy.DefaultInitialPrices.LinkPrice, ccdeploy.DefaultInitialPrices.WethPrice) // TODO: Fix gas prices? //ccdeploy.ConfirmGasPriceUpdatedForAll(t, e, state, startBlocks) // diff --git a/deployment/ccip/deploy_test.go b/deployment/ccip/deploy_test.go index f32dd63f806..dc1927261d1 100644 --- a/deployment/ccip/deploy_test.go +++ b/deployment/ccip/deploy_test.go @@ -22,7 +22,7 @@ func TestDeployCCIPContracts(t *testing.T) { }) // Deploy all the CCIP contracts. homeChainSel, feedChainSel := allocateCCIPChainSelectors(e.Chains) - _ = DeployTestContracts(t, lggr, e.ExistingAddresses, homeChainSel, feedChainSel, e.Chains) + _ = DeployTestContracts(t, lggr, e.ExistingAddresses, homeChainSel, feedChainSel, e.Chains, MockLinkPrice, MockWethPrice) nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) diff --git a/deployment/ccip/test_assertions.go b/deployment/ccip/test_assertions.go index 64d1eb8571c..0c15c8b95ed 100644 --- a/deployment/ccip/test_assertions.go +++ b/deployment/ccip/test_assertions.go @@ -27,6 +27,7 @@ func ConfirmGasPriceUpdatedForAll( e deployment.Environment, state CCIPOnChainState, startBlocks map[uint64]*uint64, + gasPrice *big.Int, ) { var wg errgroup.Group for src, srcChain := range e.Chains { @@ -46,6 +47,7 @@ func ConfirmGasPriceUpdatedForAll( dstChain, state.Chains[srcChain.Selector].FeeQuoter, *startBlock, + gasPrice, ) }) } @@ -58,6 +60,7 @@ func ConfirmGasPriceUpdated( dest deployment.Chain, srcFeeQuoter *fee_quoter.FeeQuoter, startBlock uint64, + gasPrice *big.Int, ) error { it, err := srcFeeQuoter.FilterUsdPerUnitGasUpdated(&bind.FilterOpts{ Context: context.Background(), @@ -67,7 +70,7 @@ func ConfirmGasPriceUpdated( require.NoError(t, err) require.Truef(t, it.Next(), "No gas price update event found on chain %d, fee quoter %s", dest.Selector, srcFeeQuoter.Address().String()) - require.NotEqualf(t, InitialGasPrice, it.Event.Value, "Gas price not updated on chain %d, fee quoter %s", + require.NotEqualf(t, gasPrice, it.Event.Value, "Gas price not updated on chain %d, fee quoter %s", dest.Selector, srcFeeQuoter.Address().String()) return nil } @@ -77,6 +80,8 @@ func ConfirmTokenPriceUpdatedForAll( e deployment.Environment, state CCIPOnChainState, startBlocks map[uint64]*uint64, + linkPrice *big.Int, + wethPrice *big.Int, ) { var wg errgroup.Group for _, chain := range e.Chains { @@ -89,8 +94,8 @@ func ConfirmTokenPriceUpdatedForAll( linkAddress := state.Chains[chain.Selector].LinkToken.Address() wethAddress := state.Chains[chain.Selector].Weth9.Address() tokenToPrice := make(map[common.Address]*big.Int) - tokenToPrice[linkAddress] = InitialLinkPrice - tokenToPrice[wethAddress] = InitialWethPrice + tokenToPrice[linkAddress] = linkPrice + tokenToPrice[wethAddress] = wethPrice return ConfirmTokenPriceUpdated( t, chain, diff --git a/deployment/ccip/test_helpers.go b/deployment/ccip/test_helpers.go index 9d6ac0ab35d..4c348f46920 100644 --- a/deployment/ccip/test_helpers.go +++ b/deployment/ccip/test_helpers.go @@ -120,6 +120,8 @@ func DeployTestContracts(t *testing.T, homeChainSel, feedChainSel uint64, chains map[uint64]deployment.Chain, + linkPrice *big.Int, + wethPrice *big.Int, ) deployment.CapabilityRegistryConfig { capReg, err := DeployCapReg(lggr, // deploying cap reg for the first time on a blank chain state @@ -127,7 +129,7 @@ func DeployTestContracts(t *testing.T, Chains: make(map[uint64]CCIPChainState), }, ab, chains[homeChainSel]) require.NoError(t, err) - _, err = DeployFeeds(lggr, ab, chains[feedChainSel]) + _, err = DeployFeeds(lggr, ab, chains[feedChainSel], linkPrice, wethPrice) require.NoError(t, err) evmChainID, err := chainsel.ChainIdFromSelector(homeChainSel) require.NoError(t, err) @@ -166,7 +168,13 @@ func allocateCCIPChainSelectors(chains map[uint64]deployment.Chain) (homeChainSe // NewMemoryEnvironment creates a new CCIP environment // with capreg, fee tokens, feeds and nodes set up. -func NewMemoryEnvironment(t *testing.T, lggr logger.Logger, numChains int, numNodes int) DeployedEnv { +func NewMemoryEnvironment( + t *testing.T, + lggr logger.Logger, + numChains int, + numNodes int, + linkPrice *big.Int, + wethPrice *big.Int) DeployedEnv { require.GreaterOrEqual(t, numChains, 2, "numChains must be at least 2 for home and feed chains") require.GreaterOrEqual(t, numNodes, 4, "numNodes must be at least 4") ctx := testcontext.Get(t) @@ -176,7 +184,7 @@ func NewMemoryEnvironment(t *testing.T, lggr logger.Logger, numChains int, numNo require.NoError(t, err) ab := deployment.NewMemoryAddressBook() - crConfig := DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains) + crConfig := DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains, linkPrice, wethPrice) nodes := memory.NewNodes(t, zapcore.InfoLevel, chains, numNodes, 1, crConfig) for _, node := range nodes { require.NoError(t, node.App.Start(ctx)) @@ -209,7 +217,19 @@ func NewMemoryEnvironment(t *testing.T, lggr logger.Logger, numChains int, numNo // NewMemoryEnvironmentWithJobs creates a new CCIP environment // with capreg, fee tokens, feeds, nodes and jobs set up. func NewMemoryEnvironmentWithJobs(t *testing.T, lggr logger.Logger, numChains int, numNodes int) DeployedEnv { - e := NewMemoryEnvironment(t, lggr, numChains, numNodes) + e := NewMemoryEnvironment(t, lggr, numChains, numNodes, MockLinkPrice, MockWethPrice) + e.SetupJobs(t) + return e +} + +func NewMemoryEnvironmentWithJobsAndPrices( + t *testing.T, + lggr logger.Logger, + numChains int, + numNodes int, + linkPrice *big.Int, + wethPrice *big.Int) DeployedEnv { + e := NewMemoryEnvironment(t, lggr, numChains, numNodes, linkPrice, wethPrice) e.SetupJobs(t) return e } @@ -323,7 +343,7 @@ func AddLanesForAll(e deployment.Environment, state CCIPOnChainState) error { for source := range e.Chains { for dest := range e.Chains { if source != dest { - err := AddLane(e, state, source, dest) + err := AddLaneWithDefaultPrices(e, state, source, dest) if err != nil { return err } @@ -333,6 +353,11 @@ func AddLanesForAll(e deployment.Environment, state CCIPOnChainState) error { return nil } +func ToPackedFee(execFee, daFee *big.Int) *big.Int { + daShifted := new(big.Int).Lsh(daFee, 112) + return new(big.Int).Or(daShifted, execFee) +} + const ( // MockLinkAggregatorDescription This is the description of the MockV3Aggregator.sol contract // nolint:lll @@ -345,7 +370,7 @@ const ( ) var ( - MockLinkPrice = big.NewInt(5e18) + MockLinkPrice = deployment.E18Mult(500) MockWethPrice = big.NewInt(9e8) // MockDescriptionToTokenSymbol maps a mock feed description to token descriptor MockDescriptionToTokenSymbol = map[string]TokenSymbol{ @@ -362,14 +387,20 @@ var ( } ) -func DeployFeeds(lggr logger.Logger, ab deployment.AddressBook, chain deployment.Chain) (map[string]common.Address, error) { +func DeployFeeds( + lggr logger.Logger, + ab deployment.AddressBook, + chain deployment.Chain, + linkPrice *big.Int, + wethPrice *big.Int, +) (map[string]common.Address, error) { linkTV := deployment.NewTypeAndVersion(PriceFeed, deployment.Version1_0_0) mockLinkFeed := func(chain deployment.Chain) deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface] { linkFeed, tx, _, err1 := mock_v3_aggregator_contract.DeployMockV3Aggregator( chain.DeployerKey, chain.Client, - LinkDecimals, // decimals - MockLinkPrice, // initialAnswer + LinkDecimals, // decimals + linkPrice, // initialAnswer ) aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(linkFeed, chain.Client) @@ -382,7 +413,7 @@ func DeployFeeds(lggr logger.Logger, ab deployment.AddressBook, chain deployment wethFeed, tx, _, err1 := mock_ethusd_aggregator_wrapper.DeployMockETHUSDAggregator( chain.DeployerKey, chain.Client, - MockWethPrice, // initialAnswer + wethPrice, // initialAnswer ) aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(wethFeed, chain.Client) diff --git a/deployment/go.mod b/deployment/go.mod index ed05d136993..6963180766e 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -22,7 +22,7 @@ require ( github.com/sethvargo/go-retry v0.2.4 github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86 github.com/smartcontractkit/chain-selectors v1.0.29 - github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b + github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 github.com/smartcontractkit/chainlink-protos/job-distributor v0.4.0 github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.13 diff --git a/deployment/go.sum b/deployment/go.sum index 6c372de39f2..66487c2f9bc 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1382,8 +1382,8 @@ github.com/smartcontractkit/chain-selectors v1.0.29 h1:aZ9+OoUSMn4nqnissHtDvDoKR github.com/smartcontractkit/chain-selectors v1.0.29/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8= github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU= github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b h1:4kmZtaQ4fXwduHnw9xk5VmiIOW4nHg/Mx6iidlZJt5o= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 h1:n3wy96cqxsaJGoCDbFulFPHind6Etq0tiWZcwAnTs3Q= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 h1:2llRW4Tn9W/EZp2XvXclQ9IjeTBwwxVPrrqaerX+vCE= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068/go.mod h1:ny87uTW6hLjCTLiBqBRNFEhETSXhHWevYlPclT5lSco= github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw= diff --git a/go.mod b/go.mod index d9a65c16063..7655e472f7a 100644 --- a/go.mod +++ b/go.mod @@ -76,7 +76,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.29 github.com/smartcontractkit/chainlink-automation v0.8.1 - github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b + github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241018134907-a00ba3729b5e diff --git a/go.sum b/go.sum index 885518d69aa..016997e62f5 100644 --- a/go.sum +++ b/go.sum @@ -1076,8 +1076,8 @@ github.com/smartcontractkit/chain-selectors v1.0.29 h1:aZ9+OoUSMn4nqnissHtDvDoKR github.com/smartcontractkit/chain-selectors v1.0.29/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8= github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU= github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b h1:4kmZtaQ4fXwduHnw9xk5VmiIOW4nHg/Mx6iidlZJt5o= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 h1:n3wy96cqxsaJGoCDbFulFPHind6Etq0tiWZcwAnTs3Q= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 h1:2llRW4Tn9W/EZp2XvXclQ9IjeTBwwxVPrrqaerX+vCE= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068/go.mod h1:ny87uTW6hLjCTLiBqBRNFEhETSXhHWevYlPclT5lSco= github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw= diff --git a/integration-tests/ccip-tests/testsetups/test_helpers.go b/integration-tests/ccip-tests/testsetups/test_helpers.go index 4de5d0988a2..eeae7f5f8c3 100644 --- a/integration-tests/ccip-tests/testsetups/test_helpers.go +++ b/integration-tests/ccip-tests/testsetups/test_helpers.go @@ -69,7 +69,16 @@ func (d DeployedLocalDevEnvironment) RestartChainlinkNodes(t *testing.T) error { return errGrp.Wait() } -func NewLocalDevEnvironment(t *testing.T, lggr logger.Logger) (ccipdeployment.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { +func NewLocalDevEnvironmentWithDefaultPrice( + t *testing.T, + lggr logger.Logger) (ccipdeployment.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { + return NewLocalDevEnvironment(t, lggr, ccipdeployment.MockLinkPrice, ccipdeployment.MockWethPrice) +} + +func NewLocalDevEnvironment( + t *testing.T, + lggr logger.Logger, + linkPrice, wethPrice *big.Int) (ccipdeployment.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { ctx := testcontext.Get(t) // create a local docker environment with simulated chains and job-distributor // we cannot create the chainlink nodes yet as we need to deploy the capability registry first @@ -88,7 +97,7 @@ func NewLocalDevEnvironment(t *testing.T, lggr logger.Logger) (ccipdeployment.De require.NoError(t, err) ab := deployment.NewMemoryAddressBook() - crConfig := ccipdeployment.DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains) + crConfig := ccipdeployment.DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains, linkPrice, wethPrice) // start the chainlink nodes with the CR address err = StartChainlinkNodes(t, envConfig, @@ -128,7 +137,7 @@ func NewLocalDevEnvironmentWithRMN( lggr logger.Logger, numRmnNodes int, ) (ccipdeployment.DeployedEnv, devenv.RMNCluster) { - tenv, dockerenv, _ := NewLocalDevEnvironment(t, lggr) + tenv, dockerenv, _ := NewLocalDevEnvironmentWithDefaultPrice(t, lggr) state, err := ccipdeployment.LoadOnchainState(tenv.Env) require.NoError(t, err) diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 2a8d9eebf07..9e07bd4f7cb 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -413,7 +413,7 @@ require ( github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86 // indirect - github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b // indirect + github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 // indirect github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f // indirect github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241018134907-a00ba3729b5e // indirect github.com/smartcontractkit/chainlink-feeds v0.1.1 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 5a4bcb648cd..5635684b688 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1403,8 +1403,8 @@ github.com/smartcontractkit/chain-selectors v1.0.29 h1:aZ9+OoUSMn4nqnissHtDvDoKR github.com/smartcontractkit/chain-selectors v1.0.29/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8= github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU= github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b h1:4kmZtaQ4fXwduHnw9xk5VmiIOW4nHg/Mx6iidlZJt5o= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 h1:n3wy96cqxsaJGoCDbFulFPHind6Etq0tiWZcwAnTs3Q= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 h1:2llRW4Tn9W/EZp2XvXclQ9IjeTBwwxVPrrqaerX+vCE= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068/go.mod h1:ny87uTW6hLjCTLiBqBRNFEhETSXhHWevYlPclT5lSco= github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 7398abc5af9..30cdab1097d 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -65,7 +65,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b // indirect + github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 // indirect github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f // indirect github.com/smartcontractkit/chainlink-testing-framework/havoc v1.50.2 // indirect github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 6ca863f3d08..b4eaf20b15b 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1392,8 +1392,8 @@ github.com/smartcontractkit/chain-selectors v1.0.29 h1:aZ9+OoUSMn4nqnissHtDvDoKR github.com/smartcontractkit/chain-selectors v1.0.29/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8= github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU= github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b h1:4kmZtaQ4fXwduHnw9xk5VmiIOW4nHg/Mx6iidlZJt5o= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20241112095015-3e85d9f1898b/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436 h1:n3wy96cqxsaJGoCDbFulFPHind6Etq0tiWZcwAnTs3Q= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20241115103032-ec39846b3436/go.mod h1:4adKaHNaxFsRvV/lYfqtbsWyyvIPUMLR0FdOJN/ljis= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068 h1:2llRW4Tn9W/EZp2XvXclQ9IjeTBwwxVPrrqaerX+vCE= github.com/smartcontractkit/chainlink-common v0.3.1-0.20241114134822-aadff98ef068/go.mod h1:ny87uTW6hLjCTLiBqBRNFEhETSXhHWevYlPclT5lSco= github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f h1:BwrIaQIx5Iy6eT+DfLhFfK2XqjxRm74mVdlX8gbu4dw= diff --git a/integration-tests/smoke/ccip_messaging_test.go b/integration-tests/smoke/ccip_messaging_test.go index a070d7b0061..4aa9ba34229 100644 --- a/integration-tests/smoke/ccip_messaging_test.go +++ b/integration-tests/smoke/ccip_messaging_test.go @@ -51,7 +51,7 @@ func Test_CCIPMessaging(t *testing.T) { // Setup 2 chains and a single lane. lggr := logger.TestLogger(t) ctx := ccdeploy.Context(t) - e, _, _ := testsetups.NewLocalDevEnvironment(t, lggr) + e, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) state, err := ccdeploy.LoadOnchainState(e.Env) require.NoError(t, err) @@ -105,7 +105,7 @@ func Test_CCIPMessaging(t *testing.T) { } // connect a single lane, source to dest - require.NoError(t, ccdeploy.AddLane(e.Env, state, sourceChain, destChain)) + require.NoError(t, ccdeploy.AddLaneWithDefaultPrices(e.Env, state, sourceChain, destChain)) var ( replayed bool diff --git a/integration-tests/smoke/ccip_test.go b/integration-tests/smoke/ccip_test.go index b063b26ae8d..007a3c37e52 100644 --- a/integration-tests/smoke/ccip_test.go +++ b/integration-tests/smoke/ccip_test.go @@ -22,7 +22,7 @@ func TestInitialDeployOnLocal(t *testing.T) { t.Parallel() lggr := logger.TestLogger(t) ctx := ccdeploy.Context(t) - tenv, _, _ := testsetups.NewLocalDevEnvironment(t, lggr) + tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) e := tenv.Env state, err := ccdeploy.LoadOnchainState(tenv.Env) @@ -114,7 +114,7 @@ func TestTokenTransfer(t *testing.T) { t.Parallel() lggr := logger.TestLogger(t) ctx := ccdeploy.Context(t) - tenv, _, _ := testsetups.NewLocalDevEnvironment(t, lggr) + tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) e := tenv.Env state, err := ccdeploy.LoadOnchainState(e) diff --git a/integration-tests/smoke/fee_boosting_test.go b/integration-tests/smoke/fee_boosting_test.go new file mode 100644 index 00000000000..625200360e8 --- /dev/null +++ b/integration-tests/smoke/fee_boosting_test.go @@ -0,0 +1,158 @@ +package smoke + +import ( + "math/big" + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/test-go/testify/require" + "golang.org/x/exp/maps" + + jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job" + "github.com/smartcontractkit/chainlink/deployment" + ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" + "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testsetups" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" + "github.com/smartcontractkit/chainlink/v2/core/logger" +) + +type feeboostTestCase struct { + t *testing.T + sender []byte + deployedEnv ccdeploy.DeployedEnv + onchainState ccdeploy.CCIPOnChainState + initialPrices ccdeploy.InitialPrices + priceFeedPrices priceFeedPrices + sourceChain, destChain uint64 +} + +type priceFeedPrices struct { + linkPrice *big.Int + wethPrice *big.Int +} + +// TODO: find a way to reuse the same test setup for all tests +func Test_CCIPFeeBoosting(t *testing.T) { + ctx := ccdeploy.Context(t) + + setupTestEnv := func(t *testing.T, numChains int) (ccdeploy.DeployedEnv, ccdeploy.CCIPOnChainState, []uint64) { + e, _, _ := testsetups.NewLocalDevEnvironment( + t, logger.TestLogger(t), + deployment.E18Mult(5), + big.NewInt(9e8)) + + state, err := ccdeploy.LoadOnchainState(e.Env) + require.NoError(t, err) + + allChainSelectors := maps.Keys(e.Env.Chains) + require.Len(t, allChainSelectors, numChains) + + output, err := changeset.DeployPrerequisites(e.Env, changeset.DeployPrerequisiteConfig{ + ChainSelectors: e.Env.AllChainSelectors(), + }) + require.NoError(t, err) + require.NoError(t, e.Env.ExistingAddresses.Merge(output.AddressBook)) + + tokenConfig := ccdeploy.NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds) + // Apply migration + output, err = changeset.InitialDeploy(e.Env, ccdeploy.DeployCCIPContractConfig{ + HomeChainSel: e.HomeChainSel, + FeedChainSel: e.FeedChainSel, + ChainsToDeploy: allChainSelectors, + TokenConfig: tokenConfig, + MCMSConfig: ccdeploy.NewTestMCMSConfig(t, e.Env), + OCRSecrets: deployment.XXXGenerateTestOCRSecrets(), + }) + require.NoError(t, err) + require.NoError(t, e.Env.ExistingAddresses.Merge(output.AddressBook)) + state, err = ccdeploy.LoadOnchainState(e.Env) + require.NoError(t, err) + + // Ensure capreg logs are up to date. + ccdeploy.ReplayLogs(t, e.Env.Offchain, e.ReplayBlocks) + + // Apply the jobs. + for nodeID, jobs := range output.JobSpecs { + for _, job := range jobs { + // Note these auto-accept + _, err := e.Env.Offchain.ProposeJob(ctx, + &jobv1.ProposeJobRequest{ + NodeId: nodeID, + Spec: job, + }) + require.NoError(t, err) + } + } + + return e, state, allChainSelectors + } + + t.Run("boost needed due to WETH price increase (also covering gas price inscrease)", func(t *testing.T) { + e, state, chains := setupTestEnv(t, 2) + runFeeboostTestCase(feeboostTestCase{ + t: t, + sender: common.LeftPadBytes(e.Env.Chains[chains[0]].DeployerKey.From.Bytes(), 32), + deployedEnv: e, + onchainState: state, + initialPrices: ccdeploy.InitialPrices{ + LinkPrice: deployment.E18Mult(5), + WethPrice: deployment.E18Mult(9), + GasPrice: ccdeploy.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), + }, + priceFeedPrices: priceFeedPrices{ + linkPrice: deployment.E18Mult(5), + wethPrice: big.NewInt(9.9e8), // increase from 9e8 to 9.9e8 + }, + sourceChain: chains[0], + destChain: chains[1], + }) + }) + + t.Run("boost needed due to LINK price decrease", func(t *testing.T) { + e, state, chains := setupTestEnv(t, 2) + runFeeboostTestCase(feeboostTestCase{ + t: t, + sender: common.LeftPadBytes(e.Env.Chains[chains[0]].DeployerKey.From.Bytes(), 32), + deployedEnv: e, + onchainState: state, + initialPrices: ccdeploy.InitialPrices{ + LinkPrice: deployment.E18Mult(5), + WethPrice: deployment.E18Mult(9), + GasPrice: ccdeploy.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), + }, + priceFeedPrices: priceFeedPrices{ + linkPrice: big.NewInt(4.5e18), // decrease from 5e18 to 4.5e18 + wethPrice: big.NewInt(9e8), + }, + sourceChain: chains[0], + destChain: chains[1], + }) + }) +} + +func runFeeboostTestCase(tc feeboostTestCase) { + require.NoError(tc.t, ccdeploy.AddLane(tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, tc.initialPrices)) + + startBlocks := make(map[uint64]*uint64) + expectedSeqNum := make(map[uint64]uint64) + msgSentEvent := ccdeploy.TestSendRequest(tc.t, tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, false, router.ClientEVM2AnyMessage{ + Receiver: common.LeftPadBytes(tc.onchainState.Chains[tc.destChain].Receiver.Address().Bytes(), 32), + Data: []byte("message that needs fee boosting"), + TokenAmounts: nil, + FeeToken: common.HexToAddress("0x0"), + ExtraArgs: nil, + }) + expectedSeqNum[tc.destChain] = msgSentEvent.SequenceNumber + + // hack + time.Sleep(30 * time.Second) + replayBlocks := make(map[uint64]uint64) + replayBlocks[tc.sourceChain] = 1 + replayBlocks[tc.destChain] = 1 + ccdeploy.ReplayLogs(tc.t, tc.deployedEnv.Env.Offchain, replayBlocks) + + ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) + ccdeploy.ConfirmExecWithSeqNrForAll(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) +}