Skip to content

Commit 52e2919

Browse files
authored
Merge pull request #142 from livepeer/yf/inflationChangeSetter
Inflation change and verifier solver setters. Tweak initial parameters
2 parents b9f08fd + b09add6 commit 52e2919

File tree

7 files changed

+87
-30
lines changed

7 files changed

+87
-30
lines changed

Diff for: contracts/token/Minter.sol

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ contract Minter is Manager, IMinter {
6767
ParameterUpdate("targetBondingRate");
6868
}
6969

70+
function setInflationChange(uint256 _inflationChange) external onlyControllerOwner {
71+
// Must be valid percentage
72+
require(MathUtils.validPerc(_inflationChange));
73+
74+
inflationChange = _inflationChange;
75+
76+
ParameterUpdate("inflationChange");
77+
}
78+
7079
function transferTokenOwnership(address _newOwner) external onlyControllerOwner {
7180
livepeerToken().transferOwnership(_newOwner);
7281
}

Diff for: contracts/verification/LivepeerVerifier.sol

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ contract LivepeerVerifier is Manager, IVerifier {
5555
verificationCodeHash = _verificationCodeHash;
5656
}
5757

58+
function addSolver(address _solver) external onlyControllerOwner {
59+
// Must not be null address
60+
require(_solver != address(0));
61+
// Must not already be a solver
62+
require(!isSolver[_solver]);
63+
64+
solvers.push(_solver);
65+
isSolver[_solver] = true;
66+
}
67+
5868
/*
5969
* @dev Fire VerifyRequest event which solvers should listen for to retrieve verification parameters
6070
*/

Diff for: migrations/migrations.config.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ module.exports = {
1111
unbondingPeriod: 2
1212
},
1313
jobsManager: {
14-
verificationRate: 1,
14+
verificationRate: 100,
1515
verificationPeriod: 50,
1616
slashingPeriod: 50,
17-
failedVerificationSlashAmount: 20 * PERC_MULTIPLIER,
18-
missedVerificationSlashAmount: 30 * PERC_MULTIPLIER,
19-
doubleClaimSegmentSlashAmount: 40 * PERC_MULTIPLIER,
20-
finderFee: 4 * PERC_MULTIPLIER
17+
failedVerificationSlashAmount: 1,
18+
missedVerificationSlashAmount: .1 * PERC_MULTIPLIER,
19+
doubleClaimSegmentSlashAmount: 3 * PERC_MULTIPLIER,
20+
finderFee: 5 * PERC_MULTIPLIER
2121
},
2222
roundsManager: {
2323
roundLength: 50,
2424
roundLockAmount: 100000
2525
},
2626
faucet: {
27-
faucetAmount: new BigNumber(1000000000000000000000).mul(TOKEN_UNIT),
28-
requestAmount: new BigNumber(1000000).mul(TOKEN_UNIT),
27+
faucetAmount: new BigNumber(10000000).mul(TOKEN_UNIT),
28+
requestAmount: new BigNumber(10).mul(TOKEN_UNIT),
2929
requestWait: 2,
3030
whitelist: []
3131
},
3232
minter: {
33-
inflation: 26 * PERC_MULTIPLIER,
34-
inflationChange: .02 * PERC_MULTIPLIER,
35-
targetBondingRate: 50 * PERC_MULTIPLIER
33+
inflation: .0137 * PERC_MULTIPLIER,
34+
inflationChange: .001 * PERC_MULTIPLIER,
35+
targetBondingRate: 10 * PERC_MULTIPLIER
3636
},
3737
verifier: {
3838
verificationCodeHash: "QmZmvi1BaYSdxM1Tgwhi2mURabh46xCkzuH9PWeAkAZZGc",

Diff for: test/integration/Delegation.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ contract("Delegation", accounts => {
5151
})
5252

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

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

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

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

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

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

92-
const bond = (await bondingManager.getDelegator(delegator1))[2]
93-
assert.equal(bond, transcoder2, "delegator 1 delegate incorrect")
92+
const delegate = (await bondingManager.getDelegator(delegator1))[2]
93+
assert.equal(delegate, transcoder2, "delegator 1 delegate incorrect")
9494
})
9595

