pub struct DocumentRankedEntries {
pub starting_rank: u64,
pub entries: Vec<RankedEntry>,
}Expand description
Verified ranked (GROUP BY … ORDER BY <aggregate> LIMIT n [OFFSET m]) result types. DocumentRankedEntries carries one entry
per returned group in ranking order, plus the starting_rank
that pins each entry to an absolute position;
verify_ranked_top_k_proof is the tenderdash-composition wrapper
that binds the proof’s reconstructed root hash to the signed app
hash and returns the whole verified drive::query::RankedPage.
One page of a GROUP BY … ORDER BY <aggregate> LIMIT n [OFFSET m]
query: the ranked groups, plus the rank the page starts at.
Entry order is the ranking order — best-first for DESC,
worst-first for ASC. Callers must not re-sort; ties (groups with
equal aggregates) come back in group-key order in the direction of
the walk, which is descending group-key order for DESC.
Fewer than n entries is normal — the index simply holds fewer
groups than were asked for — and is not an error.
Each RankedEntry’s key is the raw index-key bytes of the
GROUP BY property’s value (for a string property, its UTF-8
bytes); its value is the aggregate, one of
RankedEntryValue::Count / RankedEntryValue::Sum /
RankedEntryValue::AvgFixedPoint. Averages are fixed-point
integers scaled by crate::RANKED_AVG_SCALE; divide by it (or
call RankedEntryValue::as_f64) to render one.
The fixed point is exact on the proved path only. A page built
by Self::from_verified carries the very integer the proof
commits to; one built by Self::from_unproved_response carries a
best-effort reconstruction from the wire’s double — see that
method for what that costs.
Fields§
§starting_rank: u64The 0-based rank of entries[0] — the query’s OFFSET, as
actually honoured.
This is what turns a page back into a ranking: entry i is
the group at rank starting_rank + i. Without it a caller who
asked for ORDER BY avg(grade) DESC LIMIT 1 OFFSET 4 receives
one entry and has no way to tell it really is the 5th-best
group rather than the best.
On the proved path this is grovedb’s cryptographically
attested count, re-derived by the verifier from the counted
subtree commitments in the proof bytes rather than trusted from
the response. It equals the requested offset unless the walk ran
out of groups first, in which case entries is empty and this
is a proof that the ranking holds exactly this many groups in
total — an offset past the end is a positive answer, not an
error.
On the unproven decode it is whatever the node put on the
wire (0 when the field is absent), and carries no more weight
than the entries beside it.
entries: Vec<RankedEntry>The groups on this page, in ranking order.
Implementations§
Source§impl DocumentRankedEntries
impl DocumentRankedEntries
Sourcepub fn from_verified(page: RankedPage) -> Self
pub fn from_verified(page: RankedPage) -> Self
Build a DocumentRankedEntries from a verifier-side
RankedPage — the shape rs-drive’s merk-level verifier
returns, carrying the attested skip alongside the entries.
Mirrors
DocumentSplitCounts::from_verified,
except that it is not the identity: RankedPage is rs-drive’s
internal type and this is the client-facing one, so the rename
of skipped → starting_rank happens here, where the value
stops being “how far the walk skipped” and starts being “which
rank you are looking at”.
Sourcepub fn from_unproved_response(
response: &GetDocumentsResponse,
) -> Result<(Self, ResponseMetadata), Error>
pub fn from_unproved_response( response: &GetDocumentsResponse, ) -> Result<(Self, ResponseMetadata), Error>
Decode the unproven ranked payload of a getDocuments
response — the ResultData.ranked variant a node returns for a
ranked request sent with prove = false.
Order is preserved verbatim: the server emits entries in ranking order and this decoder never re-sorts.
This is a plain wire decode with no cryptographic guarantee
whatsoever — it is the “trust the node” path, and that applies
to Self::starting_rank every bit as much as to the entries:
an unproven page claiming to start at rank 4 is a claim, not a
fact. Prefer verify_ranked_top_k_proof (via rs-sdk’s
DocumentRankedEntries::fetch) unless you are deliberately
reading from a node you already trust.
A node that predates the wire skipped field leaves it unset;
that decodes to starting_rank == 0, which is the right answer
for the offset-less queries such a node could serve at all.
§Averages come back approximate here
The wire’s avg is a double, deliberately: these entries only
exist on this path, and a proof-verifying client reconstructs
the exact fixed point from the proof instead. To keep one
RankedEntryValue type across both paths this decoder
multiplies the double back up by crate::RANKED_AVG_SCALE and
rounds, so the RankedEntryValue::AvgFixedPoint it yields is a
best-effort reconstruction, not the committed integer — its
low digits are noise beyond f64’s ~15–16 significant decimal
digits. Render it, compare it loosely, but do not treat it as the
value grovedb ranked on; ask for the proof if you need that.
§Errors
Error::EmptyVersionwhen the response carries no version.Error::ResponseDecodeErrorwhen the response is a V0 response (which has no ranked shape), carries a proof rather than data, or carries a non-rankedResultDatavariant.Error::ResponseDecodeErrorwhen an entry’svalueoneof is unset, or itsavgis not a finite double that scales intoi128range.
Trait Implementations§
Source§impl Clone for DocumentRankedEntries
impl Clone for DocumentRankedEntries
Source§fn clone(&self) -> DocumentRankedEntries
fn clone(&self) -> DocumentRankedEntries
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DocumentRankedEntries
impl Debug for DocumentRankedEntries
Source§impl Default for DocumentRankedEntries
impl Default for DocumentRankedEntries
Source§fn default() -> DocumentRankedEntries
fn default() -> DocumentRankedEntries
impl Eq for DocumentRankedEntries
Source§impl<'dq, Q> FromProof<Q> for DocumentRankedEntries
Reject the generic FromProof entry point for
DocumentRankedEntries.
impl<'dq, Q> FromProof<Q> for DocumentRankedEntries
Reject the generic FromProof entry point for
DocumentRankedEntries.
DocumentRankedEntries is reached from rs-sdk via the
FromProof<DocumentQuery> impl defined alongside the SDK’s
DocumentQuery type (see
rs-sdk/src/platform/documents/document_ranked_entries.rs), which
resolves the (axis, descending, k, offset) tuple and the covering
index from the request’s (select, group_by, order_by, limit, offset) shape plus the data contract. The generic
FromProof<Q: TryInto<DriveDocumentQuery>> path carries neither —
DriveDocumentQuery has no notion of a ranking — so it errors out
explicitly rather than verifying the wrong thing; calling this impl
directly is a programmer mistake.
Source§fn maybe_from_proof_with_metadata<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
_request: I,
_response: O,
_network: Network,
_platform_version: &PlatformVersion,
_provider: &'a dyn ContextProvider,
) -> Result<(Option<Self>, ResponseMetadata, Proof), Error>where
Self: 'a,
fn maybe_from_proof_with_metadata<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
_request: I,
_response: O,
_network: Network,
_platform_version: &PlatformVersion,
_provider: &'a dyn ContextProvider,
) -> Result<(Option<Self>, ResponseMetadata, Proof), Error>where
Self: 'a,
Source§fn maybe_from_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<Option<Self>, Error>where
Self: Sized + 'a,
fn maybe_from_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<Option<Self>, Error>where
Self: Sized + 'a,
Source§fn from_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<Self, Error>where
Self: Sized + 'a,
fn from_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<Self, Error>where
Self: Sized + 'a,
Source§fn from_proof_with_metadata<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<(Self, ResponseMetadata), Error>where
Self: Sized + 'a,
fn from_proof_with_metadata<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<(Self, ResponseMetadata), Error>where
Self: Sized + 'a,
Source§fn from_proof_with_metadata_and_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<(Self, ResponseMetadata, Proof), Error>where
Self: Sized + 'a,
fn from_proof_with_metadata_and_proof<'a, I: Into<Self::Request>, O: Into<Self::Response>>(
request: I,
response: O,
network: Network,
platform_version: &PlatformVersion,
provider: &'a dyn ContextProvider,
) -> Result<(Self, ResponseMetadata, Proof), Error>where
Self: Sized + 'a,
Source§impl PartialEq for DocumentRankedEntries
impl PartialEq for DocumentRankedEntries
impl StructuralPartialEq for DocumentRankedEntries
Auto Trait Implementations§
impl Freeze for DocumentRankedEntries
impl RefUnwindSafe for DocumentRankedEntries
impl Send for DocumentRankedEntries
impl Sync for DocumentRankedEntries
impl Unpin for DocumentRankedEntries
impl UnsafeUnpin for DocumentRankedEntries
impl UnwindSafe for DocumentRankedEntries
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§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> ⓘ
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§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.