The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/solidity/contracts/Replica.sol

55 lines
1.3 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
import "./Common.sol";
contract Replica is Common {
uint32 public immutable ownSLIP44;
uint256 public optimisticSeconds;
bytes32 current;
bytes32 pending;
uint256 confirmAt;
uint256 lastProcessed;
event DoubleUpdate();
constructor(
uint32 _originSLIP44,
uint32 _ownSLIP44,
address _updater,
uint256 _optimisticSeconds,
bytes32 _start,
uint256 _lastProcessed
) Common(_originSLIP44, _updater) {
ownSLIP44 = _ownSLIP44;
optimisticSeconds = _optimisticSeconds;
current = _start;
lastProcessed = _lastProcessed;
}
function fail() internal override {
_setFailed();
}
function update(
bytes32 _newRoot,
bytes32 _oldRoot,
bytes memory _signature
) external notFailed {
require(current == _oldRoot, "Not current update");
require(Common.checkSig(_newRoot, _oldRoot, _signature), "Bad sig");
confirmAt = block.timestamp + optimisticSeconds;
pending = _newRoot;
}
function confirm() external notFailed {
require(confirmAt != 0, "No pending");
require(block.timestamp >= confirmAt, "Not yet");
current = pending;
delete pending;
delete confirmAt;
}
}