Skip to content

feat: add active provider index#497

Open
Luisfc68 wants to merge 3 commits into
v2.6.0-syncfrom
feature/FLY-2298
Open

feat: add active provider index#497
Luisfc68 wants to merge 3 commits into
v2.6.0-syncfrom
feature/FLY-2298

Conversation

@Luisfc68

Copy link
Copy Markdown
Collaborator

What

Add active provider index

Why

So multiple registration don't cause discovery to make O(n) calls to collateral management during getProviders

Task

https://rsklabs.atlassian.net/browse/FLY-2298

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Comment thread src/CollateralManagement.sol Dismissed
Comment thread src/FlyoverDiscovery.sol Dismissed
Comment thread src/FlyoverDiscovery.sol Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a v2.1.0 “active provider” enumeration to FlyoverDiscovery to avoid getProviders() scanning historical provider IDs (mitigating O(n) collateral checks), and wires CollateralManagement to notify discovery on full collateral withdrawal so withdrawn providers are removed from the active enumeration.

Changes:

  • Introduces an _activeProviderIds set in FlyoverDiscovery, updates approveRegistration()/getProviders(), and adds removeProvider() for withdrawal-driven removal.
  • Adds v2.1.0 reinitializers (initializeV2_1_0) to both FlyoverDiscovery and CollateralManagement, plus deployment-script wiring.
  • Expands unit/integration/fuzz/invariant coverage for active listing, withdrawals, and “inflated lastProviderId” scenarios.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/pegout/PegOutTestBase.sol Updates test setup to call v2.1.0 initializers.
test/pegin/PegInTestBase.sol Updates test setup to call v2.1.0 initializers.
test/invariant/SystemInvariant.t.sol Initializes v2.1.0 in invariant system setup.
test/invariant/handlers/DiscoveryHandler.sol Extends invariant handler to cover pending-withdraw, resign, and withdraw flows.
test/invariant/DiscoveryInvariant.t.sol Adds/updates invariants for operational listing, uniqueness, and withdrawn filtering.
test/integration/FlyoverDiscovery.t.sol Initializes v2.1.0 in integration setup.
test/integration/CollateralManagement.t.sol Initializes v2.1.0 in integration setup.
test/helpers/FlyoverTestBase.sol Initializes v2.1.0 in shared test base setup.
test/fuzz/discovery/DiscoveryFuzzTestBase.sol Initializes v2.1.0 for discovery fuzz tests.
test/fuzz/discovery/DiscoveryActiveListing.fuzz.t.sol New fuzz suite validating active-index listing behavior under many scenarios.
test/discovery/ListingFilter.t.sol Adds focused tests for pending registrations, withdrawals, and inflated providerId scanning avoidance.
test/discovery/DiscoveryTestBase.sol Adds “no v2.1.0 init” deployment path and upgrade helpers for migration tests.
test/discovery/ActiveListing.t.sol New unit tests for active-index behavior, initialization, and upgrade/migration scenarios.
test/differential/DifferentialParity.diff.t.sol Adjusts BTC address helper to vary by network (mainnet/testnet) in differential tests.
test/differential/base/DifferentialBase.sol Adds env override for reference address and deploy options tweaks for differential harness.
test/deployment/DeployFlyoverDiscovery.t.sol Extends deployment test to run v2.1.0 initialization during flow.
test/deployment/DeployFlyover.t.sol Runs v2.1.0 initialization in full deployment tests.
test/Benchmark.t.sol Initializes v2.1.0 for benchmark setup.
src/test-contracts/CollateralManagementMock.sol Adds setFlyoverDiscovery surface and event to match new interface usage in tests.
src/interfaces/IFlyoverDiscovery.sol Adds removeProvider(address) to discovery interface.
src/interfaces/ICollateralManagement.sol Adds setFlyoverDiscovery(address) to collateral management interface.
src/FlyoverDiscovery.sol Implements active provider index, migration initializer, and removeProvider().
src/CollateralManagement.sol Adds discovery pointer + initializer + setter; notifies discovery on full collateral withdrawal.
script/deployment/DeployFlyoverDiscovery.s.sol Initializes discovery + collateral management v2.1.0 during discovery deployment.
script/deployment/DeployFlyover.s.sol Initializes discovery + collateral management v2.1.0 during full deployment.
script/deployment/DeployCollateralManagement.s.sol Optionally initializes CM v2.1.0 with discovery proxy from env.
addresses.json Adds LiquidityBridgeContract addresses for networks.

Comment thread test/discovery/DiscoveryTestBase.sol
Comment thread test/deployment/DeployFlyoverDiscovery.t.sol
Comment thread test/discovery/ActiveListing.t.sol
Comment thread src/FlyoverDiscovery.sol
Comment on lines +84 to +88
lp = _liquidityProviders[i];
if (_collateralManagement.isRegistered(lp.providerType, lp.providerAddress)) {
_addActiveProvider(i);
_registrationStates[lp.providerAddress] = RegistrationState.Approved;
}
Comment on lines +148 to +150
if (address(flyoverDiscovery).code.length == 0) revert Flyover.NoContract(flyoverDiscovery);
_flyoverDiscovery = IFlyoverDiscovery(flyoverDiscovery);
}
Comment on lines +391 to +395
function _notifyCollateralWithdrawal(address providerAddress) private {
if (address(_flyoverDiscovery) != address(0)) {
_flyoverDiscovery.removeProvider(providerAddress);
}
}
@Luisfc68 Luisfc68 marked this pull request as ready for review June 29, 2026 10:42
@Luisfc68 Luisfc68 requested a review from a team as a code owner June 29, 2026 10:42
Copilot AI review requested due to automatic review settings June 29, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.

Comment on lines +59 to +61
function setFlyoverDiscovery(address addr) external {
emit FlyoverDiscoverySet(address(0), addr);
}
Comment thread src/FlyoverDiscovery.sol
Comment on lines +81 to +93
function initializeV2_1_0() external reinitializer(2) onlyRole(DEFAULT_ADMIN_ROLE) {
Flyover.LiquidityProvider storage lp;
bool providerExists;
for (uint i = 1; i < lastProviderId + 1; ++i) {
lp = _liquidityProviders[i];
providerExists = lp.providerAddress != address(0);
if (providerExists) {
_registrationStates[lp.providerAddress] = RegistrationState.Approved;
}
if (providerExists && _collateralManagement.isRegistered(lp.providerType, lp.providerAddress)) {
_addActiveProvider(i);
}
}
Comment on lines +120 to +127
uint256 approved = handler.ghost_approvedCount();
uint256 withdrawn = handler.ghost_withdrawnCount();

assertLe(
discovery.getProviders().length,
approved - withdrawn,
"INVARIANT VIOLATED: Listing larger than active approved providers"
);
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.

3 participants