Skip to content

Commit

Permalink
fix: fix #1 (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Chataigner <[email protected]>
  • Loading branch information
tchataigner authored Jun 20, 2024
1 parent 488446c commit 9e8d708
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
42 changes: 10 additions & 32 deletions aptos/core/src/types/trusted_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,11 @@ impl TrustedState {
bail!("Inconsistent epoch change proof and latest ledger info");
};

cfg_if::cfg_if! {
if #[cfg(feature = "waypoint")] {
let new_state = TrustedState::EpochState {
waypoint: Waypoint::new_any(verified_ledger_info.ledger_info()),
epoch_state: new_epoch_state,
};
} else {
let new_state = TrustedState::EpochState {
waypoint: Waypoint {
version: verified_ledger_info.ledger_info().version(),
value: HashValue::default(),
},
epoch_state: new_epoch_state,
};
}
}
let new_state = TrustedState::EpochState {
waypoint: Waypoint::new_any(verified_ledger_info.ledger_info()),
epoch_state: new_epoch_state,
};

Ok(TrustedStateChange::Epoch {
new_state,
latest_epoch_change_li: epoch_change_li,
Expand Down Expand Up @@ -396,22 +385,11 @@ impl EpochChangeProof {
.next_epoch_state()
.ok_or_else(|| format_err!("LedgerInfo doesn't carry a ValidatorSet"))?;

cfg_if::cfg_if! {
if #[cfg(feature = "waypoint")] {
let new_trusted_state = TrustedState::EpochState {
waypoint: Waypoint::new_any(new_li),
epoch_state: new_epoch_state.clone(),
};
} else {
let new_trusted_state = TrustedState::EpochState {
waypoint: Waypoint {
version: new_li.version(),
value: HashValue::default(),
},
epoch_state: new_epoch_state.clone(),
};
}
}
let new_trusted_state = TrustedState::EpochState {
waypoint: Waypoint::new_any(new_li),
epoch_state: new_epoch_state.clone(),
};

trusted_state = new_trusted_state;
}

Expand Down
26 changes: 20 additions & 6 deletions aptos/core/src/types/waypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub const WAYPOINT_SIZE: usize = U64_SIZE + HASH_LENGTH;
pub struct Waypoint {
/// The version of the reconfiguration transaction that is being approved by this waypoint.
#[getset(get_copy = "pub")]
pub(crate) version: Version,
version: Version,
/// The hash of the chosen fields of LedgerInfo.
pub(crate) value: HashValue,
value: HashValue,
}

/// `Waypoint` is a structure representing a waypoint,
Expand All @@ -46,11 +46,24 @@ impl Waypoint {
/// # Returns
///
/// A new `Waypoint`.
///
/// # Note
///
/// If the `waypoint` feature is not enabled, the `Waypoint` value will be a dummy value.
pub fn new_any(ledger_info: &LedgerInfo) -> Self {
let converter = Ledger2WaypointConverter::new(ledger_info);
Self {
version: ledger_info.version(),
value: converter.hash(),
cfg_if::cfg_if! {
if #[cfg(feature = "waypoint")] {
let converter = Ledger2WaypointConverter::new(ledger_info);
Self {
version: ledger_info.version(),
value: converter.hash(),
}
} else {
Self {
version: ledger_info.version(),
value: HashValue::default(),
}
}
}
}

Expand Down Expand Up @@ -146,6 +159,7 @@ impl Ledger2WaypointConverter {
/// # Returns
///
/// A new `Ledger2WaypointConverter`.
#[allow(dead_code)]
pub(crate) fn new(ledger_info: &LedgerInfo) -> Self {
Self {
epoch: ledger_info.epoch(),
Expand Down
34 changes: 21 additions & 13 deletions aptos/proof-server/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
use anyhow::{anyhow, Result};
use aptos_lc_core::crypto::hash::{CryptoHash, HashValue};
use aptos_lc_core::types::trusted_state::{TrustedState, TrustedStateChange};
use aptos_lc_core::types::trusted_state::TrustedState;
use aptos_lc_core::types::waypoint::Waypoint;
use clap::Parser;
use log::{debug, error, info};
use proof_server::error::ClientError;
Expand Down Expand Up @@ -491,8 +492,6 @@ async fn epoch_change_proving_task(
fetch_epoch_change_proof_data(&aptos_node_url, Some(epoch)).await?;

// Retrieve the validator verifier hash for penultimate epoch.
let trusted_state = epoch_change_proof_data.trusted_state().clone();

let validator_verifier_hash = match epoch_change_proof_data.trusted_state() {
TrustedState::EpochState { epoch_state, .. } => epoch_state.verifier().hash(),
_ => {
Expand Down Expand Up @@ -523,16 +522,25 @@ async fn epoch_change_proving_task(
debug!("Epoch change proof for latest epoch received from prover");

// Proving is done, ratchet the client state to the new trusted state.
let ratcheted_state = match trusted_state
.verify_and_ratchet_inner(epoch_change_proof_data.epoch_change_proof())
.map_err(|err| ClientError::Ratchet { source: err.into() })?
{
TrustedStateChange::Epoch { new_state, .. } => new_state,
_ => {
return Err(ClientError::Ratchet {
source: "Expected epoch change".into(),
})
}
let ledger_info = epoch_change_proof_data
.epoch_change_proof()
.ledger_info_with_sigs
.first()
.ok_or_else(|| ClientError::Internal {
source: "Epoch Change Proof has more than one LedgerInfoWithSignatures".into(),
})?
.ledger_info()
.clone();

let ratcheted_state = TrustedState::EpochState {
waypoint: Waypoint::new_any(&ledger_info),
epoch_state: ledger_info
.next_epoch_state()
.ok_or_else(|| ClientError::Internal {
source: "LedgerInfoWithSignatures in EpochChangeProof has no next EpochState"
.into(),
})?
.clone(),
};

Ok((ratcheted_state, validator_verifier_hash, epoch_change_proof))
Expand Down

0 comments on commit 9e8d708

Please sign in to comment.