Skip to content

refactor(oracle): expose fixed-size source progress API - #79

Merged
ByteYue merged 1 commit into
aptos-nodefrom
codex/oracle-source-progress-api
Aug 3, 2026
Merged

refactor(oracle): expose fixed-size source progress API#79
ByteYue merged 1 commit into
aptos-nodefrom
codex/oracle-source-progress-api

Conversation

@ByteYue

@ByteYue ByteYue commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • replace the variable-size latest_record field in OracleSourceState with the bounded latest_position cursor
  • remove the payload-bearing LatestDataRecord API type
  • add a BCS round-trip test that locks the source-progress schema to 44 bytes

Why this PR is separate

This is the Aptos API prerequisite from Galxe/gravity-audit#1038. Gravity reth serializes and gravity SDK decodes this source-progress structure, so both consumers must agree on a bounded schema before the Oracle runtime/provider PRs are restacked.

This PR intentionally contains no JWK observer, duplicate-observation, certification, quorum, or execution behavior change. That hardening remains in draft PR #78 for separate review.

Compatibility

This intentionally changes the BCS shape from:

(source_type, source_id, latest_nonce, Option<LatestDataRecord>)

to:

(source_type, source_id, latest_nonce, latest_position)

Dependent reth/SDK PRs must pin this revision and decode the same schema. The fixed-width representation prevents OracleState response size from growing with external payload data.

Validation

  • cargo test -p api-types: 8 passed
  • rustfmt --edition 2021 --check crates/api-types/src/on_chain_config/oracle_state.rs: passed
  • git diff --check origin/aptos-node...HEAD: passed
  • full workspace/package formatting currently reports unrelated pre-existing formatting drift on aptos-node; the changed file itself is clean

Tracking

@ByteYue
ByteYue merged commit a64f8ad into aptos-node Aug 3, 2026
42 of 47 checks passed
ByteYue added a commit to Galxe/gravity-sdk that referenced this pull request Aug 3, 2026
## Summary

- wire `gravity_node` to the merged generic Reth Oracle relayer API
- decode the fixed-size `OracleState` snapshot from the latest committed
Gravity block
- reconcile providers by the shared `(source_type, source_id)` URI
identity
- retain and re-emit a pending observation until the authoritative
on-chain nonce catches up
- suppress stale or already-committed observations before they become
guaranteed-revert system transactions
- keep provider endpoints validator-local and redact credentials, paths,
and query strings from logs

## Runtime behavior

`add_uri` now requires an authoritative on-chain source state before
warming the Reth provider with its `latest_nonce` and `latest_position`.
`get_last_state` follows the same snapshot and fails closed when
`OracleState` is unavailable, malformed, or missing the requested
source.

After a provider returns an update, the wrapper caches that exact
`PollResult`. While its nonce is ahead of the committed state, later
observations return the cached payload instead of polling again. Once
execution catches up, polling resumes. A provider result with
`observed_nonce <= onchain_nonce` is marked unchanged so it cannot
inject a `recordBatch` that must revert with `NonceNotSequential`.

The state-read error path does not mutate the pending tracker, so a
transient committed-state failure cannot erase an observation waiting
for execution.

## Dependency alignment

- pin Gravity Aptos to the merged Oracle state API revision from
Galxe/gravity-aptos#79
- pin Gravity Reth to the merged generic relayer core plus dependency
correction from Galxe/gravity-reth#416 and Galxe/gravity-reth#417
- align the node CLI and transaction-pool type aliases with Reth 2.3
- keep Alloy and Reth helper crates on versions compatible with the SDK
Rust 1.93 toolchain

The lockfile is necessarily large because the existing SDK branch moves
from its older Reth/Aptos dependency graphs to those merged revisions.

## Non-goals

- no Binance source implementation
- no Polygon or Polymarket source implementation
- no external-network E2E or frontend demo

Those remain isolated provider and E2E slices in the split plan.

## Validation

- `RUSTFLAGS='--cfg tokio_unstable' cargo +1.93.0 check -p gravity_node
--tests --locked`
- `RUSTFLAGS='--cfg tokio_unstable' cargo +1.93.0 test -p gravity_node
relayer::tests --locked` (12 passed)
- `cargo +nightly fmt --all -- --check`
- `cargo +1.93.0 metadata --locked --no-deps --format-version 1`

## Tracking

- Galxe/gravity-audit#1038
- Addresses Galxe/gravity-audit#908
ByteYue added a commit to Galxe/gravity-sdk that referenced this pull request Aug 3, 2026
## Summary

Add one deterministic, merge-gating E2E suite for the complete
multi-validator Binance price-feed path. This PR intentionally keeps the
localhost provider fixture, reusable oracle helpers, cluster definition,
and E2E assertions together so the workflow can be reviewed and run as
one unit.

The suite also pins `gravity-reth` to the merged generic relayer runtime
through Galxe/gravity-reth#419.

## Workflow under test

1. Start four equal-voting-power Gravity validators.
2. Deploy `PriceFeedResolver` and register two `sourceType=3` tasks
through the on-chain governance lifecycle.
3. Have every validator discover the tasks and fetch the same explicit,
closed one-minute `indexPriceKlines` buckets for `NVDAUSDT` and
`TSLAUSDT`.
4. Form JWK consensus from at least three certifying validators.
5. Execute the agreed bytes through `NativeOracle` and its resolver
callback.
6. Verify observer startup, quorum evidence, per-validator relayer
progress, resolver values, and identical contract state through all four
RPC endpoints at one block.

## Determinism and network boundary

- The Binance-compatible endpoint binds to `127.0.0.1` only.
- Requests must include the exact pair, interval, `startTime`,
`endTime`, and `limit=1` closed-bucket coordinates.
- Prices are deterministic fixed-point values keyed by pair and bucket.
- The test uses no Binance API key, secret, or public Binance endpoint.
- The mock request counters prove that multiple validators independently
fetched each feed.

## Cross-repository revisions

- `gravity-aptos`: `a64f8adc274bf2681df796766ef9a5b195fee44b`
(Galxe/gravity-aptos#79)
- `gravity_chain_core_contracts`:
`ccd88ee62d90d38f824def26b32063fd094807c7`
(Galxe/gravity_chain_core_contracts#114)
- `gravity-reth`: `4ee9f656d5eb36f86934ffd712c476b57145d328`
(Galxe/gravity-reth#419)

## Run

From the SDK repository root, after building `gravity_node` and
`gravity_cli`:

```bash
PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" \
  ./gravity_e2e/run_test.sh \
    binance_price_feed_multivalidator \
    --force-init \
    --log-cli-level=INFO
```

Expected terminal evidence includes all four validators active,
observer/certifier/quorum assertions passing for both feeds, stored
round `29720875` for the fixed fixture bucket, and `All suites passed!`
after all four nodes stop.

## Validation

- `cargo build --bin gravity_node --bin gravity_cli --profile
quick-release` with the repository-required Rust flags
- `python3 -m pytest -q
gravity_e2e/gravity_e2e/utils/test_mock_binance_index.py` (`3 passed`)
- `./gravity_e2e/run_test.sh binance_price_feed_multivalidator
--log-cli-level=INFO` (`1 passed` in 40.65s)
- Python compile checks, TOML/JSON parse checks, and `git diff --check`

Refs Galxe/gravity-audit#1038
Refs Galxe/gravity-audit#1033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants