Skip to content

Commit

Permalink
fix: update agent ABI and remove double-update (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Jun 21, 2022
1 parent 0527cb8 commit 6145a38
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 221 deletions.
2 changes: 1 addition & 1 deletion agents/processor/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Replica {
// dispatched to the chain. We'll still log warnings if they fail
let fut = match status {
MessageStatus::None => self.replica.prove_and_process(message.as_ref(), &proof),
MessageStatus::Proven => self.replica.process(message.as_ref()),
MessageStatus::Proven(_) => self.replica.process(message.as_ref()),
_ => unreachable!(),
};
info!("Submitting message for processing");
Expand Down
98 changes: 21 additions & 77 deletions chains/nomad-ethereum/abis/Replica.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,11 @@
"internalType": "uint32",
"name": "_localDomain",
"type": "uint32"
},
{
"internalType": "uint256",
"name": "_processGas",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_reserveGas",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes32",
"name": "oldRoot",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32[2]",
"name": "newRoot",
"type": "bytes32[2]"
},
{
"indexed": false,
"internalType": "bytes",
"name": "signature",
"type": "bytes"
},
{
"indexed": false,
"internalType": "bytes",
"name": "signature2",
"type": "bytes"
}
],
"name": "DoubleUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -185,25 +144,38 @@
},
{
"inputs": [],
"name": "PROCESS_GAS",
"name": "LEGACY_STATUS_NONE",
"outputs": [
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "RESERVE_GAS",
"name": "LEGACY_STATUS_PROCESSED",
"outputs": [
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "LEGACY_STATUS_PROVEN",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
Expand Down Expand Up @@ -273,34 +245,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_oldRoot",
"type": "bytes32"
},
{
"internalType": "bytes32[2]",
"name": "_newRoot",
"type": "bytes32[2]"
},
{
"internalType": "bytes",
"name": "_signature",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "_signature2",
"type": "bytes"
}
],
"name": "doubleUpdate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "homeDomainHash",
Expand Down Expand Up @@ -366,9 +310,9 @@
"name": "messages",
"outputs": [
{
"internalType": "enum Replica.MessageStatus",
"internalType": "bytes32",
"name": "",
"type": "uint8"
"type": "bytes32"
}
],
"stateMutability": "view",
Expand Down
176 changes: 66 additions & 110 deletions chains/nomad-ethereum/src/bindings/replica.rs

Large diffs are not rendered by default.

34 changes: 6 additions & 28 deletions chains/nomad-ethereum/src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,11 @@ where
}

#[tracing::instrument(err)]
async fn double_update(
&self,
double: &DoubleUpdate,
) -> Result<TxOutcome, ChainCommunicationError> {
let mut tx = self.contract.double_update(
double.0.update.previous_root.to_fixed_bytes(),
[
double.0.update.new_root.to_fixed_bytes(),
double.1.update.new_root.to_fixed_bytes(),
],
double.0.signature.to_vec().into(),
double.1.signature.to_vec().into(),
);

if let Some(limits) = &self.gas {
tx.tx.set_gas(U256::from(limits.double_update));
}

self.submitter
.submit(self.domain, self.contract.address(), tx.tx)
.await
async fn double_update(&self, _: &DoubleUpdate) -> Result<TxOutcome, ChainCommunicationError> {
tracing::warn!("double-update submission has been deprecated");
Ok(TxOutcome {
txid: Default::default(),
})
}
}

Expand Down Expand Up @@ -317,13 +301,7 @@ where

#[tracing::instrument(err)]
async fn message_status(&self, leaf: H256) -> Result<MessageStatus, ChainCommunicationError> {
let status = self.contract.messages(leaf.into()).call().await?;
match status {
0 => Ok(MessageStatus::None),
1 => Ok(MessageStatus::Proven),
2 => Ok(MessageStatus::Processed),
_ => panic!("Bad status from solidity"),
}
Ok(self.contract.messages(leaf.into()).call().await?.into())
}

async fn acceptable_root(&self, root: H256) -> Result<bool, ChainCommunicationError> {
Expand Down
25 changes: 21 additions & 4 deletions nomad-core/src/traits/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,31 @@ use crate::{
};

/// The status of a message in the replica
#[repr(u8)]
pub enum MessageStatus {
/// Message is unknown
None = 0,
None,
/// Message has been proven but not processed
Proven = 1,
Proven(H256),
/// Message has been processed
Processed = 2,
Processed,
}
impl From<H256> for MessageStatus {
fn from(status: H256) -> Self {
if status.is_zero() {
return MessageStatus::None;
}
if status == H256::from_low_u64_be(2) {
return MessageStatus::Processed;
}
MessageStatus::Proven(status)
}
}

impl From<[u8; 32]> for MessageStatus {
fn from(status: [u8; 32]) -> Self {
let status: H256 = status.into();
status.into()
}
}

/// Interface for on-chain replicas
Expand Down
2 changes: 1 addition & 1 deletion tools/nomad-cli/src/subcommands/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl ProveCommand {
let status = replica.message_status(message.to_leaf()).await?;
let outcome = match status {
MessageStatus::None => replica.prove_and_process(&message, &proof).await?,
MessageStatus::Proven => replica.process(&message).await?,
MessageStatus::Proven(_) => replica.process(&message).await?,
_ => {
println!("Message already processed.");
return Ok(());
Expand Down

0 comments on commit 6145a38

Please sign in to comment.