Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
Browse files Browse the repository at this point in the history
…crib-352/ccip-v2-integration-tests
  • Loading branch information
scheibinger committed Jan 21, 2025
2 parents 2aa85a1 + c430b5b commit 6f04719
Show file tree
Hide file tree
Showing 41 changed files with 819 additions and 178 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-nails-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#added core configs
2 changes: 1 addition & 1 deletion .github/actions/golangci-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ inputs:
outputs:
golang-report-artifact-url:
description: The URL to the uploaded artifact
value: ${{ steps.upload-artifact.outputs.artifact_url }}
value: ${{ steps.upload-artifact.outputs.artifact-url }}

runs:
using: composite
Expand Down
3 changes: 3 additions & 0 deletions ccip/config/evm/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ResendAfterThreshold = '1m'
[Transactions.AutoPurge]
Enabled = false

[Transactions.TransactionManagerV2]
Enabled = false

[BalanceMonitor]
Enabled = true

Expand Down
10 changes: 10 additions & 0 deletions contracts/.changeset/soft-glasses-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainlink/contracts': patch
---

#internal fix missing case in gas estimation logic


PR issue: CCIP-4919

Solidity Review issue: CCIP-3966
10 changes: 10 additions & 0 deletions contracts/.changeset/wicked-maps-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainlink/contracts': minor
---

#internal Add EVM extraArgs encode & decode to MessageHasher

PR issue: CCIP-4918


Solidity Review issue: CCIP-3966
13 changes: 6 additions & 7 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ OffRamp_commit:test_ReportOnlyRootSuccess_gas() (gas: 141051)
OffRamp_commit:test_RootWithRMNDisabled() (gas: 153873)
OffRamp_commit:test_StaleReportWithRoot() (gas: 232057)
OffRamp_commit:test_ValidPriceUpdateThenStaleReportWithRoot() (gas: 206700)
OffRamp_constructor:test_Constructor() (gas: 6311247)
OffRamp_constructor:test_Constructor() (gas: 6322677)
OffRamp_execute:test_LargeBatch() (gas: 3373860)
OffRamp_execute:test_MultipleReports() (gas: 291458)
OffRamp_execute:test_MultipleReportsWithPartialValidationFailures() (gas: 364826)
Expand Down Expand Up @@ -278,13 +278,12 @@ OffRamp_releaseOrMintTokens:test_releaseOrMintTokens_WithGasOverride() (gas: 163
OffRamp_releaseOrMintTokens:test_releaseOrMintTokens_destDenominatedDecimals() (gas: 174276)
OffRamp_setDynamicConfig:test_SetDynamicConfig() (gas: 25442)
OffRamp_setDynamicConfig:test_SetDynamicConfigWithInterceptor() (gas: 47493)
OffRamp_trialExecute:test_trialExecute() (gas: 263614)
OffRamp_trialExecute:test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() (gas: 24490)
OffRamp_trialExecute:test_trialExecute() (gas: 263680)
OffRamp_trialExecute:test_trialExecute_RateLimitError() (gas: 120710)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() (gas: 29391)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() (gas: 29539)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 131932)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 281327)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_SenderIsGasEstimator_InsufficientGasForToCompleteTx() (gas: 67132)
OffRamp_trialExecute:test_trialExecute_SenderIsNotGasEstimator_CallWithExactGasReverts() (gas: 24573)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 131998)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 281305)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy() (gas: 245406)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates() (gas: 325996)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 17190)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/ocr/MultiOCR3Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract contract MultiOCR3Base is ITypeAndVersion, Ownable2StepMsgSender {
error NonUniqueSignatures();
error OracleCannotBeZeroAddress();
error StaticConfigCannotBeChanged(uint8 ocrPluginType);
error InsufficientGasForCallWithExact();
error InsufficientGasToCompleteTx(bytes4 err);

/// @dev Packing these fields used on the hot path in a ConfigInfo variable reduces the retrieval of all
/// of them to a minimum number of SLOADs.
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
if (
CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG == bytes4(err)
|| CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG == bytes4(err)
|| ERC165CheckerReverting.InsufficientGasForStaticCall.selector == bytes4(err)
) {
revert InsufficientGasForCallWithExact();
revert InsufficientGasToCompleteTx(bytes4(err));
}
}
// return the message execution state as FAILURE and the revert data.
Expand Down
24 changes: 23 additions & 1 deletion contracts/src/v0.8/ccip/test/helpers/MessageHasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ contract MessageHasher {
uint256 gasLimit,
bool allowOutOfOrderExecution
) public pure returns (Client.EVMExtraArgsV2 memory) {
return Client.EVMExtraArgsV2(gasLimit, allowOutOfOrderExecution);
return Client.EVMExtraArgsV2({gasLimit: gasLimit, allowOutOfOrderExecution: allowOutOfOrderExecution});
}

