Repository navigation
Conversation
There was a problem hiding this comment.
Summary
Forked Phoenix markets go stale because nothing updates their oracle readings. This PR fixes that by raising every market's spot and perp stale_threshold in the local PerpAssetMap to u32::MAX whenever any Phoenix override runs. Map overrides put the raised thresholds in the same write. Other overrides fetch the map if it isn't local, raise the thresholds, and log a warning on failure without failing the override. The unit tests and the mainnet clock-advance test cover the main paths. The PR also adds a claude-review.yml workflow, which the title doesn't mention.
Overall the approach is sound and the tests are good. Main concerns:
- Errors are handled differently on the two paths. On the PerpAssetMap path, a
raise_stale_thresholdserror is propagated with?, so any decode or offset-search problem now fails a map override that used to succeed. On every other path the same error is only logged. - The offset search is weaker than the existing helper. It finds metadata by taking the first byte match after a cursor and assumes iteration order matches storage order.
patch_market_metadatausesunique_subslice_offset, which requires exactly one match. - Side effects on failure.
keep_oracle_readings_usableruns before the Trader override is validated, so the map is changed (and possibly fetched from upstream) even when that override then fails. It also re-parses the whole map on every Phoenix override, including accounts that end up on the genericOk(None)path. This is probably acceptable, but it should be documented. - Unrelated workflow.
.github/workflows/claude-review.ymlhas nothing to do with oracle staleness and should be a separate PR.
| let kept = async { | ||
| let map = phoenix_dependency(svm, &PHOENIX_PERP_ASSET_MAP, remote_ctx).await?; | ||
| let Some(data) = raise_stale_thresholds(&PHOENIX_PERP_ASSET_MAP, &map.data)? else { | ||
| return Ok(()); |
There was a problem hiding this comment.
The map is written here with svm.set_account, but the caller in svm.rs never adds it to settled_this_slot. As a result, a later map override in the same slot with fetchBeforeUse: true refetches the map from upstream. It still ends up with raised thresholds, because the map path raises them again, but it pays for one more remote fetch.
| const PREPARATION_SLOT: u64 = 0; | ||
| /// The threshold is a `u64` that Phoenix may multiply by a `u8` hard-stale multiplier; unlike | ||
| /// `u64::MAX`, this keeps that product from overflowing. | ||
| const KEPT_STALE_THRESHOLD_SLOTS: u64 = u32::MAX as u64; |
There was a problem hiding this comment.
The comment says Phoenix multiplies the threshold by a u8. If Phoenix also adds the threshold to a slot (e.g. last_update_slot + threshold * mult), u32::MAX * 255 still fits in a u64, so this is safe. Please note in the comment which Phoenix check this is based on, so the bound can be re-checked when the program is upgraded.
…tional tests + rename
OverviewThe PR raises every market's spot and perp oracle
The PR also adds unit tests (including a two-market fixture), a mainnet clock-advance test, README guidance, and an unrelated Claude review workflow. AssessmentThe core logic is sound:
The tests are thorough. The byte-diff check that nothing outside the PriceComponents changes is a good addition. Issues and suggestions
The offset is found by searching the raw bytes for each decoded
This depends on
This runs for every Phoenix-owned account that isn't a map, including
The test builds a second full mainnet-backed locker just to get a clean starting state, which doubles the RPC load in an already network-bound test. You could reuse the first locker: reset the clock to
This workflow is unrelated to the oracle-staleness fix; consider moving it to its own PR. Also, the PR title and body are pasted directly into the prompt. Fork PRs are skipped, but any same-repo contributor can steer the review output. The impact is limited because the tools are read-only, but it is worth knowing. |
There was a problem hiding this comment.
What this PR does: Phoenix rejects a market once its oracle readings are older than the market's stale threshold. Nothing updates those readings on a local fork, so this PR raises every market's spot and perp stale_threshold in the local PerpAssetMap to u32::MAX. The map override applies the raise in the same write. Every other Phoenix-owned override applies it first, through keep_oracle_readings_usable. The PR also updates the README and adds unit tests (two markets, failure fallbacks) and a mainnet test that moves the clock forward by 1M slots.
Assessment: The approach is reasonable and well tested. If the raise fails, the requested override still applies, and the multiplier math cannot overflow (u8 * u32::MAX fits in a u64). Things to consider:
- Side effect applies to the whole session, even when it shouldn't.
keep_oracle_readings_usablewrites the map before the override's own validation runs. If the override then errors and is skipped, or the account falls through to the generic IDL path (_ => Ok(None)), the thresholds still stay raised. After any Phoenix scenario is played, users can no longer test stale-oracle behaviour. It may be worth documenting this as a deliberate trade-off, or putting it behind an opt-out. - Inconsistent with the map path. If
forge_phoenix_overridefails on a PerpAssetMap override (e.g. a bad value), the thresholds are not raised. Every other Phoenix override kind raises them unconditionally. - Cost. Each Trader or other Phoenix override decodes and scans the whole map again. It's cheap when nothing changes, but it repeats work across multiple overrides in the same slot.
- Unrelated change.
.github/workflows/claude-review.ymlhas nothing to do with the oracle-staleness fix and would be better as its own PR. Also, the workflow puts the PR title and body directly into the prompt. That is acceptable only because fork PRs are skipped, so it's worth keeping in mind.
| for entry in map.iter() { | ||
| let metadata = entry.map_err(decode_error)?.metadata; | ||
| let metadata_bytes = metadata.as_bytes(); | ||
| let offset = data[cursor..] |
There was a problem hiding this comment.
This finds each entry's offset by searching the raw bytes for the metadata (windows().position()). It works because each market's metadata includes its unique market pubkey, but it's indirect, and it costs O(len × metadata_len) in the worst case. If the decoder can return each entry's byte offset, or if entries sit at fixed header + slot * entry_size positions (the tests already assume 48 + i * 1584), computing the offset directly would be simpler and could never point at the wrong location.
| .map(Some), | ||
| _ => Ok(None), | ||
| kind => { | ||
| keep_oracle_readings_usable(svm, remote_ctx).await; |
There was a problem hiding this comment.
This runs before prepare_trader_override validates anything, and it also runs for Phoenix accounts that return Ok(None) (the generic IDL path). As a result, the map is changed permanently even when this override is later skipped with an error. If that's intended ("keep the session usable regardless"), it would help to say so explicitly in the README. Users who want to test stale-oracle rejection lose that ability as soon as any Phoenix scenario runs.
| @@ -280,6 +334,16 @@ pub async fn prepare_phoenix_override( | |||
| Some(PhoenixAccount::PerpAssetMap) => { | |||
| let mark_slot = svm.inner.get_sysvar::<Clock>().slot; | |||
| let data = forge_phoenix_override(account_pubkey, account, values, mark_slot)?; | |||
There was a problem hiding this comment.
If forge_phoenix_override fails here, the ? returns before raise_stale_thresholds runs, so a bad PerpAssetMap override leaves the thresholds unchanged. All other Phoenix override kinds raise them unconditionally through keep_oracle_readings_usable. Consider making the two paths consistent: either always raise, or only raise when the override succeeds.
a54c85d
into
fix/scenarios/phoenix/oracle-staleness
The PR appears safe to merge, with no outstanding findings.
Summary
Phoenix overrides raise oracle stale thresholds in the local
PerpAssetMap, keeping fetched readings usable as the clock advances.Reviews (4) · Last reviewed commit: "ci: remove claude code" · Reviewed by Greptile