Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store relayer on relay [SLT-182] #3170

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
mapping(bytes32 => BridgeStatus) public bridgeStatuses;
/// @notice Proof of relayed bridge tx on origin chain
mapping(bytes32 => BridgeProof) public bridgeProofs;
/// @notice Whether bridge has been relayed on destination chain
mapping(bytes32 => bool) public bridgeRelays;
/// @notice Relay details on destination chain
mapping(bytes32 => BridgeRelay) public bridgeRelayDetails;

/// @dev to prevent replays
uint256 public nonce;
Expand Down Expand Up @@ -139,8 +139,13 @@
if (block.timestamp > transaction.deadline) revert DeadlineExceeded();

// mark bridge transaction as relayed
if (bridgeRelays[transactionId]) revert TransactionRelayed();
bridgeRelays[transactionId] = true;
if (bridgeRelayDetails[transactionId].blockNumber != 0) revert TransactionRelayed();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid repetition, let's make bridgeRelays(bytes32) a public view - will make it easier to maintain later on.


bridgeRelayDetails[transactionId] = BridgeRelay({
blockNumber: uint48(block.number),
blockTimestamp: uint48(block.timestamp),
relayer: relayer
});
ChiTimesChi marked this conversation as resolved.
Show resolved Hide resolved

// transfer tokens to recipient on destination chain and gas rebate if requested
address to = transaction.destRecipient;
Expand Down Expand Up @@ -173,6 +178,12 @@
rebate
);
}

/// @inheritdoc IFastBridgeV2
function bridgeRelays(bytes32 transactionId) external view returns (bool) {
// has this transactionId been relayed?
return bridgeRelayDetails[transactionId].blockNumber != 0;
ChiTimesChi marked this conversation as resolved.
Show resolved Hide resolved
}
Fixed Show fixed Hide fixed

/// @inheritdoc IFastBridge
function prove(bytes memory request, bytes32 destTxHash) external {
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ interface IFastBridgeV2 is IFastBridge {
/// @param request The encoded bridge transaction to claim on origin chain
function claim(bytes memory request) external;

/// @notice Checks if a transaction has been relayed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs forge fmt + in general we try to define the structs at the top of the contract, prior to the functions. In hindsight, both of these should've been flagged by CI workflows - I will make a ticket to update these with a reasonable settings (e.g. older FastBridge has a ton of linter warnings that might as well be ignored at this point)

/// @param transactionId The ID of the transaction to check
/// @return True if the transaction has been relayed, false otherwise
function bridgeRelays(bytes32 transactionId) external view returns (bool);

struct BridgeRelay {
uint48 blockNumber;
uint48 blockTimestamp;
address relayer;
}

}
Loading