pub struct SystemDataContracts { /* private fields */ }Expand description
Memoized materializations of the compiled-in system data contracts.
load_system_data_contract(variant, platform_version) is a deterministic pure function of
the variant and the protocol version, and its result changes across protocol versions (the
DPNS domain document type gains its history flags at protocol version 13, for instance).
This cache only avoids repeating that work — schema compilation and validation — so it holds
no authoritative state: any entry may be dropped and rebuilt with a bit-identical result.
There is no “current” contract. Every read is pinned to the protocol version the caller is
executing under, which it already carries in its [PlatformVersion]. That matters because
materializations are loaded speculatively: the first block of a protocol change is
executed for a candidate block that may be rejected, and the in-memory cache has no part in
the grovedb rollback that follows. Keying every entry by its protocol version keeps the
candidate’s materializations on keys no committed-version read can reach, so a rejected
candidate is inert rather than something that has to be undone.
Reads are lock-free and writes replace the whole map. The set of materializations only
changes when a protocol version is first read from — a handful of times per protocol
upgrade — while reads happen on every block and every contract fetch, so cloning a map of
at most a dozen Arc pointers on that rare path is cheaper than making every reader
contend on a lock word.
Implementations§
Source§impl SystemDataContracts
impl SystemDataContracts
Sourcepub fn load(
&self,
system_contract: SystemDataContract,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load( &self, system_contract: SystemDataContract, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns system_contract materialized for platform_version, reusing the memoized
materialization when one is present.
The contract is materialized at the protocol version the caller is executing at, which
is what the state holds: whenever a system contract’s materialization changes at a
protocol version, the first block of that change rewrites the persisted contract (see
perform_events_on_first_block_of_protocol_change).
§Errors
Propagates any error from load_system_data_contract, notably when a contract’s schema
is not expressible under platform_version — which is the case for contracts asked for
below their activation version.
Sourcepub fn load_withdrawals(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_withdrawals( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the withdrawals contract materialized for platform_version.
Sourcepub fn load_token_history(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_token_history( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the token history contract materialized for platform_version.
Sourcepub fn load_dpns(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_dpns( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the DPNS contract materialized for platform_version.
Sourcepub fn load_dashpay(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_dashpay( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the Dashpay contract materialized for platform_version.
Returns the masternode reward shares contract materialized for platform_version.
Sourcepub fn load_keyword_search(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_keyword_search( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the keyword search contract materialized for platform_version.
Sourcepub fn load_document_history(
&self,
platform_version: &PlatformVersion,
) -> Result<Arc<DataContract>, Error>
pub fn load_document_history( &self, platform_version: &PlatformVersion, ) -> Result<Arc<DataContract>, Error>
Returns the document history contract materialized for platform_version.
Sourcepub fn find_by_id(
&self,
id: Identifier,
platform_version: &PlatformVersion,
) -> Result<Option<Arc<DataContract>>, Error>
pub fn find_by_id( &self, id: Identifier, platform_version: &PlatformVersion, ) -> Result<Option<Arc<DataContract>>, Error>
Returns the system contract whose deterministic identifier matches id, materialized
for platform_version.
Returns None for user contracts, for system contracts this cache does not materialize
(WalletUtils, which lives only in grovedb), and for system contracts that are not yet
active at platform_version: before activation the contract does not exist in the
state, so the lookup must fall through to the billed grovedb fetch and report it absent
exactly like a non-upgraded node would.
Sourcepub fn drop_versions_below(&self, protocol_version: ProtocolVersion)
pub fn drop_versions_below(&self, protocol_version: ProtocolVersion)
Drops materializations for protocol versions below protocol_version.
Call this when a block commits, passing the committed protocol version: from that point
every live read asks for it or higher — check_tx validates against the committed
state, and the next block executes at the committed version until another upgrade
proposes a candidate — so everything below is garbage. Materializations above it are kept: those belong to an
upgrade candidate that was proposed and will be proposed again.
Nothing depends on this being called. Entries are reproducible, so skipping it costs
memory bounded by [MAX_MEMOIZED_PROTOCOL_VERSIONS], never correctness.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SystemDataContracts
impl RefUnwindSafe for SystemDataContracts
impl Send for SystemDataContracts
impl Sync for SystemDataContracts
impl Unpin for SystemDataContracts
impl UnsafeUnpin for SystemDataContracts
impl UnwindSafe for SystemDataContracts
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> CostsExt for T
impl<T> CostsExt for T
§fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
CostContext object with provided costs.§fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
CostContext object with costs computed using the
value getting wrapped.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
§fn into_on_network(self, network: Network) -> U
fn into_on_network(self, network: Network) -> U
Calls U::from_on_network(self).
§impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
§fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.