Skip to content

Commit

Permalink
perf: remove family tag checks for single-condition hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
elatoskinas committed Jul 5, 2024
1 parent 20f104f commit e0dc7c2
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 279 deletions.
428 changes: 214 additions & 214 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions contracts/src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,10 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre

if (msgFeeJuels > i_maxFeeJuelsPerMsg) revert MessageFeeTooHigh(msgFeeJuels, i_maxFeeJuelsPerMsg);

// NOTE: when supporting non-EVM chains, revisit this and parse non-EVM args
// Assumes strict ordering, unless the chain is of the EVM family and the extra args indicate out of order execution
uint64 nonce = 0;
if (
destChainConfig.dynamicConfig.familyTag != Client.EVM_FAMILY_TAG
|| !_parseEVMExtraArgsFromBytes(message.extraArgs, destChainConfig.dynamicConfig).allowOutOfOrderExecution
) {
if (!_parseEVMExtraArgsFromBytes(message.extraArgs, destChainConfig.dynamicConfig).allowOutOfOrderExecution) {
// Only bump nonce for messages that specify allowOutOfOrderExecution == false. Otherwise, we
// may block ordered message nonces, which is not what we want.
nonce = INonceManager(i_nonceManager).getIncrementedOutboundNonce(destChainSelector, originalSender);
Expand All @@ -382,7 +380,7 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
}),
sender: originalSender,
data: message.data,
extraArgs: _parseExtraArgsFromBytes(message.extraArgs, destChainConfig.dynamicConfig),
extraArgs: _convertParsedExtraArgs(message.extraArgs, destChainConfig.dynamicConfig),
receiver: message.receiver,
feeToken: message.feeToken,
feeTokenAmount: feeTokenAmount,
Expand All @@ -392,12 +390,12 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
return rampMessage;
}

/// @dev Parses extraArgs dest chain config family tag validation, and conversion to the latest arguments version.
/// @dev Parses extraArgs with dest chain config family tag validation, and re-encodes the args to the latest arguments version.
/// Used to generate an EVM2AnyRampMessage with the accurate representation of the parsed extraArgs.
/// @param extraArgs The extra args bytes
/// @param destChainDynamicConfig Dest chain config to validate against
/// @return encodedExtraArgs the parsed & encoded extra args
function _parseExtraArgsFromBytes(
function _convertParsedExtraArgs(
bytes calldata extraArgs,
DestChainDynamicConfig memory destChainDynamicConfig
) internal pure returns (bytes memory) {
Expand Down Expand Up @@ -620,9 +618,8 @@ contract EVM2EVMMultiOnRamp is IEVM2AnyOnRampClient, ITypeAndVersion, OwnerIsCre
uint256 executionGasCost = destChainDynamicConfig.destGasOverhead
+ (message.data.length * destChainDynamicConfig.destGasPerPayloadByte) + tokenTransferGas;

if (destChainDynamicConfig.familyTag == Client.EVM_FAMILY_TAG) {
executionGasCost += _parseEVMExtraArgsFromBytes(message.extraArgs, destChainDynamicConfig).gasLimit;
}
// NOTE: when supporting non-EVM chains, revisit this and parse non-EVM args
executionGasCost += _parseEVMExtraArgsFromBytes(message.extraArgs, destChainDynamicConfig).gasLimit;

uint256 executionCost = uint112(packedGasPrice) * executionGasCost * destChainDynamicConfig.gasMultiplierWeiPerEth;

Expand Down
33 changes: 11 additions & 22 deletions contracts/src/v0.8/ccip/test/NonceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
_generateSingleLaneSingleBasicMessage(SOURCE_CHAIN_SELECTOR_1, SINGLE_LANE_ON_RAMP_ADDRESS_1);
uint64 startNonceChain3 =
s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_3, abi.encode(messages[0].sender));
s_prevOffRamp.execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages), new uint256[](0)
);
s_prevOffRamp.execute(_generateSingleLaneRampReportFromMessages(messages), new uint256[](0));

// Nonce unchanged for chain 3
assertEq(
Expand Down Expand Up @@ -436,9 +434,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
uint64 startNonce = s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_1, abi.encode(messages[0].sender));

for (uint64 i = 1; i < 4; ++i) {
s_prevOffRamp.execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages), new uint256[](0)
);
s_prevOffRamp.execute(_generateSingleLaneRampReportFromMessages(messages), new uint256[](0));

// messages contains a single message - update for the next execution
messages[0].nonce++;
Expand All @@ -457,9 +453,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
uint64 startNonce = s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_2, abi.encode(messages[0].sender));

for (uint64 i = 1; i < 4; ++i) {
s_nestedPrevOffRamps[0].execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_2, messages), new uint256[](0)
);
s_nestedPrevOffRamps[0].execute(_generateSingleLaneRampReportFromMessages(messages), new uint256[](0));

// messages contains a single message - update for the next execution
messages[0].nonce++;
Expand All @@ -478,9 +472,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
_generateSingleLaneSingleBasicMessage(SOURCE_CHAIN_SELECTOR_1, SINGLE_LANE_ON_RAMP_ADDRESS_1);

uint64 startNonce = s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_1, abi.encode(messages[0].sender));
s_prevOffRamp.execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages), new uint256[](0)
);
s_prevOffRamp.execute(_generateSingleLaneRampReportFromMessages(messages), new uint256[](0));

assertEq(
startNonce + 1, s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_1, abi.encode(messages[0].sender))
Expand Down Expand Up @@ -533,9 +525,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
Internal.EVM2EVMMessage[] memory messages =
_generateSingleLaneSingleBasicMessage(SOURCE_CHAIN_SELECTOR_1, SINGLE_LANE_ON_RAMP_ADDRESS_1);

s_prevOffRamp.execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages), new uint256[](0)
);
s_prevOffRamp.execute(_generateSingleLaneRampReportFromMessages(messages), new uint256[](0));

Internal.Any2EVMRampMessage[] memory messagesMultiRamp =
_generateSingleBasicMessage(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1);
Expand Down Expand Up @@ -587,9 +577,7 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
messagesSingleLane[0].messageId = Internal._hash(messagesSingleLane[0], s_prevOffRamp.metadataHash());

// previous offramp executes msg and increases nonce
s_prevOffRamp.execute(
_generateSingleLaneRampReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messagesSingleLane), new uint256[](0)
);
s_prevOffRamp.execute(_generateSingleLaneRampReportFromMessages(messagesSingleLane), new uint256[](0));
assertEq(
startNonce + 1,
s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_1, abi.encode(messagesSingleLane[0].sender))
Expand All @@ -612,10 +600,11 @@ contract NonceManager_OffRampUpgrade is EVM2EVMMultiOffRampSetup {
assertEq(startNonce + 2, s_inboundNonceManager.getInboundNonce(SOURCE_CHAIN_SELECTOR_1, messages[0].sender));
}

function _generateSingleLaneRampReportFromMessages(
uint64 sourceChainSelector,
Internal.EVM2EVMMessage[] memory messages
) internal pure returns (Internal.ExecutionReport memory) {
function _generateSingleLaneRampReportFromMessages(Internal.EVM2EVMMessage[] memory messages)
internal
pure
returns (Internal.ExecutionReport memory)
{
bytes[][] memory offchainTokenData = new bytes[][](messages.length);

for (uint256 i = 0; i < messages.length; ++i) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit e0dc7c2

Please sign in to comment.