Skip to content

Commit

Permalink
Merge pull request #142 from livepeer/yf/inflationChangeSetter
Browse files Browse the repository at this point in the history
Inflation change and verifier solver setters. Tweak initial parameters
  • Loading branch information
yondonfu authored Jan 15, 2018
2 parents b9f08fd + b09add6 commit 52e2919
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 30 deletions.
9 changes: 9 additions & 0 deletions contracts/token/Minter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ contract Minter is Manager, IMinter {
ParameterUpdate("targetBondingRate");
}

function setInflationChange(uint256 _inflationChange) external onlyControllerOwner {
// Must be valid percentage
require(MathUtils.validPerc(_inflationChange));

inflationChange = _inflationChange;

ParameterUpdate("inflationChange");
}

function transferTokenOwnership(address _newOwner) external onlyControllerOwner {
livepeerToken().transferOwnership(_newOwner);
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/verification/LivepeerVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ contract LivepeerVerifier is Manager, IVerifier {
verificationCodeHash = _verificationCodeHash;
}

function addSolver(address _solver) external onlyControllerOwner {
// Must not be null address
require(_solver != address(0));
// Must not already be a solver
require(!isSolver[_solver]);

solvers.push(_solver);
isSolver[_solver] = true;
}

/*
* @dev Fire VerifyRequest event which solvers should listen for to retrieve verification parameters
*/
Expand Down
20 changes: 10 additions & 10 deletions migrations/migrations.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ module.exports = {
unbondingPeriod: 2
},
jobsManager: {
verificationRate: 1,
verificationRate: 100,
verificationPeriod: 50,
slashingPeriod: 50,
failedVerificationSlashAmount: 20 * PERC_MULTIPLIER,
missedVerificationSlashAmount: 30 * PERC_MULTIPLIER,
doubleClaimSegmentSlashAmount: 40 * PERC_MULTIPLIER,
finderFee: 4 * PERC_MULTIPLIER
failedVerificationSlashAmount: 1,
missedVerificationSlashAmount: .1 * PERC_MULTIPLIER,
doubleClaimSegmentSlashAmount: 3 * PERC_MULTIPLIER,
finderFee: 5 * PERC_MULTIPLIER
},
roundsManager: {
roundLength: 50,
roundLockAmount: 100000
},
faucet: {
faucetAmount: new BigNumber(1000000000000000000000).mul(TOKEN_UNIT),
requestAmount: new BigNumber(1000000).mul(TOKEN_UNIT),
faucetAmount: new BigNumber(10000000).mul(TOKEN_UNIT),
requestAmount: new BigNumber(10).mul(TOKEN_UNIT),
requestWait: 2,
whitelist: []
},
minter: {
inflation: 26 * PERC_MULTIPLIER,
inflationChange: .02 * PERC_MULTIPLIER,
targetBondingRate: 50 * PERC_MULTIPLIER
inflation: .0137 * PERC_MULTIPLIER,
inflationChange: .001 * PERC_MULTIPLIER,
targetBondingRate: 10 * PERC_MULTIPLIER
},
verifier: {
verificationCodeHash: "QmZmvi1BaYSdxM1Tgwhi2mURabh46xCkzuH9PWeAkAZZGc",
Expand Down
12 changes: 6 additions & 6 deletions test/integration/Delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract("Delegation", accounts => {
})

it("registers transcoder 1 that self bonds", async () => {
const amount = new BigNumber(10).mul(TOKEN_UNIT)
const amount = new BigNumber(1).mul(TOKEN_UNIT)
await token.approve(bondingManager.address, amount, {from: transcoder1})
await bondingManager.bond(amount, transcoder1, {from: transcoder1})
await bondingManager.transcoder(10, 5, 100, {from: transcoder1})
Expand All @@ -60,7 +60,7 @@ contract("Delegation", accounts => {
})

it("registers transcoder 2 that self bonds", async () => {
const amount = new BigNumber(10).mul(TOKEN_UNIT)
const amount = new BigNumber(1).mul(TOKEN_UNIT)
await token.approve(bondingManager.address, amount, {from: transcoder2})
await bondingManager.bond(amount, transcoder2, {from: transcoder2})
await bondingManager.transcoder(10, 5, 100, {from: transcoder2})
Expand All @@ -69,7 +69,7 @@ contract("Delegation", accounts => {
})

it("delegator 1 bonds to transcoder 1", async () => {
const amount = new BigNumber(10).mul(TOKEN_UNIT)
const amount = new BigNumber(1).mul(TOKEN_UNIT)
await token.approve(bondingManager.address, amount, {from: delegator1})
await bondingManager.bond(amount, transcoder1, {from: delegator1})

Expand All @@ -78,7 +78,7 @@ contract("Delegation", accounts => {
})

it("delegator 2 bonds to transcoder 1", async () => {
const amount = new BigNumber(10).mul(TOKEN_UNIT)
const amount = new BigNumber(1).mul(TOKEN_UNIT)
await token.approve(bondingManager.address, amount, {from: delegator2})
await bondingManager.bond(amount, transcoder1, {from: delegator2})

Expand All @@ -89,8 +89,8 @@ contract("Delegation", accounts => {
it("delegator 1 delegates to transcoder 2", async () => {
await bondingManager.bond(0, transcoder2, {from: delegator1})

const bond = (await bondingManager.getDelegator(delegator1))[2]
assert.equal(bond, transcoder2, "delegator 1 delegate incorrect")
const delegate = (await bondingManager.getDelegator(delegator1))[2]
assert.equal(delegate, transcoder2, "delegator 1 delegate incorrect")
})

it("delegator 2 delegates to transcoder 2", async () => {
Expand Down
13 changes: 13 additions & 0 deletions test/unit/Minter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ contract("Minter", accounts => {
await fixture.tearDown()
})

describe("setInflationChange", () => {
it("should fail if not called by the Controller's owner", async () => {
await expectThrow(minter.setInflationChange(5, {from: accounts[4]}))
})

it("should set the inflation change", async () => {
await minter.setInflationChange(.1 * PERC_MULTIPLIER)

const inflationChange = await minter.inflationChange.call()
assert.equal(inflationChange, .1 * PERC_MULTIPLIER, "wrong inflation change")
})
})

describe("createRewards", () => {
it("should throw if sender is not bonding manager", async () => {
await expectThrow(minter.createReward(10, 100))
Expand Down
5 changes: 2 additions & 3 deletions truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ module.exports = {
gas: 6700000
},
lpTestNet: {
from: "0x0161e041aad467a890839d5b08b138c1e6373072",
host: "localhost",
port: 8545,
network_id: 777,
gas: 6700000
network_id: 858585,
gas: 6600000
}
},
solc: {
Expand Down
48 changes: 37 additions & 11 deletions verification_test/LivepeerVerifier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Fixture from "../test/helpers/fixture"
import expectThrow from "../test/helpers/expectThrow"
import ethUtil from "ethereumjs-util"
import ethAbi from "ethereumjs-abi"

const LivepeerVerifier = artifacts.require("LivepeerVerifier")

Expand Down Expand Up @@ -35,27 +37,48 @@ contract("LivepeerVerifier", accounts => {
})
})

describe("addSolver", () => {
it("should fail for null address", async () => {
await expectThrow(verifier.addSolver("0x0"))
})

it("should fail if solver is already whitelisted", async () => {
await expectThrow(verifier.addSolver(accounts[0]))
})

it("should whitelist a new solver", async () => {
await verifier.addSolver(accounts[3])

const isSolver = await verifier.isSolver.call(accounts[3])
assert.isOk(isSolver, "did not whitelist new solver")
const solverAddress = await verifier.solvers.call(2)
assert.equal(solverAddress, accounts[3], "wrong solver address")
})
})

describe("verify", () => {
const jobId = 0
const claimId = 0
const segmentNumber = 0
const transcodingOptions = "0x123"
const dataStorageHash = "0x123"
const transcodedDataHash = web3.sha3("hello")
const dataHashes = [web3.sha3("apple"), web3.sha3("pear")]

it("should fail if sender is not the JobsManager", async () => {
await expectThrow(verifier.verify(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash))
await expectThrow(verifier.verify(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes))
})

it("should store a request", async () => {
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
await fixture.jobsManager.callVerify()

const commitHash = ethUtil.bufferToHex(ethAbi.soliditySHA3(["bytes", "bytes"], [ethUtil.toBuffer(dataHashes[0]), ethUtil.toBuffer(dataHashes[1])]))

const request = await verifier.requests.call(0)
assert.equal(request[0], jobId, "job id incorrect")
assert.equal(request[1], claimId, "claim id incorrect")
assert.equal(request[2], segmentNumber, "segment number incorrect")
assert.equal(request[3], transcodedDataHash, "transcoded data hash incorrect")
assert.equal(request[3], commitHash, "commit hash incorrect")
})

it("should fire a VerifyRequest event", async () => {
Expand All @@ -70,10 +93,11 @@ contract("LivepeerVerifier", accounts => {
assert.equal(result.args.segmentNumber, segmentNumber, "event segmentNumber incorrect")
assert.equal(result.args.transcodingOptions, transcodingOptions, "event transcodingOptions incorrect")
assert.equal(result.args.dataStorageHash, dataStorageHash, "event dataStorageHash incorrect")
assert.equal(result.args.transcodedDataHash, transcodedDataHash, "event transcodedDataHash incorrect")
assert.equal(result.args.dataHash, dataHashes[0], "event dataHash incorrect")
assert.equal(result.args.transcodedDataHash, dataHashes[1], "event transcodedDataHash incorrect")
})

await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
await fixture.jobsManager.callVerify()
})
})
Expand All @@ -84,14 +108,14 @@ contract("LivepeerVerifier", accounts => {
const segmentNumber = 0
const transcodingOptions = "0x123"
const dataStorageHash = "0x123"
const transcodedDataHash = web3.sha3("hello")
const dataHashes = [web3.sha3("apple"), web3.sha3("pear")]

it("should fail if sender is not a solver", async () => {
await expectThrow(verifier.__callback(0, "0x123", {from: accounts[3]}))
})

it("should fire a callback event with result set to true if verification succeeded", async () => {
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
await fixture.jobsManager.callVerify()

let e = verifier.Callback({})
Expand All @@ -106,11 +130,12 @@ contract("LivepeerVerifier", accounts => {
assert.equal(result.args.result, true, "callback result incorrect")
})

await verifier.__callback(0, web3.sha3("hello"), {from: accounts[0]})
const commitHash = ethUtil.bufferToHex(ethAbi.soliditySHA3(["bytes", "bytes"], [ethUtil.toBuffer(dataHashes[0]), ethUtil.toBuffer(dataHashes[1])]))
await verifier.__callback(0, commitHash, {from: accounts[0]})
})

it("should fire a callback event with result set to false if verification failed", async () => {
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
await fixture.jobsManager.callVerify()

let e = verifier.Callback({})
Expand All @@ -125,7 +150,8 @@ contract("LivepeerVerifier", accounts => {
assert.equal(result.args.result, false, "callback result incorrect")
})

await verifier.__callback(0, web3.sha3("not hello"), {from: accounts[0]})
const wrongCommitHash = ethUtil.bufferToHex(ethAbi.soliditySHA3(["bytes", "bytes"], [ethUtil.toBuffer(dataHashes[0]), ethUtil.toBuffer(web3.sha3("not pear"))]))
await verifier.__callback(0, wrongCommitHash, {from: accounts[0]})
})
})
})

0 comments on commit 52e2919

Please sign in to comment.