feat: implement end-to-end oracle consensus engine (#219) - #223
Merged
rohan911438 merged 5 commits intoJul 20, 2026
Merged
Conversation
Add a configurable OracleConsensusEngine that validates provider responses, rejects stale and statistically outlying readings (robust MAD z-score), assigns provider weights, and checks results against a configurable consensus threshold. Wire it into oracleService.aggregateResults so real market resolution flows (resolveWithFallback, retry queue) go through the engine, with per-market overrides via market.oracleConfig (maxStalenessMs, consensusThreshold, minConsensusResponses, outlierThreshold). Extend the AuditLog model/auditService with an 'oracle' category so every consensus decision (reached or rejected) is persisted with full weight and rejection breakdown for compliance/debugging. Add unit tests for the engine (including a fast-check property test) and integration tests exercising the full oracleService flow.
|
|
||
| it('resolves a market end-to-end via resolveWithFallback honoring market-level oracleConfig thresholds', async () => { | ||
| const now = Date.now(); | ||
| const ts = new Date(now).toISOString(); |
The workspace failed to compile under CI's RUSTFLAGS=-D warnings because
none of the 12 contract crates declared `testutils` as a known Cargo
feature, so soroban-sdk macro-generated cfg(feature = "testutils") code
tripped rustc's unexpected_cfgs lint. Declare the feature on every crate
(matching the existing soroban-sdk testutils dev-dependency) to fix it.
Also fix the genuine issues that were hiding behind that failure and
would have broken the next CI step:
- unused imports/variables and one dead private fn (access-control,
shared, prediction-market, market-factory, treasury, zk-verifier)
- clippy lints: too_many_arguments on contract entry points with
inherently many independent params (amm-pool::initialize,
market-factory::create_market, x402-integration::submit_private_order),
len_zero, useless_conversion, redundant_closure, and a
mismatched_lifetime_syntaxes lint in two test helpers
Verified clean end-to-end locally with CI's exact RUSTFLAGS: cargo
check/clippy/build/test all pass, 44 tests green.
Also un-ignore and commit real package-lock.json files for backend and
frontend — actions/setup-node's cache-dependency-path pointed at these
paths but they were gitignored and never committed, which is the root
cause of the Backend/Frontend/Backend Stress Tests/Preview deployment
job failures ("unable to cache dependencies").
The previous fix (feature declarations, unused-var/clippy cleanup) turned out to be necessary but not sufficient: cargo check still fails on the real CI runner with error[E0512] in ethnum 1.5.0's error.rs, which builds a TryFromIntError via mem::transmute(()) assuming it's zero-sized — an assumption current stable rustc no longer holds. This didn't reproduce in local testing because of a rustc version difference, but it's confirmed reproducing on the actual GitHub Actions runner. ethnum 1.5.0 is pinned by an exact `=1.5.0` requirement in soroban-env-common 20.3.0 (itself pulled in by soroban-sdk 20.x), so neither a Cargo.lock bump nor a normal semver-range override can move it to a fixed release. Vendor ethnum 1.5.3's source (upstream fix, no other API changes) under contracts/vendor/ethnum-1.5.0-patched, keeping its declared version at 1.5.0 so it satisfies the exact pin, and point [patch.crates-io] at it. Verified end-to-end offline (check/clippy/build/test all green, 44 tests passing) using the same vendored source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #219
Previously, oracle layer aggregated provider responses but had no configurable consensus — no outlier rejection, no weighting, no stale detection, and no auditable resolution path.
This PR implements a full E2E consensus engine that validates, weights, filters, and resolves markets deterministically.
What's Changed
Core Engine —
crates/oracle-consensus/services/oracle/consensus/New module
ConsensusEnginewith configurable rules: