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

Upgrade lynx Coordinator #312

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,43 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
}
}

function rituals(uint32 ritualId) public view returns (Ritual memory) {
return storageRitual(ritualId);
function rituals(
uint256 ritualId // uint256 for backward compatibility
)
external
view
returns (
address initiator,
uint32 initTimestamp,
uint32 endTimestamp,
uint16 totalTranscripts,
uint16 totalAggregations,
//
address authority,
uint16 dkgSize,
uint16 threshold,
bool aggregationMismatch,
//
IEncryptionAuthorizer accessController,
BLS12381.G1Point memory publicKey,
bytes memory aggregatedTranscript,
IFeeModel feeModel
Comment on lines +147 to +161
Copy link
Member

Choose a reason for hiding this comment

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

What about we create a dummy struct for this? Something like RitualView or along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

I doubt it will look any better, but if you want I can do that

Copy link
Member

Choose a reason for hiding this comment

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

If you don't think it's worth it, then it's fine, let's keep it this way

)
{
Ritual storage ritual = storageRitual(uint32(ritualId));
initiator = ritual.initiator;
initTimestamp = ritual.initTimestamp;
endTimestamp = ritual.endTimestamp;
totalTranscripts = ritual.totalTranscripts;
totalAggregations = ritual.totalAggregations;
authority = ritual.authority;
dkgSize = ritual.dkgSize;
threshold = ritual.threshold;
aggregationMismatch = ritual.aggregationMismatch;
accessController = ritual.accessController;
publicKey = ritual.publicKey;
aggregatedTranscript = ritual.aggregatedTranscript;
feeModel = ritual.feeModel;
}

// for backward compatibility
Expand All @@ -152,7 +187,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
}

function getInitiator(uint32 ritualId) external view returns (address) {
return rituals(ritualId).initiator;
return storageRitual(ritualId).initiator;
}

function getTimestamps(
Expand Down Expand Up @@ -377,7 +412,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
}

function getAuthority(uint32 ritualId) external view returns (address) {
return rituals(ritualId).authority;
return storageRitual(ritualId).authority;
}

function postAggregation(
Expand Down
11 changes: 9 additions & 2 deletions deployment/artifacts/lynx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,13 @@
],
"outputs": []
},
{
"type": "function",
"name": "initializeNumberOfRituals",
"stateMutability": "nonpayable",
"inputs": [],
"outputs": []
},
{
"type": "function",
"name": "initiateRitual",
Expand Down Expand Up @@ -4844,7 +4851,7 @@
"stateMutability": "view",
"inputs": [
{
"name": "",
"name": "ritualId",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -7054,4 +7061,4 @@
"deployer": "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600"
}
}
}
}
14 changes: 9 additions & 5 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Any, List

from ape import chain, networks
from ape import chain, networks, project
from ape.api import AccountAPI, ReceiptAPI
from ape.cli.choices import select_account
from ape.contracts.base import ContractContainer, ContractInstance, ContractTransactionHandler
Expand Down Expand Up @@ -633,6 +633,13 @@ def _deploy_proxy(
return contract_type_container.at(proxy_contract.address)

def upgrade(self, container: ContractContainer, proxy_address, data=b"") -> ContractInstance:
implementation = self.deploy(container)
# upgrade proxy to implementation
return self.upgradeTo(implementation, proxy_address, data)

def upgradeTo(
self, implementation: ContractInstance, proxy_address, data=b""
) -> ContractInstance:
admin_slot = chain.provider.get_storage_at(address=proxy_address, slot=EIP1967_ADMIN_SLOT)

if admin_slot == EMPTY_BYTES32:
Expand All @@ -645,12 +652,9 @@ def upgrade(self, container: ContractContainer, proxy_address, data=b"") -> Cont
proxy_admin = OZ_DEPENDENCY.ProxyAdmin.at(admin_address)
# TODO: Check that owner of proxy admin is deployer

implementation = self.deploy(container)
# TODO: initialize taco app implementation too

self.transact(proxy_admin.upgradeAndCall, proxy_address, implementation.address, data)

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

def finalize(self, deployments: List[ContractInstance]) -> None:
Expand Down
18 changes: 17 additions & 1 deletion scripts/lynx/upgrade_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from deployment.constants import ARTIFACTS_DIR, CONSTRUCTOR_PARAMS_DIR
from deployment.params import Deployer
from deployment.registry import contracts_from_registry
from deployment.registry import contracts_from_registry, merge_registries

VERIFY = False
CONSTRUCTOR_PARAMS_FILEPATH = CONSTRUCTOR_PARAMS_DIR / "lynx" / "upgrade-coordinator.yml"
LYNX_REGISTRY = ARTIFACTS_DIR / "lynx.json"


def main():
Expand All @@ -18,6 +19,16 @@ def main():
deployer = Deployer.from_yaml(filepath=CONSTRUCTOR_PARAMS_FILEPATH, verify=VERIFY)
instances = contracts_from_registry(filepath=ARTIFACTS_DIR / "lynx.json", chain_id=80002)

# `initializeNumberOfRituals` was used for the original upgrade, but should NOT be
# used for subsequent upgrades of Coordinator
# implementation = deployer.deploy(project.Coordinator)
# encoded_initializer_function = implementation.initializeNumberOfRituals.encode_input()
# encoded_initializer_function = b""
# coordinator = deployer.upgradeTo(
# implementation,
# instances[project.Coordinator.contract_type.name].address,
# encoded_initializer_function,
# )
coordinator = deployer.upgrade(
project.Coordinator, instances[project.Coordinator.contract_type.name].address
)
Expand All @@ -27,3 +38,8 @@ def main():
]

deployer.finalize(deployments=deployments)
merge_registries(
registry_1_filepath=LYNX_REGISTRY,
registry_2_filepath=deployer.registry_filepath,
output_filepath=LYNX_REGISTRY,
)
1 change: 1 addition & 0 deletions scripts/ritual_state_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def cli(network, domain, ritual_id, realtime):
f"\tAccessController : "
f"{ritual.accessController} {'(GlobalAllowList)' if isGlobalAllowList else ''}"
)
print(f"\tFee Model : {ritual.feeModel}")
print("\tParticipants :")
for participant in participants:
provider = participant.provider
Expand Down
Loading