Skip to main content

scp_kernel/
kernel.rs

1use crate::*;
2use tracing::debug;
3
4pub struct StellarKernel<C: Consensus, D: Driver> {
5    cd: ConsensusDriver<C, D>,
6    state: StellarState,
7}
8
9impl<C: Consensus, D: Driver> StellarKernel<C, D> {
10    pub fn new(
11        node_id: thruput_scp::SCPNodeID,
12        is_validator: bool,
13        qset: thruput_scp::SCPQuorumSet,
14        consensus: C,
15        driver: D,
16    ) -> StellarKernel<C, D> {
17        debug!(
18            "initializing SCP with local node id {} and qset {}",
19            driver.to_short_string(&node_id),
20            serde_json::to_string_pretty(&qset).unwrap()
21        );
22        let driver_clone = driver.clone();
23        StellarKernel {
24            cd: ConsensusDriver { consensus, driver },
25            state: StellarState::new(
26                node_id,
27                is_validator,
28                qset,
29                |opaque: &[u8]| driver_clone.get_hash_of(opaque),
30            ),
31        }
32    }
33
34    pub fn proto(&mut self) -> StellarProto<'_, C, D> {
35        StellarProto {
36            cd: &self.cd,
37            state: &mut self.state,
38        }
39    }
40}