Skip to content

Commit

Permalink
Add `SendFinalizedBlockhash
Browse files Browse the repository at this point in the history
  • Loading branch information
piwonskp committed Oct 30, 2024
1 parent 62330b1 commit 94e315e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ethereum/script/LocalTesting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ contract LocalSetup is Script {
vm.serializeString(json, "contractMsg_address", vm.toString(address(contractMsg)));

// Deploy L1MessagesSender
L1MessagesSender l1MessageSender = new L1MessagesSender(address(snLocal), vm.envUint("L2_CONTRACT_ADDRESS"));
// Locally the latest block is always finalized
uint16 FINALIZED_OFFSET = 1;
L1MessagesSender l1MessageSender = new L1MessagesSender(address(snLocal), vm.envUint("L2_CONTRACT_ADDRESS"), FINALIZED_OFFSET);
console.log("L1MessagesSender deployed at:", address(l1MessageSender));
vm.serializeString(json, "l1MessageSender_address", vm.toString(address(l1MessageSender)));

Expand Down
10 changes: 6 additions & 4 deletions ethereum/src/L1MessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./lib/starknet/IStarknetMessaging.sol";
contract L1MessagesSender {
IStarknetMessaging private _snMessaging;
uint256 public immutable l2RecipientAddr;
uint16 public immutable finalizedBlockOffset;

using Uint256Splitter for uint256;

Expand All @@ -16,9 +17,10 @@ contract L1MessagesSender {
598342674068027518481179578557554850038206119856216505601406522348670006916;

// TODO - describe
constructor(address snMessaging, uint256 l2RecipientAddr_) {
constructor(address snMessaging, uint256 l2RecipientAddr_, uint16 finalizedBlockOffset_) {
_snMessaging = IStarknetMessaging(snMessaging);
l2RecipientAddr = l2RecipientAddr_;
finalizedBlockOffset = finalizedBlockOffset_;
}

// TODO - natspec
Expand All @@ -28,9 +30,9 @@ contract L1MessagesSender {
_sendBlockHashToL2(parentHash, blockNumber_);
}

function sendLatestParentHashToL2() external payable {
bytes32 parentHash = blockhash(block.number - 1);
_sendBlockHashToL2(parentHash, block.number);
function sendFinalizedBlockHashToL2() external payable {
bytes32 finalizedBlockHash = blockhash(block.number - finalizedBlockOffset);
_sendBlockHashToL2(finalizedBlockHash, block.number);
}

function _sendBlockHashToL2(bytes32 parentHash_, uint256 blockNumber_) internal {
Expand Down

0 comments on commit 94e315e

Please sign in to comment.