9696
it("delegator 2 delegates to transcoder 2", async () => {

Diff for: test/unit/Minter.js

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ contract("Minter", accounts => {
3636
await fixture.tearDown()
3737
})
3838

39+
describe("setInflationChange", () => {
40+
it("should fail if not called by the Controller's owner", async () => {
41+
await expectThrow(minter.setInflationChange(5, {from: accounts[4]}))
42+
})
43+
44+
it("should set the inflation change", async () => {
45+
await minter.setInflationChange(.1 * PERC_MULTIPLIER)
46+
47+
const inflationChange = await minter.inflationChange.call()
48+
assert.equal(inflationChange, .1 * PERC_MULTIPLIER, "wrong inflation change")
49+
})
50+
})
51+
3952
describe("createRewards", () => {
4053
it("should throw if sender is not bonding manager", async () => {
4154
await expectThrow(minter.createReward(10, 100))

Diff for: truffle.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ module.exports = {
2828
gas: 6700000
2929
},
3030
lpTestNet: {
31-
from: "0x0161e041aad467a890839d5b08b138c1e6373072",
3231
host: "localhost",
3332
port: 8545,
34-
network_id: 777,
35-
gas: 6700000
33+
network_id: 858585,
34+
gas: 6600000
3635
}
3736
},
3837
solc: {

Diff for: verification_test/LivepeerVerifier.js

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Fixture from "../test/helpers/fixture"
22
import expectThrow from "../test/helpers/expectThrow"
3+
import ethUtil from "ethereumjs-util"
4+
import ethAbi from "ethereumjs-abi"
35

46
const LivepeerVerifier = artifacts.require("LivepeerVerifier")
57

@@ -35,27 +37,48 @@ contract("LivepeerVerifier", accounts => {
3537
})
3638
})
3739

40+
describe("addSolver", () => {
41+
it("should fail for null address", async () => {
42+
await expectThrow(verifier.addSolver("0x0"))
43+
})
44+
45+
it("should fail if solver is already whitelisted", async () => {
46+
await expectThrow(verifier.addSolver(accounts[0]))
47+
})
48+
49+
it("should whitelist a new solver", async () => {
50+
await verifier.addSolver(accounts[3])
51+
52+
const isSolver = await verifier.isSolver.call(accounts[3])
53+
assert.isOk(isSolver, "did not whitelist new solver")
54+
const solverAddress = await verifier.solvers.call(2)
55+
assert.equal(solverAddress, accounts[3], "wrong solver address")
56+
})
57+
})
58+
3859
describe("verify", () => {
3960
const jobId = 0
4061
const claimId = 0
4162
const segmentNumber = 0
4263
const transcodingOptions = "0x123"
4364
const dataStorageHash = "0x123"
44-
const transcodedDataHash = web3.sha3("hello")
65+
const dataHashes = [web3.sha3("apple"), web3.sha3("pear")]
4566

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

5071
it("should store a request", async () => {
51-
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
72+
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
5273
await fixture.jobsManager.callVerify()
5374

75+
const commitHash = ethUtil.bufferToHex(ethAbi.soliditySHA3(["bytes", "bytes"], [ethUtil.toBuffer(dataHashes[0]), ethUtil.toBuffer(dataHashes[1])]))
76+
5477
const request = await verifier.requests.call(0)
5578
assert.equal(request[0], jobId, "job id incorrect")
5679
assert.equal(request[1], claimId, "claim id incorrect")
5780
assert.equal(request[2], segmentNumber, "segment number incorrect")
58-
assert.equal(request[3], transcodedDataHash, "transcoded data hash incorrect")
81+
assert.equal(request[3], commitHash, "commit hash incorrect")
5982
})
6083

6184
it("should fire a VerifyRequest event", async () => {
@@ -70,10 +93,11 @@ contract("LivepeerVerifier", accounts => {
7093
assert.equal(result.args.segmentNumber, segmentNumber, "event segmentNumber incorrect")
7194
assert.equal(result.args.transcodingOptions, transcodingOptions, "event transcodingOptions incorrect")
7295
assert.equal(result.args.dataStorageHash, dataStorageHash, "event dataStorageHash incorrect")
73-
assert.equal(result.args.transcodedDataHash, transcodedDataHash, "event transcodedDataHash incorrect")
96+
assert.equal(result.args.dataHash, dataHashes[0], "event dataHash incorrect")
97+
assert.equal(result.args.transcodedDataHash, dataHashes[1], "event transcodedDataHash incorrect")
7498
})
7599

76-
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, transcodedDataHash)
100+
await fixture.jobsManager.setVerifyParams(jobId, claimId, segmentNumber, transcodingOptions, dataStorageHash, dataHashes)
77101
await fixture.jobsManager.callVerify()
78102
})
79103
})
@@ -84,14 +108,14 @@ contract("LivepeerVerifier", accounts => {
84108
const segmentNumber = 0
85109
const transcodingOptions = "0x123"
86110
const dataStorageHash = "0x123"
87-
const transcodedDataHash = web3.sha3("hello")
111+
const dataHashes = [web3.sha3("apple"), web3.sha3("pear")]
88112

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

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

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

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

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

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

128-
await verifier.__callback(0, web3.sha3("not hello"), {from: accounts[0]})
153+
const wrongCommitHash = ethUtil.bufferToHex(ethAbi.soliditySHA3(["bytes", "bytes"], [ethUtil.toBuffer(dataHashes[0]), ethUtil.toBuffer(web3.sha3("not pear"))]))
154+
await verifier.__callback(0, wrongCommitHash, {from: accounts[0]})
129155
})
130156
})
131157
})

0 commit comments

Comments
 (0)