diff --git a/configuration/configuration.js b/configuration/configuration.js new file mode 100644 index 0000000..22541be --- /dev/null +++ b/configuration/configuration.js @@ -0,0 +1,33 @@ +const fs = require("fs") + +const BASE_PATH = __dirname + "/networks" + +const DEFAULT_CONFIGURATION = { + collateral: { + repairRewardPercentage: 10, + maxNumberOfSlashes: 2, + slashCriterion: 2, + slashPercentage: 20, + }, + proofs: { + // period has to be less than downtime * blocktime + period: 120, // seconds + timeout: 30, // seconds + downtime: 64, // number of blocks + downtimeProduct: 67 // number of blocks + }, + reservations: { + maxReservations: 3 + } +} + +function loadConfiguration(name) { + const path = `${BASE_PATH}/${name}/configuration.js` + if(fs.existsSync(path)) { + return require(path) + } else { + return DEFAULT_CONFIGURATION + } +} + +module.exports = { loadConfiguration } diff --git a/configuration/networks/hardhat/configuration.js b/configuration/networks/hardhat/configuration.js new file mode 100644 index 0000000..b15d587 --- /dev/null +++ b/configuration/networks/hardhat/configuration.js @@ -0,0 +1,19 @@ +module.exports = { + collateral: { + repairRewardPercentage: 10, + maxNumberOfSlashes: 2, + slashCriterion: 2, + slashPercentage: 20, + }, + proofs: { + // period has to be less than downtime * blocktime + // blocktime can be 1 second with hardhat in automine mode + period: 60, // seconds + timeout: 30, // seconds + downtime: 64, // number of blocks + downtimeProduct: 67 // number of blocks + }, + reservations: { + maxReservations: 3 + } +} diff --git a/deploy/marketplace.js b/deploy/marketplace.js index c4cc9db..d1cb51d 100644 --- a/deploy/marketplace.js +++ b/deploy/marketplace.js @@ -1,25 +1,5 @@ const { loadZkeyHash } = require("../verifier/verifier.js") - -// marketplace configuration -const CONFIGURATION = { - collateral: { - repairRewardPercentage: 10, - maxNumberOfSlashes: 2, - slashCriterion: 2, - slashPercentage: 20, - }, - proofs: { - period: 60, - timeout: 30, - // `downtime` needs to be larger than `period` when running hardhat - // in automine mode, because it can produce a block every second - downtime: 64, - downtimeProduct: 67 - }, - reservations: { - maxReservations: 3 - } -} +const { loadConfiguration } = require("../configuration/configuration.js") async function mine256blocks({ network, ethers }) { if (network.tags.local) { @@ -32,7 +12,7 @@ async function deployMarketplace({ deployments, getNamedAccounts }) { const token = await deployments.get("TestToken") const verifier = await deployments.get("Groth16Verifier") const zkeyHash = loadZkeyHash(network.name) - let configuration = CONFIGURATION + let configuration = loadConfiguration(network.name) configuration.proofs.zkeyHash = zkeyHash const args = [configuration, token.address, verifier.address] const { deployer: from } = await getNamedAccounts() @@ -52,7 +32,7 @@ async function deployTestMarketplace({ const token = await deployments.get("TestToken") const verifier = await deployments.get("TestVerifier") const zkeyHash = loadZkeyHash(network.name) - let configuration = CONFIGURATION + let configuration = loadConfiguration(network.name) configuration.proofs.zkeyHash = zkeyHash const args = [configuration, token.address, verifier.address] const { deployer: from } = await getNamedAccounts()