Skip to content

Commit

Permalink
Adding ooo flag to the PingPong (#1239)
Browse files Browse the repository at this point in the history
* setter of a bool representing the `allowOutOfOrderExecution`
* creating and passing `extraArgs` to the message
  • Loading branch information
0xnogo authored Aug 15, 2024
1 parent 17341c7 commit 5e1b6d1
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 22 deletions.
14 changes: 8 additions & 6 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,11 @@ OCR2Base_transmit:test_UnAuthorizedTransmitter_Revert() (gas: 23484)
OCR2Base_transmit:test_UnauthorizedSigner_Revert() (gas: 39665)
OCR2Base_transmit:test_WrongNumberOfSignatures_Revert() (gas: 20557)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 390410)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 148405)
PingPong_plumbing:test_Pausing_Success() (gas: 17803)
PingPong_startPingPong:test_StartPingPong_Success() (gas: 178365)
PingPong_ccipReceive:test_CcipReceive_Success() (gas: 150175)
PingPong_plumbing:test_OutOfOrderExecution_Success() (gas: 20277)
PingPong_plumbing:test_Pausing_Success() (gas: 17777)
PingPong_startPingPong:test_StartPingPong_With_OOO_Success() (gas: 163199)
PingPong_startPingPong:test_StartPingPong_With_Sequenced_Ordered_Success() (gas: 182611)
PriceRegistry_applyDestChainConfigUpdates:test_InvalidChainFamilySelector_Revert() (gas: 16725)
PriceRegistry_applyDestChainConfigUpdates:test_InvalidDestBytesOverhead_Revert() (gas: 16816)
PriceRegistry_applyDestChainConfigUpdates:test_InvalidDestChainConfigDestChainSelectorEqZero_Revert() (gas: 16617)
Expand Down Expand Up @@ -875,9 +877,9 @@ Router_routeMessage:test_ManualExec_Success() (gas: 35381)
Router_routeMessage:test_OnlyOffRamp_Revert() (gas: 25116)
Router_routeMessage:test_WhenNotHealthy_Revert() (gas: 44724)
Router_setWrappedNative:test_OnlyOwner_Revert() (gas: 10985)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 53540)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 417080)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20157)
SelfFundedPingPong_ccipReceive:test_FundingIfNotANop_Revert() (gas: 53531)
SelfFundedPingPong_ccipReceive:test_Funding_Success() (gas: 417002)
SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 20151)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_OnlyPendingAdministrator_Revert() (gas: 51085)
TokenAdminRegistry_acceptAdminRole:test_acceptAdminRole_Success() (gas: 43947)
TokenAdminRegistry_addRegistryModule:test_addRegistryModule_OnlyOwner_Revert() (gas: 12629)
Expand Down
22 changes: 19 additions & 3 deletions contracts/src/v0.8/ccip/applications/PingPongDemo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {IERC20} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/
contract PingPongDemo is CCIPReceiver, OwnerIsCreator, ITypeAndVersion {
event Ping(uint256 pingPongCount);
event Pong(uint256 pingPongCount);
event OutOfOrderExecutionChange(bool isOutOfOrder);

// Default gas limit used for EVMExtraArgsV2 construction
uint64 private constant DEFAULT_GAS_LIMIT = 200_000;

// The chain ID of the counterpart ping pong contract
uint64 internal s_counterpartChainSelector;
Expand All @@ -23,6 +27,8 @@ contract PingPongDemo is CCIPReceiver, OwnerIsCreator, ITypeAndVersion {
bool private s_isPaused;
// The fee token used to pay for CCIP transactions
IERC20 internal s_feeToken;
// Allowing out of order execution
bool private s_outOfOrderExecution;

constructor(address router, IERC20 feeToken) CCIPReceiver(router) {
s_isPaused = false;
Expand Down Expand Up @@ -50,12 +56,13 @@ contract PingPongDemo is CCIPReceiver, OwnerIsCreator, ITypeAndVersion {
} else {
emit Pong(pingPongCount);
}
bytes memory data = abi.encode(pingPongCount);
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(s_counterpartAddress),
data: data,
data: abi.encode(pingPongCount),
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: "",
extraArgs: Client._argsToBytes(
Client.EVMExtraArgsV2({gasLimit: uint256(DEFAULT_GAS_LIMIT), allowOutOfOrderExecution: s_outOfOrderExecution})
),
feeToken: address(s_feeToken)
});
IRouterClient(getRouter()).ccipSend(s_counterpartChainSelector, message);
Expand Down Expand Up @@ -99,4 +106,13 @@ contract PingPongDemo is CCIPReceiver, OwnerIsCreator, ITypeAndVersion {
function setPaused(bool pause) external onlyOwner {
s_isPaused = pause;
}

function getOutOfOrderExecution() external view returns (bool) {
return s_outOfOrderExecution;
}

function setOutOfOrderExecution(bool outOfOrderExecution) external onlyOwner {
s_outOfOrderExecution = outOfOrderExecution;
emit OutOfOrderExecutionChange(outOfOrderExecution);
}
}
63 changes: 56 additions & 7 deletions contracts/src/v0.8/ccip/test/applications/PingPongDemo.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ contract PingPongDappSetup is EVM2EVMOnRampSetup {
}

contract PingPong_startPingPong is PingPongDappSetup {
function test_StartPingPong_Success() public {
uint256 pingPongNumber = 1;
bytes memory data = abi.encode(pingPongNumber);
uint256 internal pingPongNumber = 1;

function test_StartPingPong_With_Sequenced_Ordered_Success() public {
Client.EVM2AnyMessage memory sentMessage = Client.EVM2AnyMessage({
receiver: abi.encode(i_pongContract),
data: data,
data: abi.encode(pingPongNumber),
tokenAmounts: new Client.EVMTokenAmount[](0),
feeToken: s_sourceFeeToken,
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 2e5}))
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 200_000}))
});

