• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 15423730966

03 Jun 2025 05:20PM UTC coverage: 72.329% (-0.4%) from 72.763%
15423730966

push

github

SWvheerden
update readme

81584 of 112795 relevant lines covered (72.33%)

252196.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_layer/core/src/base_node/state_machine_service/initializer.rs
1
// Copyright 2020. The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
use std::sync::Arc;
24

25
use log::*;
26
use tari_comms::{connectivity::ConnectivityRequester, PeerManager};
27
use tari_comms_dht::Dht;
28
use tari_service_framework::{async_trait, ServiceInitializationError, ServiceInitializer, ServiceInitializerContext};
29
use tokio::sync::{broadcast, watch};
30

31
use crate::{
32
    base_node::{
33
        chain_metadata_service::ChainMetadataHandle,
34
        state_machine_service::{
35
            handle::StateMachineHandle,
36
            state_machine::{BaseNodeStateMachine, BaseNodeStateMachineConfig},
37
            states::StatusInfo,
38
        },
39
        sync::SyncValidators,
40
        LocalNodeCommsInterface,
41
    },
42
    chain_storage::{async_db::AsyncBlockchainDb, BlockchainBackend},
43
    consensus::ConsensusManager,
44
    proof_of_work::randomx_factory::RandomXFactory,
45
    transactions::CryptoFactories,
46
};
47

48
const LOG_TARGET: &str = "c::bn::state_machine_service::initializer";
49

50
pub struct BaseNodeStateMachineInitializer<B> {
51
    db: AsyncBlockchainDb<B>,
52
    config: BaseNodeStateMachineConfig,
53
    rules: ConsensusManager,
54
    factories: CryptoFactories,
55
    randomx_factory: RandomXFactory,
56
    bypass_range_proof_verification: bool,
57
}
58

59
impl<B> BaseNodeStateMachineInitializer<B>
60
where B: BlockchainBackend + 'static
61
{
62
    pub fn new(
×
63
        db: AsyncBlockchainDb<B>,
×
64
        config: BaseNodeStateMachineConfig,
×
65
        rules: ConsensusManager,
×
66
        factories: CryptoFactories,
×
67
        randomx_factory: RandomXFactory,
×
68
        bypass_range_proof_verification: bool,
×
69
    ) -> Self {
×
70
        Self {
×
71
            db,
×
72
            config,
×
73
            rules,
×
74
            factories,
×
75
            randomx_factory,
×
76
            bypass_range_proof_verification,
×
77
        }
×
78
    }
×
79
}
80

81
#[async_trait]
82
impl<B> ServiceInitializer for BaseNodeStateMachineInitializer<B>
83
where B: BlockchainBackend + 'static
84
{
85
    async fn initialize(&mut self, context: ServiceInitializerContext) -> Result<(), ServiceInitializationError> {
×
86
        trace!(target: LOG_TARGET, "Initializing Base Node State Machine Service");
×
87
        let (state_event_publisher, _) = broadcast::channel(500);
×
88
        let (status_event_sender, status_event_receiver) = watch::channel(StatusInfo::new());
×
89

×
90
        let handle = StateMachineHandle::new(
×
91
            state_event_publisher.clone(),
×
92
            status_event_receiver,
×
93
            context.get_shutdown_signal(),
×
94
        );
×
95
        context.register_handle(handle);
×
96

×
97
        let factories = self.factories.clone();
×
98
        let rules = self.rules.clone();
×
99
        let db = self.db.clone();
×
100
        let config = self.config.clone();
×
101
        let randomx_factory = self.randomx_factory.clone();
×
102
        let bypass_range_proof_verification = self.bypass_range_proof_verification;
×
103

×
104
        context.spawn_when_ready(move |handles| async move {
×
105
            let chain_metadata_service = handles.expect_handle::<ChainMetadataHandle>();
×
106
            let node_local_interface = handles.expect_handle::<LocalNodeCommsInterface>();
×
107
            let connectivity = handles.expect_handle::<ConnectivityRequester>();
×
108
            let peer_manager = handles.expect_handle::<Arc<PeerManager>>();
×
109

×
110
            let sync_validators =
×
111
                SyncValidators::full_consensus(rules.clone(), factories, bypass_range_proof_verification);
×
112

×
113
            let dht = handles.expect_handle::<Dht>();
×
114
            let node = BaseNodeStateMachine::new(
×
115
                db,
×
116
                node_local_interface,
×
117
                connectivity,
×
118
                chain_metadata_service.get_event_stream(),
×
119
                peer_manager,
×
120
                dht.subscribe_dht_events(),
×
121
                config,
×
122
                sync_validators,
×
123
                status_event_sender,
×
124
                state_event_publisher,
×
125
                randomx_factory,
×
126
                rules,
×
127
                handles.get_shutdown_signal(),
×
128
            );
×
129
            node.run().await;
×
130
            info!(target: LOG_TARGET, "Base Node State Machine Service has shut down");
×
131
        });
×
132
        debug!(target: LOG_TARGET, "Base Node State Machine Service initialized");
×
133

134
        Ok(())
×
135
    }
×
136
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc