Skip to content

Commit

Permalink
feat: disable unused contracts and fetch update to _sendPacket to set…
Browse files Browse the repository at this point in the history
… timeoutTimestamp
  • Loading branch information
reednaa committed Feb 29, 2024
1 parent 502cf10 commit 10e471d
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/apps/polymer/IncentivizedPolymerEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract IncentivizedPolymerEscrow is IncentivizedMessageEscrow, IbcMwUser, IbcU
return 0;
}

/// @dev Disable processPacket
/** @dev Disable processPacket */
function processPacket(
bytes calldata, /* messagingProtocolContext */
bytes calldata, /* rawMessage */
Expand All @@ -54,6 +54,25 @@ contract IncentivizedPolymerEscrow is IncentivizedMessageEscrow, IbcMwUser, IbcU
revert NotImplemented();
}

/** @dev Disable reemitAckMessage. Polymer manages the entire flow, so we don't need to worry about expired proofs. */
function reemitAckMessage(
bytes32 /* sourceIdentifier */,
bytes calldata /* implementationIdentifier */,
bytes calldata /* receiveAckWithContext */
) external payable override {
revert NotImplemented();
}

/** @dev Disable timeoutMessage */
function timeoutMessage(
bytes32 /* sourceIdentifier */,
bytes calldata /* implementationIdentifier */,
uint256 /* originBlockNumber */,
bytes calldata /* message */
) external payable override {
revert NotImplemented();
}

/// @notice This function is used to allow acks to be executed twice (if the first one ran out of gas)
/// This is not intended to allow processPacket to work.
function _verifyPacket(bytes calldata, /* messagingProtocolContext */ bytes calldata _message)
Expand Down Expand Up @@ -81,7 +100,7 @@ contract IncentivizedPolymerEscrow is IncentivizedMessageEscrow, IbcMwUser, IbcU
uint256 gasLimit = gasleft();
bytes32 feeRecipitent = bytes32(uint256(uint160(tx.origin)));

bytes memory sourceImplementationIdentifier = abi.encodePacked(packet.srcPortAddr);
bytes memory sourceImplementationIdentifier = bytes.concat(packet.srcPortAddr);

bytes memory receiveAck =
_handleMessage(channelId, sourceImplementationIdentifier, packet.appData, feeRecipitent, gasLimit);
Expand All @@ -99,7 +118,7 @@ contract IncentivizedPolymerEscrow is IncentivizedMessageEscrow, IbcMwUser, IbcU
bytes32 feeRecipitent = bytes32(uint256(uint160(tx.origin)));

bytes calldata rawMessage = ack.data;
bytes memory destinationImplementationIdentifier = abi.encodePacked(packet.destPortAddr);
bytes memory destinationImplementationIdentifier = bytes.concat(packet.destPortAddr);

isVerifiedMessageHash[keccak256(rawMessage)] = VerifiedMessageHashContext({
chainIdentifier: channelId,
Expand All @@ -121,22 +140,24 @@ contract IncentivizedPolymerEscrow is IncentivizedMessageEscrow, IbcMwUser, IbcU
);
}

// * Send to messaging_protocol
/**
* @param destinationChainIdentifier Universal Channel ID. It's always from the running chain's perspective.
* Each universal channel/channelId represents a directional path from the running chain to a destination chain.
* Universal ChannelIds should _destChainIdToChannelIdd from the Polymer registry.
* Although everyone is free to establish their own channels, they're not "officially" vetted until they're in the Polymer registry.
* @param destinationImplementation IncentivizedPolymerEscrow address on the counterparty chain.
* @param message packet payload
* @param deadline Packet will timeout after the dest chain's block time in nanoseconds since the epoch passes timeoutTimestamp.
*/
function _sendPacket(
bytes32 destinationChainIdentifier,
bytes memory destinationImplementation,
bytes memory message
bytes memory message,
uint64 deadline
) internal override returns (uint128 costOfsendPacketInNativeToken) {
// Packet will timeout after the dest chain's block time in nanoseconds since the epoch passes timeoutTimestamp.
uint64 timeoutTimestamp = uint64(block.timestamp + _TIMEOUT_AFTER_BLOCK) * 1e9;
// If timeoutTimestamp is set to 0, set it to maximum. This does not really apply to Polymer since it is an onRecv implementation
// but it should still conform to the general spec of Generalised Incentives.
uint64 timeoutTimestamp = deadline > 0 ? deadline : type(uint64).max;
IbcUniversalPacketSender(mw).sendUniversalPacket(
destinationChainIdentifier, bytes32(destinationImplementation), message, timeoutTimestamp
);
Expand Down

0 comments on commit 10e471d

Please sign in to comment.