Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std #1

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open

Std #1

wants to merge 100 commits into from

Conversation

theref
Copy link
Owner

@theref theref commented Jan 16, 2025

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:

High-level idea of the changes introduced in this PR.
List relevant API changes (if any), as well as related PRs and issues.

Issues fixed/closed:

  • Fixes #...

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on?
Is there a particular commit/function/section of your PR that requires more attention from reviewers?

Summary by Sourcery

Upgrade contracts to use a new Ritual struct, and add a treasury role to the Coordinator contract. Migrate existing rituals to the new struct.

manumonti and others added 30 commits June 14, 2024 14:25
Script that lists all the active rituals that a specified staking provider is participating in
Coordinator: moves rituals from array to mapping
…es to ape 0.8.8 but not to ape 0.7.x which we currently use.
Undo previous change regarding how receipts were obtained
Add duration calculation for subscription based rituals
…ifferent than /bucket_sampling used on mainnet.
Don't check for ape-infura when not using infura
derekpierre and others added 27 commits September 5, 2024 10:10
Relock dependencies to use `ape-etherscan` >= 0.8.3
…st-deployment. The contracts can either be obtained from the common domain registry, or a customized registry path.

Ensure that implementation contract for proxies are the contracts being verified.
…script

Working contract verification script to verify individual contracts post-deployment
Add function to withdraw all tokens from Coordinator for a token address
Move some common test definitions to conftest.py
Make Coordinator aware of transcript size
ReimbursementPool on Polygon Mainnet
Update Coordinator ABI on mainnet registry
Copy link

ellipsis-dev bot commented Jan 16, 2025

Your free trial has expired. To keep using Ellipsis, sign up at https://app.ellipsis.dev or contact us.

Copy link

sourcery-ai bot commented Jan 16, 2025

Reviewer's Guide by Sourcery

This pull request introduces several changes to the Coordinator contract, primarily to support upgrades and improve functionality. It also updates the requirements for several dependencies.

Class diagram showing changes to Coordinator contract

classDiagram
    class Coordinator {
        +mapping(uint256 => Ritual) _rituals
        +uint256 numberOfRituals
        -mapping(address => ParticipantKey[]) participantKeysHistory
        -mapping(bytes32 => uint32) ritualPublicKeyRegistry
        -mapping(IFeeModel => bool) feeModelsRegistry
        +initializeNumberOfRituals()
        +rituals(uint256 ritualId)
        -storageRitual(uint32 ritualId)
        +withdrawAllTokens(IERC20 token)
    }
    note for Coordinator "Changed storage layout:
    - Removed rituals array
    - Added _rituals mapping
    - Added numberOfRituals counter"
Loading

Class diagram showing new ReimbursementPool contract

classDiagram
    class ReimbursementPool {
        +mapping(address => bool) isAuthorized
        +uint256 staticGas
        +uint256 maxGasPrice
        +constructor(uint256 _staticGas, uint256 _maxGasPrice)
        +refund(uint256 gasSpent, address receiver)
        +authorize(address _contract)
        +unauthorize(address _contract)
        +setStaticGas(uint256 _staticGas)
        +setMaxGasPrice(uint256 _maxGasPrice)
        +withdrawAll(address receiver)
        +withdraw(uint256 amount, address receiver)
    }
    ReimbursementPool --|> Ownable
    ReimbursementPool --|> ReentrancyGuard
    ReimbursementPool --|> IReimbursementPool
Loading

Class diagram showing BqETHSubscription renamed to StandardSubscription

classDiagram
    class StandardSubscription {
        +struct Billing
    }
    StandardSubscription --|> EncryptorSlotsSubscription
    StandardSubscription --|> Initializable
    StandardSubscription --|> OwnableUpgradeable
    note for StandardSubscription "Renamed from BqETHSubscription
No functional changes"
Loading

File-Level Changes

Change Details Files
Updated Coordinator contract to support upgrades and added several new functions.
  • Added initializeNumberOfRituals function to initialize the number of rituals after an upgrade.
  • Added withdrawAllTokens function to allow withdrawal of ERC20 tokens.
  • Added expectedTranscriptSize function to calculate the expected size of a transcript.
  • Modified postTranscript and postAggregation to check for valid transcript size.
  • Added storage for old rituals to maintain compatibility after upgrade.
  • Added new storage variables and mappings to support new functionality.
contracts/contracts/coordination/Coordinator.sol
Added ExtendedCoordinator contract for testing upgrade functionality.
  • Added initiateOldRitual function to simulate the old ritual initiation process.
