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
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.
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§
source§impl Space
impl Space
sourcepub async fn source_chain(
&self,
keystore: MetaLairClient,
author: AgentPubKey
) -> SourceChainResult<SourceChain>
pub async fn source_chain(
&self,
keystore: MetaLairClient,
author: AgentPubKey
) -> SourceChainResult<SourceChain>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Space
impl Send for Space
impl Sync for Space
impl Unpin for Space
impl !UnwindSafe for Space
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
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
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref