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

Push the latest contracts #516

Merged
merged 27 commits into from
Jan 10, 2024
Merged
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
44 changes: 44 additions & 0 deletions contracts/.github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Test Workflow
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be integrated in the repo's GitHub workflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


on:
push:
branches:
- main
- dev
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18' # Adjust this as needed for your project

- name: Install dependencies
run: npm install

- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | bash
export PATH="$PATH:/home/runner/.config/.foundry/bin"
foundryup
forge install

- name: Generate Ethereum Private Key and Create .env File and run make
run: |
PRIVATE_KEY=$(node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
echo "export PRIVATE_KEY=0x$PRIVATE_KEY" > .env
echo "export RPC_URL=http://127.0.0.1:1337" >> .env
echo "export CHAIN_ID=1337" >> .env
export PATH="$PATH:/home/runner/.config/.foundry/bin"
npx ganache-cli -g0 -p1337 --account 0x$PRIVATE_KEY,1001901919191919191 &
sleep 5
make


6 changes: 6 additions & 0 deletions contracts/Makefile
Original file line number Diff line number Diff line change
@@ -10,6 +10,12 @@ OUTPUT ?= out
deploy-ipc:
./ops/deploy.sh $(NETWORK)

deploy-subnet-registry:
./ops/deploy-subnet-registry.sh $(NETWORK)

deploy-subnet:
./ops/deploy-subnet.sh $(NETWORK)

upgrade-gw-diamond:
./ops/upgrade-gw-diamond.sh $(NETWORK)

42 changes: 42 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -49,6 +49,48 @@ To deploy the contracts in some other network configured in the Hardhat config y
make deploy-ipc NETWORK=<network-name>
```

# Upgrading IPC Solidity Contracts

This repository's contracts use the Diamond pattern for upgradability, allowing new features to be added or issues to be corrected without a full redeployment. The upgrade process is automated and includes bytecode verification to ensure the integrity of the changes.

## Automated Upgrade and Bytecode Verification

When you run an upgrade command, the repository's scripts handle several tasks:

1. **Bytecode Verification**: The scripts fetch the bytecode of the currently deployed contracts on an FEVM-powered IPC network using the details stored in local JSON files in the root directory of the git repository. They compare this with the bytecode generated after applying the intended changes on a temporary Ganache network.

2. **Conditional Upgrades**: If the bytecode verification process detects changes that align with the intended upgrades, the `make` command conditionally triggers other scripts to perform the actual upgrade on the network.

## Upgrade Commands

To upgrade a contract, you may use the following commands. The NETWORK parameter is optional; if not specified, the scripts will default to "auto":

- **Gateway Diamond Upgrade**:

```bash
make upgrade-gw-diamond [NETWORK=<network-name>]
```

- **Subnet Actor Diamond Upgrade**:

```bash
make upgrade-sa-diamond [NETWORK=<network-name>]
```

- **Subnet Registry Diamond Upgrade**:
```bash
make upgrade-sr-diamond [NETWORK=<network-name>]
```

After running any of these commands, the scripts will provide transaction details for verification. Check the transaction on the appropriate block explorer to confirm the upgrade's success.

## Important Notes

- The upgrade commands are intended for use by authorized personnel with a deep understanding of the contracts' functionality.
- Ensure that your local repository is up to date with the latest contract code and JSON files before initiating an upgrade.
- Backup all contract data and thoroughly test any new code in a controlled environment prior to an upgrade.
- Monitor the output of the upgrade process carefully for transaction details and to verify its successful completion.

## Branching Strategy

### Production branch
7 changes: 5 additions & 2 deletions contracts/binding/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions contracts/binding/src/lib.rs
Original file line number Diff line number Diff line change
@@ -24,12 +24,18 @@ pub mod xnet_messaging_facet;
#[allow(clippy::all)]
pub mod gateway_messenger_facet;
#[allow(clippy::all)]
pub mod subnet_actor_checkpointing_facet;
#[allow(clippy::all)]
pub mod subnet_actor_diamond;
#[allow(clippy::all)]
pub mod subnet_actor_getter_facet;
#[allow(clippy::all)]
pub mod subnet_actor_manager_facet;
#[allow(clippy::all)]
pub mod subnet_actor_pause_facet;
#[allow(clippy::all)]
pub mod subnet_actor_reward_facet;
#[allow(clippy::all)]
pub mod subnet_registry_diamond;
#[allow(clippy::all)]
pub mod register_subnet_facet;
@@ -50,11 +56,11 @@ fvm_address_conversion!(gateway_getter_facet);
fvm_address_conversion!(bottom_up_router_facet);
fvm_address_conversion!(xnet_messaging_facet);
fvm_address_conversion!(gateway_messenger_facet);
fvm_address_conversion!(subnet_actor_manager_facet);
fvm_address_conversion!(subnet_actor_checkpointing_facet);
fvm_address_conversion!(subnet_actor_getter_facet);
fvm_address_conversion!(lib_gateway);

// The list of contracts that need to convert common types between each other
common_type_conversion!(gateway_getter_facet, subnet_actor_manager_facet);
common_type_conversion!(subnet_actor_getter_facet, bottom_up_router_facet);
common_type_conversion!(subnet_actor_getter_facet, checkpointing_facet);
common_type_conversion!(subnet_actor_getter_facet, xnet_messaging_facet);
33 changes: 5 additions & 28 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { HardhatUserConfig, task } from 'hardhat/config'
import '@typechain/hardhat'
import 'hardhat-storage-layout-changes'

import '@nomicfoundation/hardhat-foundry'
import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy'
import 'hardhat-contract-sizer'

import '@typechain/hardhat'
import dotenv from 'dotenv'
import fs from 'fs'
import 'hardhat-contract-sizer'
import 'hardhat-deploy'
import 'hardhat-storage-layout-changes'
import { HardhatUserConfig, task } from 'hardhat/config'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

dotenv.config()
@@ -193,27 +191,6 @@ task(
},
)

task(
'deploy-subnet',
'Builds and deploys the SubnetActor contract on the selected network',
async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name

const deployments = await getDeployments(network)
const { deploy } = await lazyImport('./scripts/deploy-subnet')

// remove unused lib
delete deployments.libs['StorableMsgHelper']

const subnetDeployment = await deploy(
deployments.Gateway,
deployments.libs,
)

await saveDeployments(network, subnetDeployment)
},
)

task(
'deploy-gw-diamond-and-facets',
'Builds and deploys Gateway Actor diamond and its facets',
19 changes: 19 additions & 0 deletions contracts/ops/deploy-subnet-registry.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll move this file to a top-level dir, but it's fine here for now.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Upgrades IPC Gateway Diamond Facets on an EVM-compatible subnet using hardhat
set -e

if [ $# -ne 1 ]
then
echo "Expected a single argument with the name of the network to deploy (localnet, calibrationnet, mainnet)"
exit 1
fi

NETWORK=$1

if [ "$NETWORK" = "auto" ]; then
echo "[*] Automatically getting chainID for network"
source ops/chain-id.sh
fi


npx hardhat deploy-subnet-registry --network ${NETWORK}
20 changes: 20 additions & 0 deletions contracts/ops/deploy-subnet.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll move this file to a top-level dir, but it's fine here for now.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Upgrades IPC Gateway Diamond Facets on an EVM-compatible subnet using hardhat
set -e

if [ $# -ne 1 ]
then
echo "Expected a single argument with the name of the network to deploy (localnet, calibrationnet, mainnet)"
exit 1
fi

NETWORK=$1

if [ "$NETWORK" = "auto" ]; then
echo "[*] Automatically getting chainID for network"
source ops/chain-id.sh
fi


npx hardhat deploy-sa-diamond-and-facets --network ${NETWORK}

36 changes: 32 additions & 4 deletions contracts/scripts/deploy-registry.template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { deployContractWithDeployer, getTransactionFees } from './util'
import { ethers } from 'hardhat'

const { getSelectors, FacetCutAction } = require('./js/diamond.js')

@@ -31,14 +31,36 @@ export async function deploy() {
const managerFacet = await deployContractWithDeployer(
deployer,
'SubnetActorManagerFacet',
{
LibStaking: LIBMAP['LibStaking'],
},
{},
txArgs,
)
const managerSelectors = getSelectors(managerFacet)
// console.log("manager address:", managerFacet.address);

const pauserFacet = await deployContractWithDeployer(
deployer,
'SubnetActorPauseFacet',
{},
txArgs,
)
const pauserSelectors = getSelectors(pauserFacet)

const rewarderFacet = await deployContractWithDeployer(
deployer,
'SubnetActorRewardFacet',
{ LibStaking: LIBMAP['LibStaking'] },
txArgs,
)
const rewarderSelectors = getSelectors(rewarderFacet)

const checkpointerFacet = await deployContractWithDeployer(
deployer,
'SubnetActorCheckpointingFacet',
{},
txArgs,
)
const checkpointerSelectors = getSelectors(checkpointerFacet)

//deploy subnet registry diamond
const registry = await ethers.getContractFactory('SubnetRegistryDiamond', {
signer: deployer,
@@ -48,8 +70,14 @@ export async function deploy() {
gateway: gatewayAddress,
getterFacet: getterFacet.address,
managerFacet: managerFacet.address,
rewarderFacet: rewarderFacet.address,
pauserFacet: pauserFacet.address,
checkpointerFacet: checkpointerFacet.address,
subnetGetterSelectors: getterSelectors,
subnetManagerSelectors: managerSelectors,
checkpointerSelectors: checkpointerSelectors,
pauserSelectors: pauserSelectors,
rewarderSelectors: rewarderSelectors,
}

const facetCuts = [] //TODO
15 changes: 11 additions & 4 deletions contracts/scripts/deploy-sa-diamond.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hre, { ethers } from 'hardhat'
import { deployContractWithDeployer, getTransactionFees } from './util'
import hre, { ethers } from 'hardhat'

const { getSelectors, FacetCutAction } = require('./js/diamond.js')

@@ -26,15 +26,22 @@ async function deploySubnetActorDiamond(
SubnetIDHelper: libs['SubnetIDHelper'],
}

const managerFacetLibs: Libraries = {
LibStaking: libs['LibStaking'],
}
const managerFacetLibs: Libraries = {}

const rewarderFacetLibs: Libraries = {}

const pauserFacetLibs: Libraries = {}

const checkpointerFacetLibs: Libraries = {}

const facets = [
{ name: 'DiamondLoupeFacet', libs: {} },
{ name: 'DiamondCutFacet', libs: {} },
{ name: 'SubnetActorGetterFacet', libs: getterFacetLibs },
{ name: 'SubnetActorManagerFacet', libs: managerFacetLibs },
{ name: 'SubnetActorRewardFacet', libs: rewarderFacetLibs },
{ name: 'SubnetActorCheckpointingFacet', libs: checkpointerFacetLibs },
{ name: 'SubnetActorPauseFacet', libs: pauserFacetLibs },
]
// The `facetCuts` variable is the FacetCut[] that contains the functions to add during diamond deployment
const facetCuts = []
Loading