contracts/test/CoordinatorTestSet.sol
Added upgrade tests for the Coordinator contract.
  • Added test_upgrade function to verify the upgrade process and data migration.
tests/test_coordinator.py
Added withdraw_tokens test case.
  • Added test_withdraw_tokens function to verify the withdrawal of tokens by the treasury.
tests/test_coordinator.py
Updated requirements for several dependencies.
  • Updated versions of various packages, including aiohttp, ape-etherscan, ape-infura, ape-polygon, ape-solidity, eth-abi, eth-account, eth-ape, and others.
requirements.txt
Refactored transcript size calculation and generation.
  • Moved transcript size calculation and generation to conftest.py.
  • Replaced approximated transcript size calculation with precise one.
  • Removed transcript_size function from test_coordinator.py and test_global_allow_list.py.
tests/test_coordinator.py
tests/test_global_allow_list.py
tests/conftest.py
Added ritual state constants to conftest.py.
  • Moved RitualState enum to conftest.py.
  • Removed RitualState enum from test_coordinator.py and test_global_allow_list.py.
tests/test_coordinator.py
tests/test_global_allow_list.py
tests/conftest.py
Added public key generation function to conftest.py.
  • Moved gen_public_key function to conftest.py.
  • Removed gen_public_key function from test_coordinator.py and test_global_allow_list.py.
tests/test_coordinator.py
tests/test_global_allow_list.py
tests/conftest.py
Removed unused fixture and imports.
  • Removed unused nu_token fixture.
  • Removed unused imports.
tests/test_coordinator.py
tests/test_global_allow_list.py
Removed selfdestruct tests.
  • Removed test_selfdestruct function.
tests/test_dispatcher.py
Improved deployment scripts.
  • Added non-interactive mode to Deployer.
  • Added support for specifying contract name and registry filepath in verify script.
  • Improved ritual initiation script to handle subscriptions and calculate duration.
deployment/params.py
scripts/verify.py
scripts/initiate_ritual.py
Added new events and improved event handling.
  • Added RewardsWithdrawn event to TACoApplication.
  • Improved event handling in test_reward.py to check for RewardsWithdrawn event.
contracts/contracts/TACoApplication.sol
tests/application/test_reward.py
Added deployment test and registry scripts to CI workflow.
  • Added a deployment test to the CI workflow.
  • Added registry scripts to list contracts for different domains.
.github/workflows/main.yaml
Updated ape configuration.
  • Removed import remappings.
  • Updated solidity and evm versions.
ape-config.yaml
Renamed BqETHSubscription to StandardSubscription.
  • Renamed files and classes related to BqETHSubscription to StandardSubscription.
scripts/lynx/deploy_bqeth.py
scripts/lynx/coordinator_approve_bqeth_fee_model.py
scripts/mainnet/deploy_bqeth.py
tests/test_bqeth_subscription.py
contracts/contracts/coordination/subscription/BqETHSubscription.sol
tests/test_bqeth_subscription.py
deployment/constructor_params/lynx/bqeth.yml
deployment/constructor_params/mainnet/bqeth.yml
deployment/options.py
contracts/test/BqETHSubscriptionTestSet.sol
Improved ritual state check script.
  • Added output for missing transcripts and aggregations.
  • Added fee model information to the output.
scripts/ritual_state_check.py
Added new deployment scripts for StandardSubscription.
  • Added scripts to deploy StandardSubscription on Tapir.
scripts/tapir/deploy_standard_subscription.py
deployment/constructor_params/tapir/bqeth.yml
Added upgrade script for Coordinator on Tapir.
  • Added script to upgrade Coordinator on Tapir.
scripts/tapir/upgrade_coordinator.py
deployment/constructor_params/tapir/upgrade-coordinator.yml
Added new deployment scripts for ReimbursementPool.
  • Added scripts to deploy and configure ReimbursementPool on Lynx and Mainnet.
scripts/lynx/deploy_reimbursement_pool.py
scripts/mainnet/deploy_reimbursement_pool.py
scripts/lynx/coordinator_sets_reimbursement_pool.py
deployment/constructor_params/mainnet/reimbursement-pool.yml
deployment/constructor_params/lynx/reimbursement-pool.yml
Added new deployment scripts for FreeFeeModel on Tapir.
  • Added scripts to deploy and configure FreeFeeModel on Tapir.
