Skip to content

Commit

Permalink
Merge branch 'vote-tally' of protocol-github:consensus-shipyard/ipc i…
Browse files Browse the repository at this point in the history
…nto refactor-syncer
  • Loading branch information
cryptoAtwill committed Jan 6, 2025
2 parents 7434eba + 3b59306 commit cee0e11
Show file tree
Hide file tree
Showing 71 changed files with 2,328 additions and 943 deletions.
132 changes: 60 additions & 72 deletions .github/workflows/auto-deploy-contracts.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Auto deploy IPC contracts when changed
name: Auto-deploy IPC contracts to Calibrationnet when changed

on:
workflow_dispatch:
Expand All @@ -8,6 +8,9 @@ on:
paths:
- contracts/**

permissions:
contents: write

env:
GIT_USERNAME: github-actions[bot]
GIT_EMAIL: ipc+github-actions[bot]@users.noreply.github.com
Expand All @@ -20,106 +23,91 @@ concurrency:
jobs:
deploy-contracts:
runs-on: ubuntu-latest

env:
RPC_URL: https://calibration.filfox.info/rpc/v1
RPC_URL: https://calibration.filfox.io/rpc/v1
PRIVATE_KEY: ${{ secrets.CONTRACTS_DEPLOYER_PRIVATE_KEY }}
steps:
- name: Checkout cd/contracts branch
uses: actions/checkout@v4
with:
ref: cd/contracts
submodules: recursive
fetch-depth: 0
token: ${{ secrets.WORKFLOW_PAT_JIE }}

- name: (Dry run) Try merge from main branch to see if there's any conflicts that can't be resolved itself
steps:
- name: Configure git
run: |
git show HEAD
git config --global user.name "$GIT_USERNAME"
git config --global user.email "$GIT_EMAIL"
git checkout main
git pull --rebase origin main
git checkout cd/contracts
git merge main --no-edit --allow-unrelated-histories
- name: Checkout the branch that triggered this run
- name: Check out the branch that triggered this run
uses: actions/checkout@v4
with:
# TODO(jie): After switch to workflow_dispatch only, we should use ref_name.
# head_ref only works for workflow triggered by pull requests.
# ref: ${{ github.ref_name }}
ref: ${{ github.head_ref }}
ref: ${{ github.ref_name }}
submodules: recursive
fetch-depth: 0

- uses: pnpm/action-setup@v2

- name: Setup node and npm
- name: Set up node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: 'pnpm-lock.yaml'
node-version: '21'
cache: 'pnpm'

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Deploy IPC contracts to calibration net
- name: Restore cache
id: cache-restore
uses: actions/cache/restore@v4
with:
## Hardhat is intelligent enough to perform incremental compilation. But GitHub Actions caches are immutable.
## Since we can't have a rolling cache, we create a new cache for each run, but use restore-keys to load the
## most recently created cache.
## Reference: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
key: ${{ runner.os }}-contracts-artifacts-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-contracts-artifacts-
path: |
contracts/out
contracts/deployments
contracts/artifacts
- name: Deploy IPC contracts to Calibrationnet
id: deploy_contracts
env:
REGISTRY_CREATION_PRIVILEGES: 'unrestricted'
run: |
cd contracts
npm install --save hardhat
output=$(make deploy-stack NETWORK=calibrationnet)
echo "deploy_output<<EOF" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
pnpm install
make deploy-stack NETWORK=calibrationnet
- name: Parse deploy output
run: |
deploy_output='${{ steps.deploy_contracts.outputs.deploy_output }}'
echo "$deploy_output"
deployed_gateway_address=$(echo "$deploy_output" | grep '"Gateway"' | awk -F'"' '{print $4}')
deployed_registry_address=$(echo "$deploy_output" | grep '"SubnetRegistry"' | awk -F'"' '{print $4}')
echo "gateway_address=$deployed_gateway_address" >> $GITHUB_ENV
echo "registry_address=$deployed_registry_address" >> $GITHUB_ENV
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Review deployed addresses
- name: Save cache
id: cache-save
uses: actions/cache/save@v4
if: always() && steps.cache-restore.outputs.cache-hit != 'true'
with:
key: ${{ runner.os }}-contracts-artifacts-${{ github.run_id }}
path: |
contracts/out
contracts/deployments
contracts/artifacts
- name: Populate output
run: |
echo "commit_hash: $commit_hash"
echo "gateway_address: $gateway_address"
echo "registry_address: $registry_address"
cd contracts
jq -n --arg commit "$(git rev-parse HEAD)" \
--arg gateway_addr "$(jq -r '.address' deployments/calibrationnet/GatewayDiamond.json)" \
--arg registry_addr "$(jq -r '.address' deployments/calibrationnet/SubnetRegistryDiamond.json)" \
'{"commit":$commit, "gateway_addr":$gateway_addr, "registry_addr":$registry_addr}' > /tmp/output.json
cat /tmp/output.json
- name: Switch code repo to cd/contracts branch
uses: actions/checkout@v4
with:
ref: cd/contracts
submodules: recursive
fetch-depth: 0
token: ${{ secrets.WORKFLOW_PAT_JIE }}

- name: Merge from main branch and update cd/contracts branch
run: |
git config --global user.name "$GIT_USERNAME"
git config --global user.email "$GIT_EMAIL"
git checkout main
git pull --rebase origin main
git checkout cd/contracts
git merge main --no-edit --allow-unrelated-histories
git push -f origin cd/contracts
- name: Write deployed address to output file
- name: Commit and push deployment info
run: |
mkdir -p deployments
json_str='{"commit":"'$commit_hash'","gateway_addr":"'$gateway_address'","registry_addr":"'$registry_address'"}'
jq -n "$json_str" > deployments/r314159.json
cat deployments/r314159.json
- name: Commit output file and push it to remote repo
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update contract address
branch: cd/contracts
file_pattern: deployments/r314159.json
commit_user_name: ${{env.GIT_USERNAME}}
commit_user_email: ${{env.GIT_EMAIL}}
push_options: '--force'
skip_dirty_check: true
create_branch: true
cp /tmp/output.json deployments/r314159.json
git add deployments/r314159.json
git commit -m "Contracts deployed @ ${{ github.sha }}"
git push origin cd/contracts
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@

All notable changes to this project will be documented in this file.

## [axon-r07] - 2024-12-02

### 🚀 Features

- Enable process metrics (#1180)
- Add `subnet_id` to metrics as a global label (#1204)
- Subnet activity rollups and validator rewards (phase 1) (#1181)
- *(misc)* Examples: validator rewards with ERC20 minting (#1200)

### 🐛 Bug Fixes

- Update deploy command for calibration net (#1184)
- Fix HumanReadable serialization error (#1189)
- Use eth_getTransactionCount(pending) to get nonce (#1194)
- Docs for deploy command (#1191)
- Clippy + upgrade dependencies + Rust 1.81.0 (#1188)
- For "Nonce Has Already Been Used" Issue During Deployment on Calibrationnet (#1186)
- Add `--artifacts-path` flag documentation (#1199)
- Install target arch (#1203)
- Metrics validator label to use address instead of pk struct formatting (#1201)
- Update deploy-registry.ts (#1206)
- Fix inconsistent network btw eth and fendermint (#1212)
- Improve Gas Fee Estimation by Integrating Filecoin's EIP-1559-Compatible APIs (#1182)

### 🚜 Refactor

- *(ipld)* Migrate metrics scheme (#1207)

### 📚 Documentation

- Add a doc for activity rollups. (#1222)

### ⚙️ Miscellaneous Tasks

- *(release)* Axon-r06. (#1176)
- Upgrade `fvm` and `builtin-actors` versions (#1209)

### Docs

- Fix a broken reference for the subnets webpage (#1178)

## [axon-r06] - 2024-10-18

### 🚀 Features
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

24 changes: 24 additions & 0 deletions contracts/contracts/lib/LibStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ library LibValidatorSet {
return addresses;
}

function listWaitingValidators(ValidatorSet storage validators) internal view returns (address[] memory addresses) {
uint16 size = validators.waitingValidators.getSize();
addresses = new address[](size);
for (uint16 i = 1; i <= size; ) {
addresses[i - 1] = validators.waitingValidators.getAddress(i);
unchecked {
++i;
}
}
return addresses;
}

/// @notice Get the total collateral of *active* validators.
function getTotalActivePower(ValidatorSet storage validators) internal view returns (uint256 collateral) {
uint16 size = validators.activeValidators.getSize();
Expand Down Expand Up @@ -431,6 +443,18 @@ library LibStaking {
return s.validatorSet.waitingValidators.getSize() + s.validatorSet.activeValidators.getSize();
}

/// @notice Returns all active validators.
function listActiveValidators() internal view returns (address[] memory addresses) {
SubnetActorStorage storage s = LibSubnetActorStorage.appStorage();
return s.validatorSet.listActiveValidators();
}

/// @notice Returns all waiting validators.
function listWaitingValidators() internal view returns (address[] memory addresses) {
SubnetActorStorage storage s = LibSubnetActorStorage.appStorage();
return s.validatorSet.listWaitingValidators();
}

function getTotalConfirmedCollateral() internal view returns (uint256) {
SubnetActorStorage storage s = LibSubnetActorStorage.appStorage();
return s.validatorSet.getTotalConfirmedCollateral();
Expand Down
10 changes: 10 additions & 0 deletions contracts/contracts/subnet/SubnetActorGetterFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ contract SubnetActorGetterFacet {
validator = s.validatorSet.validators[validatorAddress];
}

/// @notice Returns detailed information about all active validators.
function getActiveValidators() external view returns (address[] memory) {
return LibStaking.listActiveValidators();
}

/// @notice Returns detailed information about all waiting validators.
function getWaitingValidators() external view returns (address[] memory) {
return LibStaking.listWaitingValidators();
}

/// @notice Returns the total number of validators (active and waiting).
function getTotalValidatorsNumber() external view returns (uint16) {
return LibStaking.totalValidators();
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/helpers/SelectorLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ library SelectorLibrary {
if (keccak256(abi.encodePacked(facetName)) == keccak256(abi.encodePacked("SubnetActorGetterFacet"))) {
return
abi.decode(
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000203354c3e10000000000000000000000000000000000000000000000000000000035142c8c0000000000000000000000000000000000000000000000000000000006c46853000000000000000000000000000000000000000000000000000000004b27aa72000000000000000000000000000000000000000000000000000000004b0694e200000000000000000000000000000000000000000000000000000000b6797d3c000000000000000000000000000000000000000000000000000000008ef3f76100000000000000000000000000000000000000000000000000000000e02d971b00000000000000000000000000000000000000000000000000000000903e693000000000000000000000000000000000000000000000000000000000948628a900000000000000000000000000000000000000000000000000000000d92e8f1200000000000000000000000000000000000000000000000000000000c7cda762000000000000000000000000000000000000000000000000000000009754b29e0000000000000000000000000000000000000000000000000000000038a210b30000000000000000000000000000000000000000000000000000000080f76021000000000000000000000000000000000000000000000000000000005dd9147c00000000000000000000000000000000000000000000000000000000d6eb591000000000000000000000000000000000000000000000000000000000332a5ac9000000000000000000000000000000000000000000000000000000001597bf7e0000000000000000000000000000000000000000000000000000000052d182d1000000000000000000000000000000000000000000000000000000001904bb2e00000000000000000000000000000000000000000000000000000000cfca28240000000000000000000000000000000000000000000000000000000040550a1c00000000000000000000000000000000000000000000000000000000d081be03000000000000000000000000000000000000000000000000000000001f3a0e410000000000000000000000000000000000000000000000000000000072d0a0e000000000000000000000000000000000000000000000000000000000599c7bd1000000000000000000000000000000000000000000000000000000009e33bd0200000000000000000000000000000000000000000000000000000000c5ab224100000000000000000000000000000000000000000000000000000000f0cf6c9600000000000000000000000000000000000000000000000000000000ad81e4d60000000000000000000000000000000000000000000000000000000080875df700000000000000000000000000000000000000000000000000000000",
hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000223354c3e10000000000000000000000000000000000000000000000000000000035142c8c0000000000000000000000000000000000000000000000000000000006c46853000000000000000000000000000000000000000000000000000000004b27aa72000000000000000000000000000000000000000000000000000000004b0694e200000000000000000000000000000000000000000000000000000000b6797d3c000000000000000000000000000000000000000000000000000000008ef3f76100000000000000000000000000000000000000000000000000000000e02d971b00000000000000000000000000000000000000000000000000000000903e693000000000000000000000000000000000000000000000000000000000948628a900000000000000000000000000000000000000000000000000000000d92e8f12000000000000000000000000000000000000000000000000000000009de7025800000000000000000000000000000000000000000000000000000000c7cda762000000000000000000000000000000000000000000000000000000009754b29e0000000000000000000000000000000000000000000000000000000038a210b30000000000000000000000000000000000000000000000000000000080f76021000000000000000000000000000000000000000000000000000000005dd9147c00000000000000000000000000000000000000000000000000000000d6eb591000000000000000000000000000000000000000000000000000000000332a5ac9000000000000000000000000000000000000000000000000000000001597bf7e0000000000000000000000000000000000000000000000000000000052d182d1000000000000000000000000000000000000000000000000000000001904bb2e000000000000000000000000000000000000000000000000000000006ad04c7900000000000000000000000000000000000000000000000000000000cfca28240000000000000000000000000000000000000000000000000000000040550a1c00000000000000000000000000000000000000000000000000000000d081be03000000000000000000000000000000000000000000000000000000001f3a0e410000000000000000000000000000000000000000000000000000000072d0a0e000000000000000000000000000000000000000000000000000000000599c7bd1000000000000000000000000000000000000000000000000000000009e33bd0200000000000000000000000000000000000000000000000000000000c5ab224100000000000000000000000000000000000000000000000000000000f0cf6c9600000000000000000000000000000000000000000000000000000000ad81e4d60000000000000000000000000000000000000000000000000000000080875df700000000000000000000000000000000000000000000000000000000",
(bytes4[])
);
}
Expand Down
9 changes: 8 additions & 1 deletion contracts/test/integration/SubnetActorDiamond.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
require(saDiamond.getter().bottomUpCheckPeriod() == params.bottomUpCheckPeriod, "unexpected bottom-up period");
require(saDiamond.getter().majorityPercentage() == params.majorityPercentage, "unexpected majority percentage");
require(saDiamond.getter().getParent().toHash() == _parentId.toHash(), "unexpected parent subnetID hash");
require(saDiamond.getter().genesisValidators().length == 0, "unexpected genesis validators");
require(saDiamond.getter().getActiveValidators().length == 0, "unexpected active validators");
require(saDiamond.getter().getWaitingValidators().length == 0, "unexpected waiting validators");
}

function testSubnetActorDiamondReal_LoupeFunction() public view {
Expand Down Expand Up @@ -137,7 +140,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
TestUtils.ensureBytesEqual(v.metadata, publicKey1);
require(saDiamond.getter().bootstrapped(), "subnet not bootstrapped");
require(!saDiamond.getter().killed(), "subnet killed");
require(saDiamond.getter().genesisValidators().length == 1, "not one validator in genesis");
require(saDiamond.getter().genesisValidators().length == 1, "not 1 genesis validator");
require(saDiamond.getter().getActiveValidators().length == 1, "not 1 active validator");
require(saDiamond.getter().getWaitingValidators().length == 0, "not 0 waiting validator");

(uint64 nextConfigNum, uint64 startConfigNum) = saDiamond.getter().getConfigurationNumbers();
require(nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER, "next config num not 1");
Expand Down Expand Up @@ -183,6 +188,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator1");
require(saDiamond.getter().isActiveValidator(validator2), "not active validator2");
require(!saDiamond.getter().isWaitingValidator(validator2), "waiting validator2");
require(saDiamond.getter().getActiveValidators().length == 2, "not 2 active validators");
require(saDiamond.getter().getWaitingValidators().length == 0, "not 0 waiting validators");

(nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers();
require(
Expand Down
Loading

0 comments on commit cee0e11

Please sign in to comment.