Skip to content

contracts: optional on-chain enumeration of deferred PaymentChannel settlements #902

Description

@yigitdot

Follow-up from the review of #849 / PR #889 (kept out of that PR's scope).

Context

PR #889 adds a deferred-settlement path: when FeeRouter is paused, PaymentChannel.settleChannel still pays the client refund and closes the channel, but parks the provider's settle leg under settlementDeferred[channelId] for a later permissionless flushDeferredSettlement(channelId).

The deferral mapping is a mapping(bytes32 => bool) with no on-chain enumeration. A pending flush is discoverable only via the indexed SettlementDeferred event — recovery therefore depends on off-chain event indexing. Funds are safe (parked in the contract) and permissionlessly flushable by anyone who knows the channelId, and the id is deterministically derivable, so this is low severity. But a deferral that no indexer captured (e.g. logs pruned/missed during the pause window) is invisible on-chain, and the provider's share could sit indefinitely with no automatic sweep.

PR #889 documents this dependency in NatSpec on the settlementDeferred mapping.

Proposal (optional)

Add on-chain enumeration so a keeper can drain pending settlements without log replay:

  • An OZ EnumerableSet.Bytes32Set of deferred channel ids — insert in the settleChannel defer branch, remove in flushDeferredSettlement — plus a deferredSettlements()/paginated view.
  • Or a lighter keeper-oriented view if the full set is deemed too much storage.

Trade-off: extra SSTORE on the (rare) defer/flush paths and added surface to test/audit, versus removing the off-chain-indexer dependency for fund recovery.

Refs

Activity

  1. added
    kind:feature
    prio:low
    on Jun 14, 2026
  2. github-actions commented on Jun 14, 2026

    @github-actions

    🎯 Triage report

    A well-scoped follow-up to #849 / PR #889. The deferred-settlement path introduced by PR #889 parks provider funds in a mapping(bytes32 => bool) that has no on-chain enumeration, leaving recovery dependent on off-chain event indexing. This issue proposes adding EnumerableSet.Bytes32Set (or a lighter paginated view) so a keeper can sweep pending settlements without log replay. Funds are safe and the issue is correctly self-assessed as low-severity; this is a UX/resilience improvement.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature Optional hardening of an existing mechanism; no regression, not a bug
    Labels enhancement, technical, low (unchanged) All three labels already applied are accurate
    Coding agent Suitable Scope is limited to PaymentChannel.sol; implementation path is explicit (OZ EnumerableSet.Bytes32Set, insert on defer branch, remove on flush, add view); success criteria and trade-offs are stated

    🔗 Similar issues

    💡 Notes and suggestions

    Implementation sketch:

    // In PaymentChannel.sol storage
    using EnumerableSet for EnumerableSet.Bytes32Set;
    EnumerableSet.Bytes32Set private _deferredIds;
    
    // In settleChannel defer branch (after writing settlementDeferred[channelId] = true):
    _deferredIds.add(channelId);
    
    // In flushDeferredSettlement (after clearing settlementDeferred[channelId]):
    _deferredIds.remove(channelId);
    
    // View (paginated to avoid gas blow-up on large sets):
    function deferredSettlementCount() external view returns (uint256);
    function deferredSettlementAt(uint256 index) external view returns (bytes32);

    SSTORE cost note: EnumerableSet.add writes 2 slots (value→index mapping + array push) — roughly 40k gas on the first insert, 5k on subsequent due to non-zero slots. Given the defer path is emergency/rare, this is acceptable, but worth a comment in the contract and test.

    CI gotchas to watch for:

    • FOUNDRY_PROFILE=ci forge build --sizes --deny warnings — ensure the new storage variable doesn't trigger any solc warnings (should be clean).
    • Add slither suppression if unused-return fires on EnumerableSet.add/remove (returns a bool; assign or suppress at the function level per CLAUDE.md).
    • Add test coverage for: (a) deferred set populated after pause-settle, (b) removed after flush, (c) view returns correct count/element.

    Lighter alternative: if the full set is considered too much storage/complexity, a minimal uint128 deferredCount increment/decrement counter (no enumeration, just presence signal) could tell a keeper "there is work to do" and rely on SettlementDeferred events only for the specific IDs. Significantly cheaper but still off-chain-dependent for the ID list.

    Decision to record: whether to ship full enumeration, the lighter counter, or defer entirely post-PoC — this is currently marked optional and low priority, so it may be a prod-blocking candidate if the team decides on-chain enumeration is not needed for the initial testnet deployment.

    Generated by Agentic Triage for issue #902 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featureprio:low

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions