kaspa_consensus_core/
trusted.rs

1use crate::{block::Block, header::Header, BlockHashMap, BlueWorkType, KType};
2use kaspa_hashes::Hash;
3use serde::{Deserialize, Serialize};
4use std::sync::Arc;
5
6/// Represents semi-trusted externally provided Ghostdag data (by a network peer)
7#[derive(Clone, Serialize, Deserialize)]
8pub struct ExternalGhostdagData {
9    pub blue_score: u64,
10    pub blue_work: BlueWorkType,
11    pub selected_parent: Hash,
12    pub mergeset_blues: Vec<Hash>,
13    pub mergeset_reds: Vec<Hash>,
14    pub blues_anticone_sizes: BlockHashMap<KType>,
15}
16
17/// Represents an externally provided block with associated Ghostdag data which
18/// is only partially validated by the consensus layer. Note there is no actual trust
19/// but rather these blocks are indirectly validated through the PoW mined over them
20pub struct TrustedBlock {
21    pub block: Block,
22    pub ghostdag: ExternalGhostdagData,
23}
24
25impl TrustedBlock {
26    pub fn new(block: Block, ghostdag: ExternalGhostdagData) -> Self {
27        Self { block, ghostdag }
28    }
29}
30
31/// Represents an externally provided header with associated Ghostdag data which
32/// is only partially validated by the consensus layer. Note there is no actual trust
33/// but rather these headers are indirectly validated through the PoW mined over them
34pub struct TrustedHeader {
35    pub header: Arc<Header>,
36    pub ghostdag: ExternalGhostdagData,
37}
38
39impl TrustedHeader {
40    pub fn new(header: Arc<Header>, ghostdag: ExternalGhostdagData) -> Self {
41        Self { header, ghostdag }
42    }
43}
44
45/// Represents externally provided Ghostdag data associated with a block Hash
46pub struct TrustedGhostdagData {
47    pub hash: Hash,
48    pub ghostdag: ExternalGhostdagData,
49}
50
51impl TrustedGhostdagData {
52    pub fn new(hash: Hash, ghostdag: ExternalGhostdagData) -> Self {
53        Self { hash, ghostdag }
54    }
55}