Skip to content

Commit

Permalink
Update the consensus constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Jul 21, 2023
1 parent b613d35 commit 456c32e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
16 changes: 4 additions & 12 deletions node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use ::rand::thread_rng;
use anyhow::Result;
use indexmap::IndexMap;
use parking_lot::Mutex;
use std::{collections::BTreeMap, future::Future, sync::Arc};
use std::{collections::BTreeMap, future::Future, net::SocketAddr, sync::Arc};
use tokio::{
sync::{oneshot, OnceCell},
task::JoinHandle,
Expand All @@ -66,15 +66,13 @@ pub struct Consensus<N: Network, C: ConsensusStorage<N>> {
bft: BFT<N>,
/// The primary sender.
primary_sender: Arc<OnceCell<PrimarySender<N>>>,
/// The memory pool.
memory_pool: MemoryPool<N>,
/// The spawned handles.
handles: Arc<Mutex<Vec<JoinHandle<()>>>>,
}

impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {
/// Initializes a new instance of consensus.
pub fn new(account: Account<N>, ledger: Ledger<N, C>, dev: Option<u16>) -> Result<Self> {
pub fn new(account: Account<N>, ledger: Ledger<N, C>, ip: Option<SocketAddr>, dev: Option<u16>) -> Result<Self> {
// Initialize the committee.
let committee = {
// TODO (howardwu): Fix the ledger round number.
Expand All @@ -91,15 +89,9 @@ impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {
// Initialize the ledger service.
let ledger_service = Arc::new(CoreLedgerService::<N, C>::new(ledger.clone()));
// Initialize the BFT.
let bft = BFT::new(account, storage, ledger_service, None, dev)?;
let bft = BFT::new(account, storage, ledger_service, ip, dev)?;
// Return the consensus.
Ok(Self {
ledger,
bft,
primary_sender: Default::default(),
memory_pool: Default::default(),
handles: Default::default(),
})
Ok(Self { ledger, bft, primary_sender: Default::default(), handles: Default::default() })
}

/// Run the consensus instance.
Expand Down
2 changes: 1 addition & 1 deletion node/src/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<N: Network, C: ConsensusStorage<N>> Beacon<N, C> {
}

// Initialize the consensus.
let mut consensus = Consensus::new(account.clone(), ledger.clone(), dev)?;
let mut consensus = Consensus::new(account.clone(), ledger.clone(), None, dev)?;
// Initialize the primary channels.
let (primary_sender, primary_receiver) = init_primary_channels::<N>();
// Start the consensus.
Expand Down
2 changes: 1 addition & 1 deletion node/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
}
}
// Initialize the consensus.
let mut consensus = Consensus::new(account.clone(), ledger.clone(), dev)?;
let mut consensus = Consensus::new(account.clone(), ledger.clone(), None, dev)?;
// Initialize the primary channels.
let (primary_sender, primary_receiver) = init_primary_channels::<N>();
// Start the consensus.
Expand Down

0 comments on commit 456c32e

Please sign in to comment.