Skip to content

Commit e3e3cad

Browse files
authored
Check if params exist before setting them (#231)
* Check if params exist before setting them Fix #228 * Check if gp parameter exist Fix #233
1 parent ab16976 commit e3e3cad

File tree

1 file changed

+95
-70
lines changed

1 file changed

+95
-70
lines changed

migrate-dao.js

Lines changed: 95 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -408,47 +408,52 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
408408
deploymentState.permissions = []
409409
deploymentState.votingMachinesParams = []
410410
}
411+
if (migrationParams.VotingMachinesParams !== undefined && migrationParams.VotingMachinesParams.length > 0) {
412+
if (deploymentState.registeredGenesisProtocolParamsCount === undefined) {
413+
deploymentState.registeredGenesisProtocolParamsCount = 0
414+
}
415+
for (deploymentState.registeredGenesisProtocolParamsCount;
416+
deploymentState.registeredGenesisProtocolParamsCount < migrationParams.VotingMachinesParams.length;
417+
deploymentState.registeredGenesisProtocolParamsCount++) {
418+
spinner.start('Setting GenesisProtocol parameters...')
419+
setState(deploymentState, network)
420+
if (migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votingParamsHash !== undefined) {
421+
deploymentState.votingMachinesParams.push(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votingParamsHash)
422+
setState(deploymentState, network)
423+
continue
424+
}
425+
let parameters = [
426+
[
427+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].queuedVoteRequiredPercentage.toString(),
428+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].queuedVotePeriodLimit.toString(),
429+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].boostedVotePeriodLimit.toString(),
430+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].preBoostedVotePeriodLimit.toString(),
431+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].thresholdConst.toString(),
432+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].quietEndingPeriod.toString(),
433+
web3.utils.toWei(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].proposingRepReward.toString()),
434+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votersReputationLossRatio.toString(),
435+
web3.utils.toWei(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].minimumDaoBounty.toString()),
436+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].daoBountyConst.toString(),
437+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].activationTime.toString()
438+
],
439+
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].voteOnBehalf
440+
]
441+
const genesisProtocolSetParams = genesisProtocol.methods.setParameters(...parameters)
411442

