Skip to content

Commit aed09f4

Browse files
authored
Merge pull request #4234 from ProvableHQ/fix/validator_block_tree_dump
[Fix] Make the validators dump their block tree correctly
2 parents a294c33 + 62caba2 commit aed09f4

16 files changed

Lines changed: 94 additions & 21 deletions

File tree

cli/src/commands/start.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use std::{
6464
sync::{Arc, atomic::AtomicBool},
6565
};
6666
use tokio::{
67-
runtime::{self, Runtime},
67+
runtime::{self, Handle, Runtime},
6868
sync::mpsc,
6969
task,
7070
};
@@ -323,7 +323,9 @@ impl Start {
323323
}
324324

325325
// Initialize the runtime.
326-
Self::runtime().block_on(async move {
326+
let runtime = Self::runtime();
327+
let handle = runtime.handle().clone();
328+
runtime.block_on(async move {
327329
// Error messages.
328330
let node_parse_error = || "Failed to start node";
329331

@@ -332,9 +334,15 @@ impl Start {
332334

333335
// Parse the node arguments, start it, and block until shutdown.
334336
match self_.network {
335-
MainnetV0::ID => self_.parse_node::<MainnetV0>(log_receiver).await.with_context(node_parse_error)?,
336-
TestnetV0::ID => self_.parse_node::<TestnetV0>(log_receiver).await.with_context(node_parse_error)?,
337-
CanaryV0::ID => self_.parse_node::<CanaryV0>(log_receiver).await.with_context(node_parse_error)?,
337+
MainnetV0::ID => {
338+
self_.parse_node::<MainnetV0>(handle, log_receiver).await.with_context(node_parse_error)?
339+
}
340+
TestnetV0::ID => {
341+
self_.parse_node::<TestnetV0>(handle, log_receiver).await.with_context(node_parse_error)?
342+
}
343+
CanaryV0::ID => {
344+
self_.parse_node::<CanaryV0>(handle, log_receiver).await.with_context(node_parse_error)?
345+
}
338346
_ => panic!("Invalid network ID specified"),
339347
};
340348

@@ -665,7 +673,7 @@ impl Start {
665673

666674
/// Start the node and blocks until it terminates.
667675
#[rustfmt::skip]
668-
async fn parse_node<N: Network>(&mut self, log_receiver: mpsc::Receiver<Vec<u8>>) -> Result<()> {
676+
async fn parse_node<N: Network>(&mut self, handle: Handle, log_receiver: mpsc::Receiver<Vec<u8>>) -> Result<()> {
669677
if !self.nobanner {
670678
// Print the welcome banner.
671679
println!("{}", crate::helpers::welcome_message());
@@ -842,7 +850,7 @@ impl Start {
842850
}
843851

844852
// Register the signal handler.
845-
let signal_handler = SignalHandler::new();
853+
let signal_handler = SignalHandler::new(Some(handle));
846854

847855
// Initialize the node.
848856
let node = match node_type {

node/bft/ledger-service/src/ledger.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,8 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
474474
}
475475
}
476476
}
477+
478+
fn is_stopped(&self) -> bool {
479+
self.stoppable.is_stopped()
480+
}
477481
}

node/bft/ledger-service/src/mock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,9 @@ impl<N: Network> LedgerService<N> for MockLedgerService<N> {
235235
let height = N::CONSENSUS_HEIGHT(consensus_version).unwrap();
236236
Ok(consensus_config_value!(N, TRANSACTION_SPEND_LIMIT, height).unwrap())
237237
}
238+
239+
fn is_stopped(&self) -> bool {
240+
// No ledger to check against.
241+
false
242+
}
238243
}

node/bft/ledger-service/src/prover.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,9 @@ impl<N: Network> LedgerService<N> for ProverLedgerService<N> {
190190
) -> Result<u64> {
191191
bail!("Cannot compute spent_cost in prover")
192192
}
193+
194+
fn is_stopped(&self) -> bool {
195+
// No ledger to check against.
196+
false
197+
}
193198
}

node/bft/ledger-service/src/traits.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,6 @@ pub trait LedgerService<N: Network>: std::fmt::Debug + Send + Sync {
160160
transaction: &Transaction<N>,
161161
consensus_version: ConsensusVersion,
162162
) -> Result<u64>;
163+
164+
fn is_stopped(&self) -> bool;
163165
}

node/bft/ledger-service/src/translucent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,8 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for TranslucentLedgerS
200200
) -> Result<u64> {
201201
self.inner.transaction_spend_in_microcredits(transaction, consensus_version)
202202
}
203+
204+
fn is_stopped(&self) -> bool {
205+
self.inner.is_stopped()
206+
}
203207
}

node/bft/src/primary.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,8 @@ impl<N: Network> Primary<N> {
20552055
info!("Shutting down the primary...");
20562056
// Remove the callback.
20572057
self.primary_callback.clear();
2058+
// Shut down the sync service.
2059+
self.sync.shut_down().await;
20582060
// Shut down the workers.
20592061
self.workers().iter().for_each(|worker| worker.shut_down());
20602062
// Abort the tasks.

node/bft/src/worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ mod tests {
676676
fn check_block_subdag(&self, _block: Block<N>, _prefix: &[PendingBlock<N>]) -> Result<PendingBlock<N>, CheckBlockError<N>>;
677677
fn begin_ledger_update<'a>(&'a self) -> Result<Box<dyn LedgerUpdateService<N> + 'a>, BeginLedgerUpdateError>;
678678
fn transaction_spend_in_microcredits(&self, transaction: &Transaction<N>, consensus_version: ConsensusVersion) -> Result<u64>;
679+
fn is_stopped(&self) -> bool;
679680
}
680681
}
681682

node/rest/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
139139
pub const fn handles(&self) -> &Arc<Mutex<Vec<JoinHandle<()>>>> {
140140
&self.handles
141141
}
142+
143+
/// Shuts down the REST instance.
144+
pub fn shut_down(&self) {
145+
self.handles.lock().iter().for_each(|handle| handle.abort());
146+
}
142147
}
143148

144149
impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {

node/router/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ impl<N: Network> Router<N> {
238238
&self.cache
239239
}
240240

241+
/// Returns a reference to the ledger.
242+
pub fn ledger(&self) -> &Arc<dyn LedgerService<N>> {
243+
&self.ledger
244+
}
245+
241246
/// Returns `true` if the node is only engaging with trusted peers.
242247
pub fn trusted_peers_only(&self) -> bool {
243248
self.trusted_peers_only

0 commit comments

Comments
 (0)