Skip to content

Commit

Permalink
Merge pull request #416 from omisego/200-migrations-fixes
Browse files Browse the repository at this point in the history
Truffle migrations verbosity and fixed invalid JSON rpc
  • Loading branch information
kendricktan authored Nov 4, 2019
2 parents bc3e9e4 + 8d6c529 commit 1608296
Show file tree
Hide file tree
Showing 6 changed files with 8,357 additions and 31 deletions.
27 changes: 24 additions & 3 deletions plasma_framework/migrations/1_initial_checks_and_migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ const Migrations = artifacts.require('Migrations');

const fundAddressIfEmpty = async (from, to, value, receiverName) => {
const balanceWeiCount = await Migrations.web3.eth.getBalance(to);
const balanceEthCount = Migrations.web3.utils.fromWei(balanceWeiCount.toString());
const fundEthCount = Migrations.web3.utils.fromWei(value.toString());

if (parseInt(balanceWeiCount, 10) === 0) {
console.log(`Funding ${receiverName} address...`);
console.log(`Funding ${receiverName} address with ${fundEthCount} ETH...`);
await Migrations.web3.eth.sendTransaction({
from,
to,
value,
});
console.log(`Successfully funded ${receiverName} address.`);
} else {
console.log(`${receiverName} already has ${balanceEthCount} ETH, skipping funding.`);
}
};

const outputAddressFunds = async (addr, addrName) => {
const balanceWeiCount = await Migrations.web3.eth.getBalance(addr);
const balanceEthCount = Migrations.web3.utils.fromWei(balanceWeiCount.toString());
console.log(`${addrName} contains ${balanceEthCount} ETH`);
};

