feature: current in Common. Event for Message

buddies-main-deployment
James Prestwich 4 years ago
parent f3a0c4fbab
commit 64b5ae8fc6
No known key found for this signature in database
GPG Key ID: 75A7F5C06D747046
  1. 10
      solidity/contracts/Common.sol
  2. 24
      solidity/contracts/Home.sol
  3. 16
      solidity/contracts/Replica.sol

@ -7,10 +7,11 @@ abstract contract Common {
enum States {ACTIVE, FAILED}
uint32 public immutable originSLIP44;
address public updater;
bytes32 public immutable DOMAIN_HASH;
address public updater;
States public state;
bytes32 public current;
event Update(
bytes32 indexed _oldRoot,
@ -24,9 +25,14 @@ abstract contract Common {
bytes _signature2
);
constructor(uint32 _originSLIP44, address _updater) {
constructor(
uint32 _originSLIP44,
address _updater,
bytes32 _current
) {
originSLIP44 = _originSLIP44;
updater = _updater;
current = _current;
DOMAIN_HASH = keccak256(abi.encodePacked(_originSLIP44, "OPTICS"));
state = States.ACTIVE;
}

@ -9,20 +9,32 @@ contract Home is MerkleTreeManager, QueueManager, Common {
using QueueLib for QueueLib.Queue;
using MerkleLib for MerkleLib.Tree;
mapping(uint32 => uint32) public sequences;
uint256 constant BOND_SIZE = 50 ether;
event Message(
uint32 indexed destination,
uint32 indexed sequence,
// the message is after this root. Some future update will contain it.
bytes32 indexed current,
bytes message
);
event ImproperUpdate();
constructor(uint32 _originSLIP44, address _updater)
constructor(
uint32 _originSLIP44,
address _updater,
bytes32 _current
)
payable
MerkleTreeManager()
QueueManager()
Common(_originSLIP44, _updater)
Common(_originSLIP44, _updater, _current)
{
require(msg.value >= BOND_SIZE, "insufficient bond");
}
// TODO
function fail() internal override {
_setFailed();
msg.sender.transfer(address(this).balance / 2);
@ -33,11 +45,15 @@ contract Home is MerkleTreeManager, QueueManager, Common {
bytes32 recipient,
bytes memory body
) external notFailed {
uint32 sequence = sequences[destination] + 1;
sequences[destination] = sequence;
bytes32 _digest =
keccak256(
abi.encodePacked(
originSLIP44,
bytes32(uint256(uint160(msg.sender))),
sequence,
destination,
recipient,
body
@ -46,6 +62,7 @@ contract Home is MerkleTreeManager, QueueManager, Common {
tree.insert(_digest);
queue.enqueue(root());
emit Message(destination, sequence, current, body);
}
function update(
@ -67,6 +84,7 @@ contract Home is MerkleTreeManager, QueueManager, Common {
bytes memory _signature
) public notFailed returns (bool) {
require(Common.checkSig(_newRoot, _oldRoot, _signature), "bad sig");
require(_oldRoot == current, "Not a current update");
if (!queue.contains(_newRoot)) {
fail();
emit ImproperUpdate();

@ -9,7 +9,6 @@ abstract contract Replica is Common {
uint32 public immutable ownSLIP44;
uint256 public optimisticSeconds;
bytes32 current;
bytes32 pending;
uint256 confirmAt;
@ -20,11 +19,11 @@ abstract contract Replica is Common {
uint32 _ownSLIP44,
address _updater,
uint256 _optimisticSeconds,
bytes32 _start
) Common(_originSLIP44, _updater) {
bytes32 _current
) Common(_originSLIP44, _updater, _current) {
ownSLIP44 = _ownSLIP44;
optimisticSeconds = _optimisticSeconds;
current = _start;
current = _current;
}
function fail() internal override {
@ -93,7 +92,10 @@ contract ProcessingReplica is Replica, HasZeroHashes {
function _beforeUpdate() internal override {}
function process(bytes calldata _message) public {
function process(bytes memory _message)
public
returns (bool, bytes memory)
{
bytes29 _m = _message.ref(0);
uint32 _destination = uint32(_m.indexUint(36, 4));
@ -113,7 +115,7 @@ contract ProcessingReplica is Replica, HasZeroHashes {
bytes memory payload = _m.slice(76, _m.len() - 76, 0).clone();
// results intentionally ignored
recipient.call(payload);
return recipient.call(payload);
}
function prove(
@ -134,7 +136,7 @@ contract ProcessingReplica is Replica, HasZeroHashes {
bytes32 leaf,
bytes32[32] calldata proof,
uint256 index,
bytes calldata message
bytes memory message
) external {
require(prove(leaf, proof, index), "!prove");
process(message);

Loading…
Cancel
Save