function encodeSVMExtraArgsV1(
Client.SVMExtraArgsV1 memory extraArgs
) public pure returns (bytes memory) {
return Client._svmArgsToBytes(extraArgs);
}

function decodeSVMExtraArgsV1(
uint32 computeUnits,
uint64 accountIsWritableBitmap,
bool allowOutOfOrderExecution,
bytes32 tokenReceiver,
bytes32[] memory accounts
) public pure returns (Client.SVMExtraArgsV1 memory) {
return Client.SVMExtraArgsV1({
computeUnits: computeUnits,
accountIsWritableBitmap: accountIsWritableBitmap,
allowOutOfOrderExecution: allowOutOfOrderExecution,
tokenReceiver: tokenReceiver,
accounts: accounts
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.24;

import {CallWithExactGas} from "../../../../shared/call/CallWithExactGas.sol";
import {ERC165CheckerReverting} from "../../../libraries/ERC165CheckerReverting.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {MultiOCR3Base} from "../../../ocr/MultiOCR3Base.sol";
Expand Down Expand Up @@ -120,58 +121,46 @@ contract OffRamp_trialExecute is OffRampSetup {
assertEq(abi.encodeWithSelector(OffRamp.NotACompatiblePool.selector, address(0)), err);
}

function test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() public {
function test_trialExecute_SenderIsNotGasEstimator_CallWithExactGasReverts() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, new uint32[](0))),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);

(Internal.MessageExecutionState newState, bytes memory err) =
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
s_offRamp.trialExecute(message, offchainTokenData, new uint32[](0));
assertEq(uint256(Internal.MessageExecutionState.FAILURE), uint256(newState));
assertEq(CallWithExactGas.NotEnoughGasForCall.selector, bytes4(err));
}

function test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeWithSelector(CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG, "")
);
function test_trialExecute_RevertsWhen_SenderIsGasEstimator_InsufficientGasForToCompleteTx() public {
bytes4[3] memory sigs = [
CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG,
CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG,
ERC165CheckerReverting.InsufficientGasForStaticCall.selector
];

changePrank(Internal.GAS_ESTIMATION_SENDER);
vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
}

function test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);
for (uint256 i = 0; i < sigs.length; ++i) {
vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, new uint32[](0))),
abi.encodeWithSelector(sigs[i])
);

changePrank(Internal.GAS_ESTIMATION_SENDER);

changePrank(Internal.GAS_ESTIMATION_SENDER);
vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
vm.expectRevert(abi.encodeWithSelector(MultiOCR3Base.InsufficientGasToCompleteTx.selector, sigs[i]));
s_offRamp.trialExecute(message, offchainTokenData, new uint32[](0));
}
}
}
33 changes: 26 additions & 7 deletions core/capabilities/compute/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,33 @@ func (c *Compute) createFetcher() func(ctx context.Context, req *wasmpb.FetchReq
}

const (
defaultNumWorkers = 3
defaultNumWorkers = 3
defaultMaxMemoryMBs = 128
defaultMaxTickInterval = 100 * time.Millisecond
defaultMaxTimeout = 10 * time.Second
)

type Config struct {
webapi.ServiceConfig
NumWorkers int
NumWorkers int
MaxMemoryMBs uint64
MaxTimeout time.Duration
MaxTickInterval time.Duration
}

