Skip to content

Commit

Permalink
Merge pull request #3185 from AleoHQ/testnet3-staging
Browse files Browse the repository at this point in the history
[Feb 10 Backport] Theoretical Hotfix for `testnet3` branch
  • Loading branch information
howardwu committed Mar 23, 2024
2 parents 199c953 + 9ea2dc2 commit 862d632
Show file tree
Hide file tree
Showing 20 changed files with 616 additions and 487 deletions.
639 changes: 336 additions & 303 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -46,7 +46,7 @@ default-features = false

[workspace.dependencies.snarkvm]
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2127981"
rev = "94d1135"
#version = "=0.16.18"
features = [ "circuit", "console", "rocks" ]

Expand Down
11 changes: 8 additions & 3 deletions node/bft/events/src/challenge_response.rs
Expand Up @@ -17,6 +17,7 @@ use super::*;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChallengeResponse<N: Network> {
pub signature: Data<Signature<N>>,
pub nonce: u64,
}

impl<N: Network> EventTrait for ChallengeResponse<N> {
Expand All @@ -30,15 +31,17 @@ impl<N: Network> EventTrait for ChallengeResponse<N> {
impl<N: Network> ToBytes for ChallengeResponse<N> {
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.signature.write_le(&mut writer)?;
self.nonce.write_le(&mut writer)?;
Ok(())
}
}

impl<N: Network> FromBytes for ChallengeResponse<N> {
fn read_le<R: Read>(mut reader: R) -> IoResult<Self> {
let signature = Data::read_le(&mut reader)?;
let nonce = u64::read_le(&mut reader)?;

Ok(Self { signature })
Ok(Self { signature, nonce })
}
}

Expand All @@ -53,7 +56,7 @@ pub mod prop_tests {
};

use bytes::{Buf, BufMut, BytesMut};
use proptest::prelude::{BoxedStrategy, Strategy};
use proptest::prelude::{any, BoxedStrategy, Strategy};
use test_strategy::proptest;

type CurrentNetwork = snarkvm::prelude::Testnet3;
Expand All @@ -70,7 +73,9 @@ pub mod prop_tests {
}

pub fn any_challenge_response() -> BoxedStrategy<ChallengeResponse<CurrentNetwork>> {
any_signature().prop_map(|sig| ChallengeResponse { signature: Data::Object(sig) }).boxed()
(any_signature(), any::<u64>())
.prop_map(|(sig, nonce)| ChallengeResponse { signature: Data::Object(sig), nonce })
.boxed()
}

#[proptest]
Expand Down
2 changes: 1 addition & 1 deletion node/bft/events/src/lib.rs
Expand Up @@ -118,7 +118,7 @@ impl<N: Network> From<DisconnectReason> for Event<N> {

impl<N: Network> Event<N> {
/// The version of the event protocol; it can be incremented in order to force users to update.
pub const VERSION: u32 = 5;
pub const VERSION: u32 = 6;

/// Returns the event name.
#[inline]
Expand Down
13 changes: 8 additions & 5 deletions node/bft/ledger-service/src/ledger.rs
Expand Up @@ -143,18 +143,21 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
}
}

/// Returns the previous committee for the given round.
/// If the previous round is in the future, then the current committee is returned.
fn get_previous_committee_for_round(&self, round: u64) -> Result<Committee<N>> {
/// Returns the committee lookback for the given round.
/// If the committee lookback round is in the future, then the current committee is returned.
fn get_committee_lookback_for_round(&self, round: u64) -> Result<Committee<N>> {
// Get the round number for the previous committee. Note, we subtract 2 from odd rounds,
// because committees are updated in even rounds.
let previous_round = match round % 2 == 0 {
true => round.saturating_sub(1),
false => round.saturating_sub(2),
};

// Retrieve the committee for the previous round.
self.get_committee_for_round(previous_round)
// Get the committee lookback round.
let committee_lookback_round = previous_round.saturating_sub(Committee::<N>::COMMITTEE_LOOKBACK_RANGE);

// Retrieve the committee for the committee lookback round.
self.get_committee_for_round(committee_lookback_round)
}

/// Returns `true` if the ledger contains the given certificate ID in block history.
Expand Down
4 changes: 2 additions & 2 deletions node/bft/ledger-service/src/mock.rs
Expand Up @@ -126,8 +126,8 @@ impl<N: Network> LedgerService<N> for MockLedgerService<N> {
Ok(self.committee.clone())
}

/// Returns the previous committee for the given round.
fn get_previous_committee_for_round(&self, _round: u64) -> Result<Committee<N>> {
/// Returns the committee lookback for the given round.
fn get_committee_lookback_for_round(&self, _round: u64) -> Result<Committee<N>> {
Ok(self.committee.clone())
}

Expand Down
6 changes: 3 additions & 3 deletions node/bft/ledger-service/src/prover.rs
Expand Up @@ -108,9 +108,9 @@ impl<N: Network> LedgerService<N> for ProverLedgerService<N> {
bail!("Committee for round {round} does not exist in prover")
}

/// Returns the previous committee for the given round.
/// If the previous round is in the future, then the current committee is returned.
fn get_previous_committee_for_round(&self, round: u64) -> Result<Committee<N>> {
/// Returns the committee lookback for the given round.
/// If the committee lookback round is in the future, then the current committee is returned.
fn get_committee_lookback_for_round(&self, round: u64) -> Result<Committee<N>> {
bail!("Previous committee for round {round} does not exist in prover")
}

Expand Down
6 changes: 3 additions & 3 deletions node/bft/ledger-service/src/traits.rs
Expand Up @@ -68,9 +68,9 @@ pub trait LedgerService<N: Network>: Debug + Send + Sync {
/// If the given round is in the future, then the current committee is returned.
fn get_committee_for_round(&self, round: u64) -> Result<Committee<N>>;

/// Returns the previous committee for the given round.
/// If the previous round is in the future, then the current committee is returned.
fn get_previous_committee_for_round(&self, round: u64) -> Result<Committee<N>>;
/// Returns the committee lookback for the given round.
/// If the committee lookback round is in the future, then the current committee is returned.
fn get_committee_lookback_for_round(&self, round: u64) -> Result<Committee<N>>;

/// Returns `true` if the ledger contains the given certificate ID.
fn contains_certificate(&self, certificate_id: &Field<N>) -> Result<bool>;
Expand Down
5 changes: 3 additions & 2 deletions node/bft/ledger-service/src/translucent.rs
Expand Up @@ -119,8 +119,9 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for TranslucentLedgerS
self.inner.get_committee_for_round(round)
}

fn get_previous_committee_for_round(&self, round: u64) -> Result<Committee<N>> {
self.inner.get_previous_committee_for_round(round)
/// Returns the committee lookback for the given round.
fn get_committee_lookback_for_round(&self, round: u64) -> Result<Committee<N>> {
self.inner.get_committee_lookback_for_round(round)
}

/// Returns `true` if the ledger contains the given certificate ID in block history.
Expand Down

0 comments on commit 862d632

Please sign in to comment.