Skip to content

docs: document contract architecture and failure scenarios#430

Open
rjan90 wants to merge 17 commits intomainfrom
phi/contract-architecture-docs
Open

docs: document contract architecture and failure scenarios#430
rjan90 wants to merge 17 commits intomainfrom
phi/contract-architecture-docs

Conversation

@rjan90
Copy link
Collaborator

@rjan90 rjan90 commented Feb 25, 2026

Towards: #361

Addressing/trying to answer Done criterias 1 and 2:

  1. Document the current relationship/coupling between various contracts.
  2. For each of the main components (PDP Verifier, Filecoin Pay, and Filecoin Warm Storage Service) answer, "If there were a flaw in *this* piece, what then?"
  • Documents the contract relationship/coupling in FWSS: system diagram, contract inventory table, upgrade mechanism, immutable reference coupling, and cross-contract data flows
  • Adds failure scenario analysis for each contract, identifying when a simple implementation upgrade is sufficient vs. when it requires broader changes (new proxy, coordinated upgrades, or state migration)
  • Migration strategy details left as TODOs per comment here: Document Contract Relationship and Migration Strategy #361 (comment), this PR focuses on the architectural framing.

docs: document contract architecture and failure scenarios
@rjan90 rjan90 added this to the M4.1: mainnet ready milestone Feb 25, 2026
@rjan90 rjan90 self-assigned this Feb 25, 2026
@rjan90 rjan90 added this to FOC Feb 25, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Feb 25, 2026
@rjan90 rjan90 moved this from 📌 Triage to ⌨️ In Progress in FOC Feb 25, 2026
fix: align edges of diagram correctly
chore: add links to USDFC token/contracts
@rjan90 rjan90 marked this pull request as ready for review February 25, 2026 11:01
@rjan90 rjan90 requested review from BigLep and wjmelements February 25, 2026 11:02
@BigLep BigLep moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Feb 25, 2026
Copy link
Contributor

@BigLep BigLep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally seems good to me. I'll give it a shipit once its clear that we're talking about "StateView" correctly.

SPEC.md Outdated

### Upgrade Mechanism

FWSS, PDPVerifier, and ServiceProviderRegistry each implement the same **two-step announce-then-upgrade** pattern. The owner first calls `announcePlannedUpgrade(PlannedUpgrade)` with the address of the new implementation and a future block number. The upgrade cannot execute until that block number is reached. When `upgradeToAndCall` is later invoked, the internal `_authorizeUpgrade` guard verifies the implementation matches the announcement and the delay has elapsed:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FWSS, PDPVerifier, and ServiceProviderRegistry each implement the same **two-step announce-then-upgrade** pattern. The owner first calls `announcePlannedUpgrade(PlannedUpgrade)` with the address of the new implementation and a future block number. The upgrade cannot execute until that block number is reached. When `upgradeToAndCall` is later invoked, the internal `_authorizeUpgrade` guard verifies the implementation matches the announcement and the delay has elapsed:
FWSS, PDPVerifier, and ServiceProviderRegistry each implement the same home-grown **two-step announce-then-upgrade** pattern. The owner first calls `announcePlannedUpgrade(PlannedUpgrade)` with the address of the new implementation (`PlannedUpgrade.nextImplementation`) and a future block number (`PlannedUpgrade.afterEpoch`). The upgrade cannot execute until that block number is reached. The minimum delay is at least 1 block. When [`upgradeToAndCall`](https://docs.openzeppelin.com/contracts/5.x/api/proxy#UUPSUpgradeable-upgradeToAndCall-address-bytes-) is later invoked, the internal `_authorizeUpgrade` guard verifies the implementation matches the announcement and the delay has elapsed:

I used "home grown" to make it clear that we aren't following an EIP here (but it is good/prudent to do). Maybe @wjmelements can point to industry best practice that we're modeling after.


See [`FilecoinWarmStorageService.sol:429-441`](https://github.com/FilOzone/filecoin-services/blob/main/service_contracts/src/FilecoinWarmStorageService.sol#L429-L441). The minimum code-length check (`code.length > 3000`) prevents accidental upgrades to empty or trivially small implementations. The `afterEpoch` delay gives users time to review the announced implementation before it takes effect.

### Immutable Reference Coupling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also talk about FWSS' reference to StateView. I see it stores one per https://github.com/FilOzone/filecoin-services/blob/main/service_contracts/src/FilecoinWarmStorageService.sol#L459-L496

@BigLep BigLep moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Feb 26, 2026
rjan90 and others added 8 commits February 26, 2026 07:59
Co-authored-by: Steve Loeppky <biglep@filoz.org>
Co-authored-by: Steve Loeppky <biglep@filoz.org>
Co-authored-by: Steve Loeppky <biglep@filoz.org>
Co-authored-by: Steve Loeppky <biglep@filoz.org>
Co-authored-by: Steve Loeppky <biglep@filoz.org>
docs: document storage layout violations and backwards incompatibility
docs: move UUPS explenation into `Upgrade Mechanism` section
docs: change from ASCII to mermaid charts
SPEC.md Outdated
Caller->>FilecoinPayV1: settleRail(railId)
FilecoinPayV1->>FWSS: validatePayment(railId, fromEpoch, toEpoch)
Note over FWSS: find proven periods in range
FWSS-->>FilecoinPayV1: provenEpochCount, finalSettlementEpoch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, see ValidationResult in FP. It doesn't care about proven epoch, it cares about modifiedAmount (<= the max settlement amount) and settleUpto (which epoch did we settle up to—in FWSS's case this'll usually come up to the end of the last proving period if you're trying to settle up to the current period)

rjan90 and others added 2 commits February 26, 2026 11:13
Co-authored-by: Rod Vagg <rod@vagg.org>
Document StateView's architecture, failure impact, and remediation
in the contract architecture spec. Add FWSS's StateView storage
variable reference to the Immutable Reference Coupling section.
Fix settlement sequence diagram to return ValidationResult
(modifiedAmount, settleUpto) instead of incorrect fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rjan90 and others added 4 commits February 26, 2026 13:21
Fix data flow diagram callers and add schedule deletions
Add flow 6 (Next Proving Period) showing SP calling
PDPVerifier.nextProvingPeriod, which triggers FWSS to process
scheduled deletions and recalculate the payment rate. Clean up
Schedule Deletions flow to only show the queuing step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reframe FilecoinPayV1 failure response by severity
docs: clarify StateView mutability and additive deploy behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ⌨️ In Progress

Development

Successfully merging this pull request may close these issues.

3 participants