Skip to content

Add weighted multi-oracle consensus as an alternative to sequential primary/fallback resolution #586

@greatest0fallt1me

Description

@greatest0fallt1me

Description

Multi-oracle resolution currently fetches sources sequentially and applies an unweighted majority vote. In contracts/predictify-hybrid/src/oracles.rs, OracleIntegrationManager::fetch_and_verify_oracle_result iterates oracle_sources and feeds successful results into determine_consensus_outcome, which counts "yes"/"no" equally and compares against DEFAULT_CONSENSUS_THRESHOLD = 66. Every whitelisted oracle therefore has identical influence regardless of trust. This issue adds optional per-oracle weighting so consensus can reflect oracle reliability.

Requirements and context

  • Relevant code: OracleIntegrationManager::fetch_and_verify_oracle_result, determine_consensus_outcome, and calculate_confidence_score in contracts/predictify-hybrid/src/oracles.rs; the DEFAULT_CONSENSUS_THRESHOLD constant on OracleIntegrationManager.
  • Per-oracle metadata already exists via OracleMetadata and OracleWhitelist (oracles.rs), giving a natural place to store a weight field.
  • Weighted tally should fall back to the current unweighted behavior when no weights are configured, preserving existing tests.
  • Error semantics must remain: Error::OracleNoConsensus when the weighted agreement is below threshold, Error::OracleUnavailable when no source returns data.
  • Non-functional: keep arithmetic checked/bounded (weights and counts are small u32/i128); do not introduce unbounded loops beyond the existing source set.

Acceptance criteria

  • An optional per-oracle weight is stored (e.g. extending OracleMetadata or whitelist config) with a sensible default.
  • determine_consensus_outcome (or a new weighted variant) tallies by weight and still respects the configurable threshold.
  • When weights are unset, behavior is identical to the current unweighted majority (existing tests stay green).
  • OracleNoConsensus is returned when weighted agreement is below threshold; confidence score reflects weighting.
  • Tests cover: equal weights == old behavior, skewed weights flipping the outcome, and below-threshold rejection.
  • cargo fmt, cargo clippy, and cargo test pass.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/weighted-oracle-consensus.
2. Implement changescontracts/predictify-hybrid/src/oracles.rs (consensus + metadata); admin setter in contracts/predictify-hybrid/src/lib.rs if a new config knob is added.
3. Write/extend tests — add cases to the oracle test suites (e.g. contracts/predictify-hybrid/src/tests/oracle_validation_tests.rs once re-enabled, or oracle_fallback_timeout_tests.rs).
4. Test and commit

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test -p predictify-hybrid
stellar contract build --verbose

Example commit message

feat: support weighted multi-oracle consensus in OracleIntegrationManager

Guidelines

≥90% coverage on the consensus paths. Document weighting in doc-comments, API_DOCUMENTATION.md (Oracle Management), and docs/contracts/ORACLE_RESOLUTION.md. Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions