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

feat(contracts): numerous improvements to deploy scripts (+). #1108

Merged
merged 9 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .github/workflows/auto-deploy-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
run: |
cd contracts
npm install --save hardhat
output=$(make deploy-ipc NETWORK=calibrationnet)
output=$(make deploy-stack NETWORK=calibrationnet)
echo "deploy_output<<EOF" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contracts-deployment-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
export PATH="$PATH:/home/runner/.config/.foundry/bin"
pnpm exec ganache-cli -g0 -p1337 --account 0x$PRIVATE_KEY,1001901919191919191 &
sleep 5
make deploy-ipc
make deploy-stack
2 changes: 1 addition & 1 deletion .github/workflows/contracts-pnpm-audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: NPM Audit
run: |
cd contracts
pnpm audit
pnpm audit --audit-level=moderate
14 changes: 0 additions & 14 deletions .github/workflows/contracts-sast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,3 @@ jobs:
run: cd contracts && pnpm exec prettier --check 'contracts/**/*.sol' 'test/*.sol'
- name: Solhint check
run: cd contracts && pnpm exec solhint 'contracts/**/*.sol'

codespell:
name: Codespell check
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v3
- name: CodeSpell check
uses: codespell-project/[email protected]
with:
check_hidden: true
check_filenames: true
path: contracts/contracts/*,contracts/script/*,contracts/scripts/*,contracts/test/*
ignore_words_file: contracts/.codespellignore
3 changes: 2 additions & 1 deletion .github/workflows/lint-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Lint PR"

on:
pull_request_target:
pull_request:
types:
- opened
- edited
Expand Down Expand Up @@ -29,6 +29,7 @@ jobs:
cli
contracts
core
ci
deps
docker
ethapi
Expand Down
1 change: 0 additions & 1 deletion contracts/.codespellignore

This file was deleted.

1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ solidity-files-cache.json
typechain

# Deploment assets
deployments/
deployments.json
scripts/*.out
scripts/deploy-registry.ts
Expand Down
22 changes: 3 additions & 19 deletions contracts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Targets that are commands.
COMMANDS := deploy-ipc deploy-subnet-registry deploy-subnet upgrade-gw-diamond upgrade-sa-diamond \
upgrade-sr-diamond gen compile-abi rust-binding slither lint fmt deps build \
COMMANDS := deploy-stack gen compile-abi rust-binding slither lint fmt deps build \
test install-dev install-npm-package install-eth-abi storage clean coverage \
prepare build-selector-library forge

Expand Down Expand Up @@ -32,23 +31,8 @@ NETWORK ?= auto
# It is required by docker builds, but shouldn't be checked into git.
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)

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

upgrade-sr-diamond:
./ops/upgrade-sr-diamond.sh $(NETWORK)
deploy-stack:
pnpm exec hardhat deploy-stack --network $(NETWORK)

# ==============================================================================
# Code generation
Expand Down
71 changes: 71 additions & 0 deletions contracts/extensions.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cryptoAtwill @gvelez17 @avichalp here's the extension that injects a custom provider to deal with null rounds through the RPC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xBalbinus @rk-rishikesh I'll submit this to the Hardhat FEVM kit so Filecoin devs can also benefit.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { extendEnvironment } from 'hardhat/config'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import '@nomiclabs/hardhat-ethers'
import { ProviderError } from 'hardhat/internal/core/providers/errors'

extendEnvironment((hre) => {
injectFilecoinProvider(hre)
})

const emptyBlock = {
number: '0x0',
hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0000000000000000',
sha3Uncles: '0x0000000000000000000000000000000000000000000000000000000000000000',
logsBloom: '0x' + '00'.repeat(256),
transactionsRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
receiptsRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
miner: '0x0000000000000000000000000000000000000000',
difficulty: '0x0',
totalDifficulty: '0x0',
extraData: '0x',
size: '0x0',
gasLimit: '0x0',
gasUsed: '0x0',
timestamp: '0x0',
transactions: [],
uncles: [],
}

function injectFilecoinProvider(hre: HardhatRuntimeEnvironment) {
const interceptedRpcMethods = ['eth_getBlockByNumber', 'eth_getBlockByHash']
hre.network.provider = new Proxy(hre.network.provider, {
get(target, prop, _receiver) {
const orig = (target as any)[prop]
// (prop === 'send' || prop === 'sendAsync')
// Ethers / Web3 / Hardhat provider classes are a mess and they intermix through the call stack.
// With this exact configuration, this code sees ExternalProvider#request(request: { method: string; params?: Array<any>; });
// calls only. But if we switch to Hardhat Ignition, this is likely to change.
if (!(typeof orig === 'function')) {
return orig
}
let methodFunc: (args: any[]) => string
if (prop === 'send' || prop === 'sendAsync') {
methodFunc = ([method]: any[]) => method
} else if (prop === 'request') {
methodFunc = ([{ method }]: any[]) => method
} else {
return orig
}
return async (...args: any[]) => {
try {
return await (target as any)[prop](...args)
} catch (err) {
const method = methodFunc(args)
if (
interceptedRpcMethods.includes(method) &&
err.message.includes('requested epoch was a null round')
) {
console.warn('null round hit, returning empty block')
return emptyBlock
}
console.log(`Rethrowing error ${err}`)
throw err
}
}
},
})
}
Loading
Loading