scripts/tapir/deploy_free_fee_model.py
scripts/tapir/coordinator_approve_free_fee_model.py
deployment/constructor_params/tapir/free-fee-model.yml
Added ritual membership script.
  • Added script to list active ritual memberships for a staking provider.
scripts/ritual_membership.py
Added CI deployment script.
  • Added script to deploy contracts for CI testing.
scripts/ci/deploy_child.py
deployment/constructor_params/ci/child.yml
Added new deployment scripts for StandardSubscription on Mainnet.
  • Added scripts to deploy StandardSubscription on Mainnet.
scripts/mainnet/deploy_standard_subscription.py
deployment/constructor_params/mainnet/new-subscription.yml
Added ReimbursementPool contract.
  • Added contract to manage reimbursements for gas costs.
contracts/contracts/coordination/ReimbursementPool.sol
Added IReimbursementPool interface.
  • Added interface for ReimbursementPool contract.
contracts/contracts/coordination/IReimbursementPool.sol

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @theref - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding documentation about the upgrade process and reimbursement pool configuration to help users understand these significant new features
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -105,30 +106,55 @@ def cli(
message="Cannot specify --min-version when using --handpicked.",
)

# Get the contracts from the registry
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extracting the subscription duration calculation logic into a helper function to improve readability and maintainability.

The subscription duration calculation logic adds unnecessary complexity to the CLI script. Extract this into a helper function to improve readability:

def get_ritual_duration(fee_model: str, fee_model_contract, duration: int | None) -> int:
    if fee_model != "BqETHSubscription":
        if not duration:
            raise click.BadOptionUsage("--duration", "Duration is required for non-subscription rituals")
        return duration

    total_duration = (
        fee_model_contract.subscriptionPeriodDuration()
        + fee_model_contract.yellowPeriodDuration()
        + fee_model_contract.redPeriodDuration()
    )

    start = fee_model_contract.startOfSubscription()
    if start == 0:
        return total_duration

    end = fee_model_contract.getEndOfSubscription()
    now = chain.blocks.head.timestamp
    if now > end:
        raise ValueError("Subscription has already ended.")

    return total_duration - (now - start + 100)

This improves the main flow by:

  1. Separating subscription logic from ritual initiation
  2. Reducing nesting depth
  3. Making the duration calculation more explicit
  4. Handling validation consistently

num_rituals = coordinator.numberOfRituals()

ritual_memberships = []
for ritual_id in range(0, num_rituals):
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace range(0, x) with range(x) (remove-zero-from-range)

Suggested change
for ritual_id in range(0, num_rituals):
for ritual_id in range(num_rituals):


ExplanationThe default starting value for a call to range() is 0, so it is unnecessary to
explicitly define it. This refactoring removes such zeros, slightly shortening
the code.

from eth_account import Account
from hexbytes import HexBytes
from web3 import Web3

from tests.conftest import ONE_DAY, gen_public_key, generate_transcript, RitualState
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

@@ -6,41 +6,13 @@
from eth_account.messages import encode_defunct
from web3 import Web3

from tests.conftest import gen_public_key, generate_transcript
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

Comment on lines +513 to +519
result = method(
*args,
sender=self._account,
# FIXME: Manual gas fees - #199
# max_priority_fee="3 gwei",
# max_fee="120 gwei"
)
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines +657 to 658
wrapped_instance = getattr(project, implementation.contract_type.name).at(proxy_address)
return wrapped_instance
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
wrapped_instance = getattr(project, implementation.contract_type.name).at(proxy_address)
return wrapped_instance
return getattr(project, implementation.contract_type.name).at(proxy_address)

Comment on lines +206 to 207
result = sorted(ursulas, key=lambda x: x.lower())
return result
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
result = sorted(ursulas, key=lambda x: x.lower())
return result
return sorted(ursulas, key=lambda x: x.lower())

)
verify_contracts(list(contracts.values()))
def cli(network, domain, contract_name, registry_filepath):
"""Verify a deployed contract."""
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

Comment on lines +75 to 76
proxy_contract = project.ExtendedCoordinator.at(proxy.address)
return proxy_contract
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
proxy_contract = project.ExtendedCoordinator.at(proxy.address)
return proxy_contract
return project.ExtendedCoordinator.at(proxy.address)

Comment on lines +104 to +105
proxy_contract = project.GlobalAllowList.at(proxy.address)
return proxy_contract
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
proxy_contract = project.GlobalAllowList.at(proxy.address)
return proxy_contract
return project.GlobalAllowList.at(proxy.address)

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.

6 participants