Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truffle migrations verbosity and fixed invalid JSON rpc #416

Merged
merged 14 commits into from
Nov 4, 2019
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();
Copy link
Contributor

@boolafish boolafish Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so you can deploy same contract multiple times by deployer.deply() just when you try to get it back by deployed() you will get the latest one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap you can, you save the instance in memory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also <>.new() deploys the contracts silently whereas deployer.deploy(<>) does it verbosely for some reason.....


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
28 changes: 12 additions & 16 deletions plasma_framework/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ require('dotenv').config(); // auto parse env variables from '.env' file

const HDWalletProvider = require('@truffle/hdwallet-provider');

const infuraUrl = `${process.env.INFURA_URL || 'http://127.0.0.1'}/${process.env.INFURA_API_KEY || ''}`;
const cleanInfuraUrl = infuraUrl.replace(/([^:])(\/\/+)/g, '$1/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep the previous comment of Replace double // or is it obvious? (not to me but might just be me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes actually keep the comment, it's definitely not obvious

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder: the comment is not added yet


module.exports = {
networks: {
local: {
Expand Down Expand Up @@ -31,22 +34,15 @@ module.exports = {
},
infura: {
skipDryRun: true,
provider: () => {
const infuraUrl = `${process.env.INFURA_URL}/${process.env.INFURA_API_KEY}`;

// Replace double '//'
const cleanInfuraUrl = infuraUrl.replace(/([^:])(\/\/+)/g, '$1/');

return new HDWalletProvider(
[
process.env.DEPLOYER_PRIVATEKEY,
process.env.MAINTAINER_PRIVATEKEY,
process.env.AUTHORITY_PRIVATEKEY,
],
cleanInfuraUrl,
0, 3,
);
},
provider: new HDWalletProvider(
[
process.env.DEPLOYER_PRIVATEKEY,
process.env.MAINTAINER_PRIVATEKEY,
process.env.AUTHORITY_PRIVATEKEY,
],
cleanInfuraUrl,
0, 3,
),
network_id: '*',
},
},
Expand Down
Loading