func (c *Config) ApplyDefaults() {
if c.NumWorkers == 0 {
c.NumWorkers = defaultNumWorkers
}
if c.MaxMemoryMBs == 0 {
c.MaxMemoryMBs = defaultMaxMemoryMBs
}
if c.MaxTimeout == 0 {
c.MaxTimeout = defaultMaxTimeout
}
if c.MaxTickInterval == 0 {
c.MaxTickInterval = defaultMaxTickInterval
}
}

func NewAction(
Expand All @@ -376,9 +397,7 @@ func NewAction(
idGenerator func() string,
opts ...func(*Compute),
) (*Compute, error) {
if config.NumWorkers == 0 {
config.NumWorkers = defaultNumWorkers
}
config.ApplyDefaults()
metricsLabeler, err := newComputeMetricsLabeler(metrics.NewLabeler().With("capability", CapabilityIDCompute))
if err != nil {
return nil, fmt.Errorf("failed to create compute metrics labeler: %w", err)
Expand All @@ -393,11 +412,11 @@ func NewAction(
metrics: metricsLabeler,
registry: registry,
modules: newModuleCache(clockwork.NewRealClock(), 1*time.Minute, 10*time.Minute, 3),
transformer: NewTransformer(lggr, labeler),
transformer: NewTransformer(lggr, labeler, config),
outgoingConnectorHandler: handler,
idGenerator: idGenerator,
queue: make(chan request),
numWorkers: defaultNumWorkers,
numWorkers: config.NumWorkers,
}
)

Expand Down
21 changes: 19 additions & 2 deletions core/capabilities/compute/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ParsedConfig struct {
type transformer struct {
logger logger.Logger
emitter custmsg.MessageEmitter
config Config
}

func shallowCopy(m *values.Map) *values.Map {
Expand Down Expand Up @@ -60,11 +61,15 @@ func (t *transformer) Transform(req capabilities.CapabilityRequest, opts ...func
return capabilities.CapabilityRequest{}, nil, NewInvalidRequestError(err)
}

maxMemoryMBs, err := popOptionalValue[int64](copiedReq.Config, maxMemoryMBsKey)
maxMemoryMBs, err := popOptionalValue[uint64](copiedReq.Config, maxMemoryMBsKey)
if err != nil {
return capabilities.CapabilityRequest{}, nil, NewInvalidRequestError(err)
}

if maxMemoryMBs <= 0 || maxMemoryMBs > t.config.MaxMemoryMBs {
maxMemoryMBs = t.config.MaxMemoryMBs
}

mc := &host.ModuleConfig{
MaxMemoryMBs: maxMemoryMBs,
Logger: t.logger,
Expand All @@ -82,9 +87,16 @@ func (t *transformer) Transform(req capabilities.CapabilityRequest, opts ...func
if err != nil {
return capabilities.CapabilityRequest{}, nil, NewInvalidRequestError(err)
}
if td <= 0 || td > t.config.MaxTimeout {
td = t.config.MaxTimeout
}
mc.Timeout = &td
}

if mc.Timeout == nil {
mc.Timeout = &t.config.MaxTimeout
}

tickInterval, err := popOptionalValue[string](copiedReq.Config, tickIntervalKey)
if err != nil {
return capabilities.CapabilityRequest{}, nil, NewInvalidRequestError(err)
Expand All @@ -99,6 +111,10 @@ func (t *transformer) Transform(req capabilities.CapabilityRequest, opts ...func
mc.TickInterval = ti
}

if mc.TickInterval <= 0 || mc.TickInterval > t.config.MaxTickInterval {
mc.TickInterval = t.config.MaxTickInterval
}

pc := &ParsedConfig{
Binary: binary,
Config: config,
Expand All @@ -112,10 +128,11 @@ func (t *transformer) Transform(req capabilities.CapabilityRequest, opts ...func
return copiedReq, pc, nil
}

func NewTransformer(lggr logger.Logger, emitter custmsg.MessageEmitter) *transformer {
func NewTransformer(lggr logger.Logger, emitter custmsg.MessageEmitter, config Config) *transformer {
return &transformer{
logger: lggr,
emitter: emitter,
config: config,
}
}

Expand Down
Loading

0 comments on commit 6f04719

Please sign in to comment.