412-
if (deploymentState.registeredGenesisProtocolParamsCount === undefined) {
413-
deploymentState.registeredGenesisProtocolParamsCount = 0
414-
}
415-
for (deploymentState.registeredGenesisProtocolParamsCount;
416-
deploymentState.registeredGenesisProtocolParamsCount < migrationParams.VotingMachinesParams.length;
417-
deploymentState.registeredGenesisProtocolParamsCount++) {
418-
spinner.start('Setting GenesisProtocol parameters...')
419-
setState(deploymentState, network)
420-
if (migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votingParamsHash !== undefined) {
421-
deploymentState.votingMachinesParams.push(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votingParamsHash)
422-
setState(deploymentState, network)
423-
continue
424-
}
425-
let parameters = [
426-
[
427-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].queuedVoteRequiredPercentage.toString(),
428-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].queuedVotePeriodLimit.toString(),
429-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].boostedVotePeriodLimit.toString(),
430-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].preBoostedVotePeriodLimit.toString(),
431-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].thresholdConst.toString(),
432-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].quietEndingPeriod.toString(),
433-
web3.utils.toWei(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].proposingRepReward.toString()),
434-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].votersReputationLossRatio.toString(),
435-
web3.utils.toWei(migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].minimumDaoBounty.toString()),
436-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].daoBountyConst.toString(),
437-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].activationTime.toString()
438-
],
439-
migrationParams.VotingMachinesParams[deploymentState.registeredGenesisProtocolParamsCount].voteOnBehalf
440-
]
441-
const genesisProtocolSetParams = genesisProtocol.methods.setParameters(...parameters)
442-
443-
tx = await genesisProtocolSetParams.send({ nonce: ++nonce })
444-
let votingMachinesParams = await genesisProtocolSetParams.call()
445-
deploymentState.votingMachinesParams.push(votingMachinesParams)
446-
await logTx(tx,
447-
'GenesisProtocol parameters set. | Params Hash: ' +
448-
votingMachinesParams + '\nParameters:\n' +
449-
parameters.toString().replace(/,/g, ',\n')
450-
)
451-
setState(deploymentState, network)
443+
let votingMachinesParams = await genesisProtocolSetParams.call()
444+
const votingMachineCheckParams = await genesisProtocol.methods.parameters(votingMachinesParams).call()
445+
if (votingMachineCheckParams.minimumDaoBounty === 0) {
446+
tx = await genesisProtocolSetParams.send({ nonce: ++nonce })
447+
await logTx(tx,
448+
'GenesisProtocol parameters set. | Params Hash: ' +
449+
votingMachinesParams + '\nParameters:\n' +
450+
parameters.toString().replace(/,/g, ',\n')
451+
)
452+
}
453+
454+
deploymentState.votingMachinesParams.push(votingMachinesParams)
455+
setState(deploymentState, network)
456+
}
452457
}
453458
deploymentState.registeredGenesisProtocolParamsCount++
454459
setState(deploymentState, network)
@@ -476,12 +481,16 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
476481
]
477482
const schemeRegistrarSetParams = schemeRegistrar.methods.setParameters(...parameters)
478483
schemeRegistrarParams = await schemeRegistrarSetParams.call()
479-
tx = await schemeRegistrarSetParams.send({ nonce: ++nonce })
480-
await logTx(tx,
481-
'Scheme Registrar parameters set. | Params Hash: ' +
482-
schemeRegistrarParams + '\nParameters:\n' +
483-
parameters.toString().replace(/,/g, ',\n')
484-
)
484+
485+
const schemeRegistrarCheckParams = await schemeRegistrar.methods.parameters(schemeRegistrarParams).call()
486+
if (schemeRegistrarCheckParams.intVote === '0x0000000000000000000000000000000000000000') {
487+
tx = await schemeRegistrarSetParams.send({ nonce: ++nonce })
488+
await logTx(tx,
489+
'Scheme Registrar parameters set. | Params Hash: ' +
490+
schemeRegistrarParams + '\nParameters:\n' +
491+
parameters.toString().replace(/,/g, ',\n')
492+
)
493+
}
485494

486495
deploymentState.schemeNames.push('Scheme Registrar')
487496
deploymentState.schemes.push(SchemeRegistrar)
@@ -510,12 +519,16 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
510519
: migrationParams.ContributionReward[deploymentState.ContributionRewardParamsCount].votingMachine]
511520
const contributionRewardSetParams = contributionReward.methods.setParameters(...parameters)
512521
contributionRewardParams = await contributionRewardSetParams.call()
513-
tx = await contributionRewardSetParams.send({ nonce: ++nonce })
514-
await logTx(tx,
515-
'Contribution Reward parameters set. | Params Hash: ' +
516-
contributionRewardParams + '\nParameters:' +
517-
parameters.toString().replace(/,/g, ',\n')
518-
)
522+
523+
const contributionRewardCheckParams = await contributionReward.methods.parameters(contributionRewardParams).call()
524+
if (contributionRewardCheckParams.intVote === '0x0000000000000000000000000000000000000000') {
525+
tx = await contributionRewardSetParams.send({ nonce: ++nonce })
526+
await logTx(tx,
527+
'Contribution Reward parameters set. | Params Hash: ' +
528+
contributionRewardParams + '\nParameters:' +
529+
parameters.toString().replace(/,/g, ',\n')
530+
)
531+
}
519532