uint256 expectedFee = s_sourceRouter.getFee(DEST_CHAIN_SELECTOR, sentMessage);
Expand All @@ -48,14 +47,51 @@ contract PingPong_startPingPong is PingPongDappSetup {
sender: address(s_pingPong),
receiver: i_pongContract,
nonce: 1,
data: data,
data: abi.encode(pingPongNumber),
tokenAmounts: sentMessage.tokenAmounts,
sourceTokenData: new bytes[](sentMessage.tokenAmounts.length),
gasLimit: 2e5,
gasLimit: 200_000,
feeToken: sentMessage.feeToken,
strict: false,
messageId: ""
});

_assertPingPongSuccess(message);
}

function test_StartPingPong_With_OOO_Success() public {
s_pingPong.setOutOfOrderExecution(true);

Client.EVM2AnyMessage memory sentMessage = Client.EVM2AnyMessage({
receiver: abi.encode(i_pongContract),
data: abi.encode(pingPongNumber),
tokenAmounts: new Client.EVMTokenAmount[](0),
feeToken: s_sourceFeeToken,
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV2({gasLimit: 200_000, allowOutOfOrderExecution: true}))
});

uint256 expectedFee = s_sourceRouter.getFee(DEST_CHAIN_SELECTOR, sentMessage);

Internal.EVM2EVMMessage memory message = Internal.EVM2EVMMessage({
sequenceNumber: 1,
feeTokenAmount: expectedFee,
sourceChainSelector: SOURCE_CHAIN_SELECTOR,
sender: address(s_pingPong),
receiver: i_pongContract,
nonce: 0,
data: abi.encode(pingPongNumber),
tokenAmounts: sentMessage.tokenAmounts,
sourceTokenData: new bytes[](sentMessage.tokenAmounts.length),
gasLimit: 200_000,
feeToken: sentMessage.feeToken,
strict: false,
messageId: ""
});

_assertPingPongSuccess(message);
}

function _assertPingPongSuccess(Internal.EVM2EVMMessage memory message) internal {
message.messageId = Internal._hash(message, s_metadataHash);

vm.expectEmit();
Expand Down Expand Up @@ -105,6 +141,8 @@ contract PingPong_plumbing is PingPongDappSetup {
}

function test_Fuzz_CounterPartAddress_Success(uint64 chainSelector, address counterpartAddress) public {
s_pingPong.setCounterpartChainSelector(chainSelector);

s_pingPong.setCounterpart(chainSelector, counterpartAddress);

assertEq(s_pingPong.getCounterpartAddress(), counterpartAddress);
Expand All @@ -118,4 +156,15 @@ contract PingPong_plumbing is PingPongDappSetup {

assertTrue(s_pingPong.isPaused());
}

function test_OutOfOrderExecution_Success() public {
assertFalse(s_pingPong.getOutOfOrderExecution());

vm.expectEmit();
emit PingPongDemo.OutOfOrderExecutionChange(true);

s_pingPong.setOutOfOrderExecution(true);

assertTrue(s_pingPong.getOutOfOrderExecution());
}
}
Loading

0 comments on commit 5e1b6d1

Please sign in to comment.