Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mar 27 Backport] Theoretical Hotfix for testnet3 branch #3201

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 58 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ default-features = false

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

Expand Down
2 changes: 1 addition & 1 deletion node/bft/events/src/lib.rs
Original file line number Diff line number Diff line change
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 = 6;
pub const VERSION: u32 = 7;

/// Returns the event name.
#[inline]
Expand Down
36 changes: 18 additions & 18 deletions node/bft/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,25 @@ impl<N: Network> Worker<N> {
/// Note: This method assumes the incoming solution is valid and does not exist in the ledger.
pub(crate) async fn process_unconfirmed_solution(
&self,
puzzle_commitment: PuzzleCommitment<N>,
prover_solution: Data<ProverSolution<N>>,
_puzzle_commitment: PuzzleCommitment<N>,
_prover_solution: Data<ProverSolution<N>>,
) -> Result<()> {
// Construct the transmission.
let transmission = Transmission::Solution(prover_solution.clone());
// Remove the puzzle commitment from the pending queue.
self.pending.remove(puzzle_commitment, Some(transmission.clone()));
// Check if the solution exists.
if self.contains_transmission(puzzle_commitment) {
bail!("Solution '{}' already exists.", fmt_id(puzzle_commitment));
}
// Check that the solution is well-formed and unique.
if let Err(e) = self.ledger.check_solution_basic(puzzle_commitment, prover_solution).await {
bail!("Invalid unconfirmed solution '{}': {e}", fmt_id(puzzle_commitment));
}
// Adds the prover solution to the ready queue.
if self.ready.insert(puzzle_commitment, transmission) {
trace!("Worker {} - Added unconfirmed solution '{}'", self.id, fmt_id(puzzle_commitment));
}
// // Construct the transmission.
// let transmission = Transmission::Solution(prover_solution.clone());
// // Remove the puzzle commitment from the pending queue.
// self.pending.remove(puzzle_commitment, Some(transmission.clone()));
// // Check if the solution exists.
// if self.contains_transmission(puzzle_commitment) {
// bail!("Solution '{}' already exists.", fmt_id(puzzle_commitment));
// }
// // Check that the solution is well-formed and unique.
// if let Err(e) = self.ledger.check_solution_basic(puzzle_commitment, prover_solution).await {
// bail!("Invalid unconfirmed solution '{}': {e}", fmt_id(puzzle_commitment));
// }
// // Adds the prover solution to the ready queue.
// if self.ready.insert(puzzle_commitment, transmission) {
// trace!("Worker {} - Added unconfirmed solution '{}'", self.id, fmt_id(puzzle_commitment));
// }
Ok(())
}

Expand Down
92 changes: 46 additions & 46 deletions node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,52 +189,52 @@ impl<N: Network> Consensus<N> {

impl<N: Network> Consensus<N> {
/// Adds the given unconfirmed solution to the memory pool.
pub async fn add_unconfirmed_solution(&self, solution: ProverSolution<N>) -> Result<()> {
// Process the unconfirmed solution.
{
let solution_id = solution.commitment();

// Check if the transaction was recently seen.
if self.seen_solutions.lock().put(solution_id, ()).is_some() {
// If the transaction was recently seen, return early.
return Ok(());
}
// Check if the solution already exists in the ledger.
if self.ledger.contains_transmission(&TransmissionID::from(solution_id))? {
bail!("Solution '{}' exists in the ledger {}", fmt_id(solution_id), "(skipping)".dimmed());
}
// Add the solution to the memory pool.
trace!("Received unconfirmed solution '{}' in the queue", fmt_id(solution_id));
if self.solutions_queue.lock().put(solution_id, solution).is_some() {
bail!("Solution '{}' exists in the memory pool", fmt_id(solution_id));
}
}

// If the memory pool of this node is full, return early.
let num_unconfirmed = self.num_unconfirmed_transmissions();
if num_unconfirmed > N::MAX_SOLUTIONS || num_unconfirmed > MAX_TRANSMISSIONS_PER_BATCH {
return Ok(());
}
// Retrieve the solutions.
let solutions = {
// Determine the available capacity.
let capacity = N::MAX_SOLUTIONS.saturating_sub(num_unconfirmed);
// Acquire the lock on the queue.
let mut queue = self.solutions_queue.lock();
// Determine the number of solutions to send.
let num_solutions = queue.len().min(capacity);
// Drain the solutions from the queue.
(0..num_solutions).filter_map(|_| queue.pop_lru().map(|(_, solution)| solution)).collect::<Vec<_>>()
};
// Iterate over the solutions.
for solution in solutions.into_iter() {
let solution_id = solution.commitment();
trace!("Adding unconfirmed solution '{}' to the memory pool...", fmt_id(solution_id));
// Send the unconfirmed solution to the primary.
if let Err(e) = self.primary_sender().send_unconfirmed_solution(solution_id, Data::Object(solution)).await {
warn!("Failed to add unconfirmed solution '{}' to the memory pool - {e}", fmt_id(solution_id));
}
}
pub async fn add_unconfirmed_solution(&self, _solution: ProverSolution<N>) -> Result<()> {
// // Process the unconfirmed solution.
// {
// let solution_id = solution.commitment();
//
// // Check if the transaction was recently seen.
// if self.seen_solutions.lock().put(solution_id, ()).is_some() {
// // If the transaction was recently seen, return early.
// return Ok(());
// }
// // Check if the solution already exists in the ledger.
// if self.ledger.contains_transmission(&TransmissionID::from(solution_id))? {
// bail!("Solution '{}' exists in the ledger {}", fmt_id(solution_id), "(skipping)".dimmed());
// }
// // Add the solution to the memory pool.
// trace!("Received unconfirmed solution '{}' in the queue", fmt_id(solution_id));
// if self.solutions_queue.lock().put(solution_id, solution).is_some() {
// bail!("Solution '{}' exists in the memory pool", fmt_id(solution_id));
// }
// }
//
// // If the memory pool of this node is full, return early.
// let num_unconfirmed = self.num_unconfirmed_transmissions();
// if num_unconfirmed > N::MAX_SOLUTIONS || num_unconfirmed > MAX_TRANSMISSIONS_PER_BATCH {
// return Ok(());
// }
// // Retrieve the solutions.
// let solutions = {
// // Determine the available capacity.
// let capacity = N::MAX_SOLUTIONS.saturating_sub(num_unconfirmed);
// // Acquire the lock on the queue.
// let mut queue = self.solutions_queue.lock();
// // Determine the number of solutions to send.
// let num_solutions = queue.len().min(capacity);
// // Drain the solutions from the queue.
// (0..num_solutions).filter_map(|_| queue.pop_lru().map(|(_, solution)| solution)).collect::<Vec<_>>()
// };
// // Iterate over the solutions.
// for solution in solutions.into_iter() {
// let solution_id = solution.commitment();
// trace!("Adding unconfirmed solution '{}' to the memory pool...", fmt_id(solution_id));
// // Send the unconfirmed solution to the primary.
// if let Err(e) = self.primary_sender().send_unconfirmed_solution(solution_id, Data::Object(solution)).await {
// warn!("Failed to add unconfirmed solution '{}' to the memory pool - {e}", fmt_id(solution_id));
// }
// }
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
.route("/testnet3/transaction/broadcast", post(Self::transaction_broadcast))

// POST ../solution/broadcast
.route("/testnet3/solution/broadcast", post(Self::solution_broadcast))
// .route("/testnet3/solution/broadcast", post(Self::solution_broadcast))

// GET ../find/..
.route("/testnet3/find/blockHash/:tx_id", get(Self::find_block_hash))
Expand All @@ -177,7 +177,7 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
.route("/testnet3/blocks", get(Self::get_blocks))
.route("/testnet3/height/:hash", get(Self::get_height))
.route("/testnet3/memoryPool/transmissions", get(Self::get_memory_pool_transmissions))
.route("/testnet3/memoryPool/solutions", get(Self::get_memory_pool_solutions))
// .route("/testnet3/memoryPool/solutions", get(Self::get_memory_pool_solutions))
.route("/testnet3/memoryPool/transactions", get(Self::get_memory_pool_transactions))
.route("/testnet3/statePath/:commitment", get(Self::get_state_path_for_commitment))
.route("/testnet3/stateRoot/latest", get(Self::get_state_root_latest))
Expand Down
2 changes: 1 addition & 1 deletion node/router/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<N: Network> From<DisconnectReason> for Message<N> {

impl<N: Network> Message<N> {
/// The version of the network protocol; it can be incremented in order to force users to update.
pub const VERSION: u32 = 14;
pub const VERSION: u32 = 15;

/// Returns the message name.
#[inline]
Expand Down
22 changes: 11 additions & 11 deletions node/src/validator/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,18 @@ impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Validator<N, C> {
/// Propagates the unconfirmed solution to all connected validators.
async fn unconfirmed_solution(
&self,
peer_ip: SocketAddr,
serialized: UnconfirmedSolution<N>,
solution: ProverSolution<N>,
_peer_ip: SocketAddr,
_serialized: UnconfirmedSolution<N>,
_solution: ProverSolution<N>,
) -> bool {
// Add the unconfirmed solution to the memory pool.
if let Err(error) = self.consensus.add_unconfirmed_solution(solution).await {
trace!("[UnconfirmedSolution] {error}");
return true; // Maintain the connection.
}
let message = Message::UnconfirmedSolution(serialized);
// Propagate the "UnconfirmedSolution" to the connected validators.
self.propagate_to_validators(message, &[peer_ip]);
// // Add the unconfirmed solution to the memory pool.
// if let Err(error) = self.consensus.add_unconfirmed_solution(solution).await {
// trace!("[UnconfirmedSolution] {error}");
// return true; // Maintain the connection.
// }
// let message = Message::UnconfirmedSolution(serialized);
// // Propagate the "UnconfirmedSolution" to the connected validators.
// self.propagate_to_validators(message, &[peer_ip]);
true
}

Expand Down