520533
deploymentState.schemeNames.push('Contribution Reward')
521534
deploymentState.schemes.push(ContributionReward)
@@ -543,12 +556,16 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
543556
]
544557
const genericSchemeSetParams = genericScheme.methods.setParameters(...parameters)
545558
genericSchemeParams = await genericSchemeSetParams.call()
546-
tx = await genericSchemeSetParams.send({ nonce: ++nonce })
547-
await logTx(tx,
548-
'Generic Scheme parameters set. | Params Hash: ' +
549-
genericSchemeParams + '\nParameters:\n' +
550-
parameters.toString().replace(/,/g, ',\n')
551-
)
559+
560+
const genericSchemeCheckParams = await genericScheme.methods.parameters(genericSchemeParams).call()
561+
if (genericSchemeCheckParams.intVote === '0x0000000000000000000000000000000000000000') {
562+
tx = await genericSchemeSetParams.send({ nonce: ++nonce })
563+
await logTx(tx,
564+
'Generic Scheme parameters set. | Params Hash: ' +
565+
genericSchemeParams + '\nParameters:\n' +
566+
parameters.toString().replace(/,/g, ',\n')
567+
)
568+
}
552569

553570
deploymentState.schemeNames.push('Generic Scheme')
554571
deploymentState.schemes.push(Number(arcVersion.slice(-2)) >= 24 ? UGenericScheme : GenericScheme)
@@ -579,12 +596,16 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
579596
]
580597
const globalConstraintRegistrarSetParams = globalConstraintRegistrar.methods.setParameters(...parameters)
581598
globalConstraintRegistrarParams = await globalConstraintRegistrarSetParams.call()
582-
tx = await globalConstraintRegistrarSetParams.send({ nonce: ++nonce })
583-
await logTx(tx,
584-
'Global Constraints Registrar parameters set. | Params Hash: ' +
585-
globalConstraintRegistrarParams + '\nParameters:\n' +
586-
parameters.toString().replace(/,/g, ',\n')
587-
)
599+
600+
const globalConstraintRegistrarCheckParams = await globalConstraintRegistrar.methods.parameters(globalConstraintRegistrarParams).call()
601+
if (globalConstraintRegistrarCheckParams.intVote === '0x0000000000000000000000000000000000000000') {
602+
tx = await globalConstraintRegistrarSetParams.send({ nonce: ++nonce })
603+
await logTx(tx,
604+
'Global Constraints Registrar parameters set. | Params Hash: ' +
605+
globalConstraintRegistrarParams + '\nParameters:\n' +
606+
parameters.toString().replace(/,/g, ',\n')
607+
)
608+
}
588609

589610
deploymentState.schemeNames.push('Global Constraints Registrar')
590611
deploymentState.schemes.push(GlobalConstraintRegistrar)
@@ -615,12 +636,16 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
615636
]
616637
const upgradeSchemeSetParams = upgradeScheme.methods.setParameters(...parameters)
617638
upgradeSchemeParams = await upgradeSchemeSetParams.call()
618-
tx = await upgradeSchemeSetParams.send({ nonce: ++nonce })
619-
await logTx(tx,
620-
'Upgrade Scheme parameters set. | Params Hash: ' +
621-
upgradeSchemeParams + '\nParameters:\n' +
622-
parameters.toString().replace(/,/g, ',\n')
623-
)
639+
640+
const upgradeSchemeCheckParams = await upgradeScheme.methods.parameters(upgradeSchemeParams).call()
641+
if (upgradeSchemeCheckParams.intVote === '0x0000000000000000000000000000000000000000') {
642+
tx = await upgradeSchemeSetParams.send({ nonce: ++nonce })
643+
await logTx(tx,
644+
'Upgrade Scheme parameters set. | Params Hash: ' +
645+
upgradeSchemeParams + '\nParameters:\n' +
646+
parameters.toString().replace(/,/g, ',\n')
647+
)
648+
}
624649

625650
deploymentState.schemeNames.push('Upgrade Scheme')
626651
deploymentState.schemes.push(UpgradeScheme)

0 commit comments

Comments
 (0)