pub struct Space {
    pub dna_hash: Arc<DnaHash>,
    pub cache_db: DbWrite<DbKindCache>,
    pub conductor_db: DbWrite<DbKindConductor>,
    pub authored_db: DbWrite<DbKindAuthored>,
    pub dht_db: DbWrite<DbKindDht>,
    pub p2p_agents_db: DbWrite<DbKindP2pAgents>,
    pub p2p_metrics_db: DbWrite<DbKindP2pMetrics>,
    pub p2p_batch_sender: Sender<P2pBatch>,
    pub dht_query_cache: DhtDbQueryCache,
    pub countersigning_workspace: CountersigningWorkspace,
    pub incoming_op_hashes: IncomingOpHashes,
    pub incoming_ops_batch: IncomingOpsBatch,
}
Expand description

This is the set of data required at the DnaHash space level. All cells in the same DnaHash space will share these.

Fields§

§dna_hash: Arc<DnaHash>

The dna hash for this space.

§cache_db: DbWrite<DbKindCache>

The caches databases. These are shared across cells. There is one per unique Dna.

§conductor_db: DbWrite<DbKindConductor>

The conductor database. There is only one of these.

§authored_db: DbWrite<DbKindAuthored>

The authored databases. These are shared across cells. There is one per unique Dna.

§dht_db: DbWrite<DbKindDht>

The dht databases. These are shared across cells. There is one per unique Dna.

§p2p_agents_db: DbWrite<DbKindP2pAgents>

The database for storing AgentInfoSigned

§p2p_metrics_db: DbWrite<DbKindP2pMetrics>

The database for storing p2p MetricDatum(s)

§p2p_batch_sender: Sender<P2pBatch>

The batch sender for writes to the p2p database.

§dht_query_cache: DhtDbQueryCache

A cache for slow database queries.

§countersigning_workspace: CountersigningWorkspace

Countersigning workspace that is shared across this cell.

§incoming_op_hashes: IncomingOpHashes

Incoming op hashes that are queued for processing.

§incoming_ops_batch: IncomingOpsBatch

Incoming ops batch for this space.

Implementations§

Construct a SourceChain for an author in this Space

Examples found in repository?
src/conductor/conductor/graft_records_onto_source_chain.rs (line 22)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
pub(crate) async fn graft_records_onto_source_chain(
    handle: ConductorHandle,
    cell_id: CellId,
    validate: bool,
    records: Vec<Record>,
) -> ConductorApiResult<()> {
    // Get or create the space for this cell.
    // Note: This doesn't require the cell be installed.
    let space = handle.get_or_create_space(cell_id.dna_hash())?;

    let chc = None;
    let network = handle
        .holochain_p2p()
        .to_dna(cell_id.dna_hash().clone(), chc);

    let source_chain: SourceChain = space
        .source_chain(handle.keystore().clone(), cell_id.agent_pubkey().clone())
        .await?;

    let existing = source_chain
        .query(ChainQueryFilter::new().descending())
        .await?
        .into_iter()
        .map(|r| r.signed_action)
        .collect::<Vec<SignedActionHashed>>();

    let graft = ChainGraft::new(existing, records).rebalance();
    let chain_top = graft.existing_chain_top();

    if validate {
        validate_records(handle.clone(), &cell_id, &chain_top, graft.incoming()).await?;
    }

    // Produce the op lights for each record.
    let data = graft
        .incoming
        .into_iter()
        .map(|el| {
            let ops = produce_op_lights_from_records(vec![&el])?;
            // Check have the same author as cell.
            let (sah, entry) = el.into_inner();
            if sah.action().author() != cell_id.agent_pubkey() {
                return Err(StateMutationError::AuthorsMustMatch);
            }
            Ok((sah, ops, entry.into_option()))
        })
        .collect::<StateMutationResult<Vec<_>>>()?;

    // Commit the records to the source chain.
    let ops_to_integrate = space
        .authored_db
        .async_commit({
            let cell_id = cell_id.clone();
            move |txn| {
                if let Some((_, seq)) = chain_top {
                    // Remove records above the grafting position.
                    //
                    // NOTES:
                    // - the chain top may have moved since the grafting call began,
                    //   but it doesn't really matter, since we explicitly want to
                    //   clobber anything beyond the grafting point anyway.
                    // - if there is an existing fork, there may still be a fork after the
                    //   grafting. A more rigorous approach would thin out the existing
                    //   actions until a single fork is obtained.
                    txn.execute(
                        holochain_sqlite::sql::sql_cell::DELETE_ACTIONS_AFTER_SEQ,
                        rusqlite::named_params! {
                            ":author": cell_id.agent_pubkey(),
                            ":seq": seq
                        },
                    )
                    .map_err(StateMutationError::from)?;
                }

                let mut ops_to_integrate = Vec::new();

                // Commit the records and ops to the authored db.
                for (sah, ops, entry) in data {
                    // Clippy is wrong :(
                    #[allow(clippy::needless_collect)]
                    let basis = ops
                        .iter()
                        .map(|op| op.dht_basis().clone())
                        .collect::<Vec<_>>();
                    ops_to_integrate.extend(
                        source_chain::put_raw(txn, sah, ops, entry)?
                            .into_iter()
                            .zip(basis.into_iter()),
                    );
                }
                SourceChainResult::Ok(ops_to_integrate)
            }
        })
        .await?;

    // Check which ops need to be integrated.
    // Only integrated if a cell is installed.
    if handle
        .list_cell_ids(Some(CellStatus::Joined))
        .contains(&cell_id)
    {
        holochain_state::integrate::authored_ops_to_dht_db(
            &network,
            ops_to_integrate,
            &space.authored_db,
            &space.dht_db,
            &space.dht_query_cache,
        )
        .await?;
    }
    Ok(())
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
TODO: once 1.33.0 is the minimum supported compiler version, remove Any::type_id_compat and use StdAny::type_id instead. https://github.com/rust-lang/rust/issues/27745
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more