Skip to main content

Module mode_detection

Module mode_detection 

Source
Expand description

Versioned mode detection for the sum-query dispatcher.

detect_sum_mode classifies a DocumentSumRequest into one of the DocumentSumMode variants by inspecting the (where × SumMode × prove) triple. The result picks the executor the dispatcher routes to.

Versioned because the routing table is a consensus-relevant contract on the query surface — a future protocol version that adds or relaxes shapes (e.g. a new “GroupByRange + In + prove” mapping) has to land behind a method-version bump so older nodes replaying historical traffic keep dispatching the way the chain originally saw.

Two public surfaces, both routed through the same method-version slot to guarantee server + SDK pick the same executor:

  • detect_sum_mode (server-side) — takes a full DocumentSumRequest and additionally cross-validates the request’s sum_property against the doctype’s documents_summable. Server-only because DocumentSumRequest is #[cfg(feature = "server")].

  • detect_sum_mode_from_inputs — takes the minimal (where_clauses, mode, prove) tuple the routing table actually needs, callable from both server and SDK (server OR verify features). Mirrors count’s crate::query::drive_document_count_query::DriveDocumentCountQuery::detect_mode_versioned so the SDK’s verify path picks the same executor the prover used — without this, the SDK had to reconstruct routing from ad-hoc (has_range, has_in, distinct_mode) booleans, which could disagree with the v0 routing table on edge cases (e.g. group_by = [in_field] with a co-present range clause routes to the carrier shape server-side but the heuristic would have sent it to an aggregate verifier).

Functions§

detect_sum_mode
Server-side wrapper around detect_sum_mode_from_inputs that adds the doctype cross-validation (sum_property must agree with the doctype’s documents_summable). Server-only because DocumentSumRequest is gated behind the server feature.
detect_sum_mode_from_inputs
Same routing decision as detect_sum_mode but takes the minimal (where_clauses, mode, prove) tuple — callable from SDK verify paths that don’t have a DocumentSumRequest.