Skip to content

Commit 11ccefd

Browse files
committed
Different configurations for different networks
By default we have a proof period of 2 minutes, but on hardhat it's 1 minute.
1 parent 1ce3d10 commit 11ccefd

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

configuration/configuration.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require("fs")
2+
3+
const BASE_PATH = __dirname + "/networks"
4+
5+
const DEFAULT_CONFIGURATION = {
6+
collateral: {
7+
repairRewardPercentage: 10,
8+
maxNumberOfSlashes: 2,
9+
slashCriterion: 2,
10+
slashPercentage: 20,
11+
},
12+
proofs: {
13+
// period has to be less than downtime * blocktime
14+
period: 120, // seconds
15+
timeout: 30, // seconds
16+
downtime: 64, // number of blocks
17+
downtimeProduct: 67 // number of blocks
18+
},
19+
reservations: {
20+
maxReservations: 3
21+
}
22+
}
23+
24+
function loadConfiguration(name) {
25+
const path = `${BASE_PATH}/${name}/configuration.js`
26+
if(fs.existsSync(path)) {
27+
return require(path)
28+
} else {
29+
return DEFAULT_CONFIGURATION
30+
}
31+
}
32+
33+
module.exports = { loadConfiguration }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
collateral: {
3+
repairRewardPercentage: 10,
4+
maxNumberOfSlashes: 2,
5+
slashCriterion: 2,
6+
slashPercentage: 20,
7+
},
8+
proofs: {
9+
// period has to be less than downtime * blocktime
10+
// blocktime can be 1 second with hardhat in automine mode
11+
period: 60, // seconds
12+
timeout: 30, // seconds
13+
downtime: 64, // number of blocks
14+
downtimeProduct: 67 // number of blocks
15+
},
16+
reservations: {
17+
maxReservations: 3
18+
}
19+
}

deploy/marketplace.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
const { loadZkeyHash } = require("../verifier/verifier.js")
2-
3-
// marketplace configuration
4-
const CONFIGURATION = {
5-
collateral: {
6-
repairRewardPercentage: 10,
7-
maxNumberOfSlashes: 2,
8-
slashCriterion: 2,
9-
slashPercentage: 20,
10-
},
11-
proofs: {
12-
period: 60,
13-
timeout: 30,
14-
// `downtime` needs to be larger than `period` when running hardhat
15-
// in automine mode, because it can produce a block every second
16-
downtime: 64,
17-
downtimeProduct: 67
18-
},
19-
reservations: {
20-
maxReservations: 3
21-
}
22-
}
2+
const { loadConfiguration } = require("../configuration/configuration.js")
233

244
async function mine256blocks({ network, ethers }) {
255
if (network.tags.local) {
@@ -32,7 +12,7 @@ async function deployMarketplace({ deployments, getNamedAccounts }) {
3212
const token = await deployments.get("TestToken")
3313
const verifier = await deployments.get("Groth16Verifier")
3414
const zkeyHash = loadZkeyHash(network.name)
35-
let configuration = CONFIGURATION
15+
let configuration = loadConfiguration(network.name)
3616
configuration.proofs.zkeyHash = zkeyHash
3717
const args = [configuration, token.address, verifier.address]
3818
const { deployer: from } = await getNamedAccounts()
@@ -52,7 +32,7 @@ async function deployTestMarketplace({
5232
const token = await deployments.get("TestToken")
5333
const verifier = await deployments.get("TestVerifier")
5434
const zkeyHash = loadZkeyHash(network.name)
55-
let configuration = CONFIGURATION
35+
let configuration = loadConfiguration(network.name)
5636
configuration.proofs.zkeyHash = zkeyHash
5737
const args = [configuration, token.address, verifier.address]
5838
const { deployer: from } = await getNamedAccounts()

0 commit comments

Comments
 (0)