module.exports = async (
deployer,
_,
Expand All @@ -27,11 +37,22 @@ module.exports = async (
console.log(`Maintainer address: ${maintainerAddress}`);
console.log(`Authority address: ${authorityAddress}`);

const initAmountForMaintainer = process.env.MAINTAINER_ADDRESS_INITIAL_AMOUNT || 1e18; // 1 ETH by default
const initAmountForAuthority = process.env.AUTHORITY_ADDRESS_INITIAL_AMOUNT || 1e18; // 1 ETH by default
const initAmountForMaintainer = process.env.MAINTAINER_ADDRESS_INITIAL_AMOUNT || 2e17; // 0.2 ETH by default
const initAmountForAuthority = process.env.AUTHORITY_ADDRESS_INITIAL_AMOUNT || 2e17; // 0.2 ETH by default

await fundAddressIfEmpty(deployerAddress, maintainerAddress, initAmountForMaintainer, 'maintainer');
await fundAddressIfEmpty(deployerAddress, authorityAddress, initAmountForAuthority, 'authority');

await outputAddressFunds(deployerAddress, 'Deployer');
await outputAddressFunds(maintainerAddress, 'Maintainer');
await outputAddressFunds(authorityAddress, 'Authority');

console.log('\n########################### Notice ############################');
console.log('It is recommended to have 0.2 ETH in the maintainer and authority address');
console.log('With 1.0 ETH in the deployer address');
console.log('Otherwise the deployement might fail');
console.log('###############################################################\n');

// Deploy migrations
await deployer.deploy(Migrations);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ module.exports = async (
[deployerAddress, maintainerAddress, authorityAddress],
) => {
const plasmaFramework = await PlasmaFramework.deployed();
const ethDepositVerifier = await EthDepositVerifier.new();
const ethVault = await EthVault.new(plasmaFramework.address, { from: maintainerAddress });

await deployer.deploy(EthDepositVerifier);
const ethDepositVerifier = await EthDepositVerifier.deployed();

await deployer.deploy(EthVault, plasmaFramework.address, { from: maintainerAddress });
const ethVault = await EthVault.deployed();
await ethVault.setDepositVerifier(ethDepositVerifier.address, { from: maintainerAddress });

await plasmaFramework.registerVault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ module.exports = async (
) => {
const plasmaFramework = await PlasmaFramework.deployed();

const erc20DepositVerifier = await Erc20DepositVerifier.new();
const erc20Vault = await Erc20Vault.new(plasmaFramework.address, { from: maintainerAddress });
await deployer.deploy(Erc20DepositVerifier);
const erc20DepositVerifier = await Erc20DepositVerifier.deployed();

await deployer.deploy(Erc20Vault, plasmaFramework.address, { from: maintainerAddress });
const erc20Vault = await Erc20Vault.deployed();

await erc20Vault.setDepositVerifier(erc20DepositVerifier.address, { from: maintainerAddress });

await plasmaFramework.registerVault(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

const OutputGuardHandlerRegistry = artifacts.require('OutputGuardHandlerRegistry');
const PaymentExitGame = artifacts.require('PaymentExitGame');
const PaymentChallengeStandardExit = artifacts.require('PaymentChallengeStandardExit');
Expand Down Expand Up @@ -29,15 +31,34 @@ module.exports = async (
const PAYMENT_V2_TX_TYPE = config.registerKeys.txTypes.paymentV2;

// deploy and link exit game controllers
const startStandardExit = await PaymentStartStandardExit.new();
const challengeStandardExit = await PaymentChallengeStandardExit.new();
const processStandardExit = await PaymentProcessStandardExit.new();
const startInFlightExit = await PaymentStartInFlightExit.new();
const piggybackInFlightExit = await PaymentPiggybackInFlightExit.new();
const challengeInFlightExitNotCanonical = await PaymentChallengeIFENotCanonical.new();
const challengeIFEInputSpent = await PaymentChallengeIFEInputSpent.new();
const challengeIFEOutput = await PaymentChallengeIFEOutputSpent.new();
const processInFlightExit = await PaymentProcessInFlightExit.new();

await deployer.deploy(PaymentStartStandardExit);
const startStandardExit = await PaymentStartStandardExit.deployed();

await deployer.deploy(PaymentChallengeStandardExit);
const challengeStandardExit = await PaymentChallengeStandardExit.deployed();

await deployer.deploy(PaymentProcessStandardExit);
const processStandardExit = await PaymentProcessStandardExit.deployed();

await deployer.deploy(PaymentStartInFlightExit);
const startInFlightExit = await PaymentStartInFlightExit.deployed();

await deployer.deploy(PaymentPiggybackInFlightExit);
const piggybackInFlightExit = await PaymentPiggybackInFlightExit.deployed();

await deployer.deploy(PaymentChallengeIFENotCanonical);
const challengeInFlightExitNotCanonical = await PaymentChallengeIFENotCanonical.deployed();

await deployer.deploy(PaymentChallengeIFEInputSpent);
const challengeIFEInputSpent = await PaymentChallengeIFEInputSpent.deployed();

await deployer.deploy(PaymentChallengeIFEOutputSpent);
const challengeIFEOutput = await PaymentChallengeIFEOutputSpent.deployed();

await deployer.deploy(PaymentProcessInFlightExit);
const processInFlightExit = await PaymentProcessInFlightExit.deployed();

await PaymentExitGame.link('PaymentStartStandardExit', startStandardExit.address);
await PaymentExitGame.link('PaymentChallengeStandardExit', challengeStandardExit.address);
await PaymentExitGame.link('PaymentProcessStandardExit', processStandardExit.address);
Expand All @@ -49,12 +70,23 @@ module.exports = async (
await PaymentExitGame.link('PaymentProcessInFlightExit', processInFlightExit.address);

// deploy exit game
const outputGuardHandlerRegistry = await OutputGuardHandlerRegistry.new();
const spendingConditionRegistry = await SpendingConditionRegistry.new();
const stateVerifier = await PaymentTransactionStateTransitionVerifier.new();
const txFinalizationVerifier = await TxFinalizationVerifier.new();

await deployer.deploy(OutputGuardHandlerRegistry);
const outputGuardHandlerRegistry = await OutputGuardHandlerRegistry.deployed();

await deployer.deploy(SpendingConditionRegistry);
const spendingConditionRegistry = await SpendingConditionRegistry.deployed();

await deployer.deploy(PaymentTransactionStateTransitionVerifier);
const stateVerifier = await PaymentTransactionStateTransitionVerifier.deployed();

await deployer.deploy(TxFinalizationVerifier);
const txFinalizationVerifier = await TxFinalizationVerifier.deployed();

const plasmaFramework = await PlasmaFramework.deployed();
const paymentExitGame = await PaymentExitGame.new(

const paymentExitGame = await deployer.deploy(
PaymentExitGame,
plasmaFramework.address,
config.registerKeys.vaultId.eth,
config.registerKeys.vaultId.erc20,
Expand All @@ -66,22 +98,36 @@ module.exports = async (
);

// handle output guard handler
const paymentOutputGuardHandler = await PaymentOutputGuardHandler.new(PAYMENT_OUTPUT_TYPE);
await deployer.deploy(PaymentOutputGuardHandler, PAYMENT_OUTPUT_TYPE);
const paymentOutputGuardHandler = await PaymentOutputGuardHandler.deployed();
await outputGuardHandlerRegistry.registerOutputGuardHandler(
PAYMENT_OUTPUT_TYPE, paymentOutputGuardHandler.address,
);
await outputGuardHandlerRegistry.renounceOwnership();

// handle spending condition
const paymentToPaymentCondition = await PaymentOutputToPaymentTxCondition.new(
plasmaFramework.address, PAYMENT_OUTPUT_TYPE, PAYMENT_TX_TYPE,
await deployer.deploy(
PaymentOutputToPaymentTxCondition,
plasmaFramework.address,
PAYMENT_OUTPUT_TYPE,
PAYMENT_TX_TYPE,
);
const paymentToPaymentV2Condition = await PaymentOutputToPaymentTxCondition.new(
plasmaFramework.address, PAYMENT_OUTPUT_TYPE, PAYMENT_V2_TX_TYPE,
const paymentToPaymentCondition = await PaymentOutputToPaymentTxCondition.deployed();

await deployer.deploy(
PaymentOutputToPaymentTxCondition,
plasmaFramework.address,
PAYMENT_OUTPUT_TYPE,
PAYMENT_V2_TX_TYPE,
);
const paymentToPaymentV2Condition = await PaymentOutputToPaymentTxCondition.deployed();

console.log(`Registering paymentToPaymentCondition (${paymentToPaymentCondition.address}) to spendingConditionRegistry`);
await spendingConditionRegistry.registerSpendingCondition(
PAYMENT_OUTPUT_TYPE, PAYMENT_TX_TYPE, paymentToPaymentCondition.address,
);

console.log(`Registering paymentToPaymentV2Condition (${paymentToPaymentV2Condition.address}) to spendingConditionRegistry`);
await spendingConditionRegistry.registerSpendingCondition(
PAYMENT_OUTPUT_TYPE, PAYMENT_V2_TX_TYPE, paymentToPaymentV2Condition.address,
);
Expand Down
14 changes: 9 additions & 5 deletions plasma_framework/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ module.exports = {
// before getting submitted to the remote client.
remote: {
skipDryRun: true,
provider: () => new HDWalletProvider(
// Can't be a function otherwise it'll throw a JSON RPC error for some reason
// https://github.com/trufflesuite/truffle/issues/852#issuecomment-522367001
// Using 0's as private key because it'll throw an error if the private keys
// are undefined as this is instanciating a class....
provider: new HDWalletProvider(
[
process.env.DEPLOYER_PRIVATEKEY,
process.env.MAINTAINER_PRIVATEKEY,
process.env.AUTHORITY_PRIVATEKEY,
process.env.DEPLOYER_PRIVATEKEY || '0'.repeat(64),
process.env.MAINTAINER_PRIVATEKEY || '0'.repeat(64),
process.env.AUTHORITY_PRIVATEKEY || '0'.repeat(64),
],
process.env.REMOTE_URL,
process.env.REMOTE_URL || 'http://127.0.0.1:8545',
0, 3,
),
network_id: '*',
Expand Down
Loading

0 comments on commit 1608296

Please sign in to comment.