You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
contracts: optional on-chain enumeration of deferred PaymentChannel settlements #902
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.
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
// In PaymentChannel.sol storageusing EnumerableSetfor 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() externalviewreturns (uint256);
function deferredSettlementAt(uint256index) externalviewreturns (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.
Activity
github-actions commentedon Jun 14, 2026
🎯 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 addingEnumerableSet.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
enhancement,technical,low(unchanged)PaymentChannel.sol; implementation path is explicit (OZEnumerableSet.Bytes32Set, insert on defer branch, remove on flush, add view); success criteria and trade-offs are stated🔗 Similar issues
PaymentChannel.withdraw; same root cause pattern, different function💡 Notes and suggestions
Implementation sketch:
SSTORE cost note:
EnumerableSet.addwrites 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).unused-returnfires onEnumerableSet.add/remove(returns a bool; assign or suppress at the function level per CLAUDE.md).Lighter alternative: if the full set is considered too much storage/complexity, a minimal
uint128 deferredCountincrement/decrement counter (no enumeration, just presence signal) could tell a keeper "there is work to do" and rely onSettlementDeferredevents 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-blockingcandidate if the team decides on-chain enumeration is not needed for the initial testnet deployment.Add this agentic workflows to your repo
To install this agentic workflow, run
fix(contracts): clamp deferredSettlements pagination without offset+l…
test(contracts): fuzz deferredSettlements pagination invariant (#902)
feat(contracts): enumerate deferred PaymentChannel settlements on-cha…