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

Removes forks activation and checks related code #82

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,3 @@ The command `run-single-test-file` will execute the file `singleTestFileRunner.j
1 - It will assign the `01_02_51-post_wasabi_fed_pubkeys_fork.js` test file name to the `process.env.INCLUDE_CASES` variable. Since it will be the one in that `INCLUDE_CASES` variable, then only that test file will be run.

2 - It will setup a boolean `process.env.RUNNING_SINGLE_TEST_FILE` variable to `true` so the `fulfillRequirementsToRunAsSingleTestFile` function can check if it needs to manually take the blockchain to a state where the test file can run or not.

The test file should have a `fulfillRequirementsToRunAsSingleTestFile` function to be called in the `before` function because each test file has different requirements to be able to run. Some will need to mine blocks, fund the bridge, activate 1 or more forks, etc. Some will be able to run without any prior preparation.

Another advantage of this is that it will allow us to understand exactly what each test really needs in order to run, reducing uncertainties.

To indicate a fork name to be used in the `fulfillRequirementsToRunAsSingleTestFile` function, you can specify it as the last argument of the command like this, passing the fork name `fingerroot500`:

> npm run run-single-test-file 02_00_01-2wp.js fingerroot500
This is when the `fulfillRequirementsToRunAsSingleTestFile` function needs a fork name that needs to be dynamically passed. For example, the `2wp.js` file is run multiple times with different forks. We cannot simply hardcode which fork to use or to use the latest, because sometimes we will need to run it with a fork passed dynamically.
6 changes: 3 additions & 3 deletions lib/2wp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
} = require('./rsk-utils');
const { retryWithCheck } = require('./utils');
const { waitForBitcoinTxToBeInMempool, waitForBitcoinMempoolToGetTxs } = require('./btc-utils');
const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util');
const { getBridge } = require('./precompiled-abi-forks-util');
const { getBridgeState } = require('@rsksmart/bridge-state-data-parser');
const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter');

Expand All @@ -33,7 +33,7 @@ const logger = getLogger();
* @param {string} refundAddress
*/
const assertRefundUtxosSameAsPeginUtxos = async(rskTxHelper, btcTxHelper, peginTxHash, refundAddress) => {
const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName());
const bridge = getBridge(rskTxHelper.getClient());
const federationAddress = await bridge.methods.getFederationAddress().call();
const peginTx = await btcTxHelper.getTransaction(peginTxHash);
const outputsForFederation = peginTx.outs.filter(output => btcTxHelper.getOutputAddress(output.script) === federationAddress);
Expand Down Expand Up @@ -138,7 +138,7 @@ const sendPegin = async (rskTxHelper, btcTxHelper, btcSenderAddressInformation,
outputAmountsInBtc = Array.of(outputAmountsInBtc);
}

const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName());
const bridge = getBridge(rskTxHelper.getClient());
const federationAddress = await bridge.methods.getFederationAddress().call();

const recipientsTransferInformation = outputAmountsInBtc.map(amount => ({ recipientAddress: federationAddress, amountInBtc: amount }));
Expand Down
4 changes: 2 additions & 2 deletions lib/assertions/fed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var { wait } = require('../utils');
var bitcoin = require('peglib').bitcoin;
var rsk = require('peglib').rsk;
const rskUtilsLegacy = require('../rsk-utils-legacy');
const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util');
const { getBridge } = require('../precompiled-abi-forks-util');
const rskUtils = require('../rsk-utils');
const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider');

Expand Down Expand Up @@ -57,7 +57,7 @@ var checkUpdateBridge = async (rskClients, federateAddresses, fedIndex) => {

var client = rskClients[fedIndex];
var address = federateAddresses[fedIndex].toLowerCase();
const bridge = getBridge(client, await getLatestActiveForkName());
const bridge = getBridge(client);

var updateCollectionsData = bridge.methods.updateCollections().encodeABI();

Expand Down
7 changes: 1 addition & 6 deletions lib/assertions/whitelisting-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ const getUnlockedAddress = async (rskClient, privateKey, address) => {
};

const assertAddLimitedLockWhitelistAddress = (btcClient, rskClient) => (address, maxTransferValue) => async () => {
const isOrchidAlreadyActive = await Runners.common.forks.orchid.isAlreadyActive();
if (isOrchidAlreadyActive) {
return assertAddOneOffWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)();
} else {
return assertAddLockWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)();
}
return assertAddOneOffWhitelistAddress(btcClient, rskClient)(address, maxTransferValue)();
};

const assertAddOneOffWhitelistAddress = (btcClient, rskClient) => (address, maxTransferValue) => async () => {
Expand Down
9 changes: 2 additions & 7 deletions lib/assertions/whitelisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ const WHITELIST_CHANGE_PK = '3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc056
const WHITELIST_CHANGE_ADDR = '87d2a0f33744929da08b65fd62b627ea52b25f8e';

/**
* If orchid is already active, then this method will call assertAddOneOffWhitelistAddress. Otherwise, it will call assertAddLockWhitelistAddress.
*
* @param {RskTransactionHelper} rskTxHelper
* @param {string} btcAddress to be added to the bridge whitelist.
* @param {number} maxTransferValueInSatoshis max transfer value in satoshis that the `btcAddress` is allowed to transfer in a pegin transaction.
* @returns {Promise<void>}
*/
const assertAddLimitedLockWhitelistAddress = async (rskTxHelper, btcAddress, maxTransferValueInSatoshis) => {
const isOrchidAlreadyActive = await Runners.common.forks.orchid.isAlreadyActive();
if (isOrchidAlreadyActive) {
return await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis);
} else {
return await assertAddLockWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis);
}
return await assertAddOneOffWhitelistAddress(rskTxHelper, btcAddress, maxTransferValueInSatoshis);
};

/**
Expand Down
10 changes: 1 addition & 9 deletions lib/federate-starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,10 @@ const startFederate = async (index, config, stderr, stdout, runners, logbackFile
var fedStderr = new LineWrapper({ prefix: federateOutputPrefix });
fedStderr.pipe(stderr);

let parseActivations = (forks) => {
activations = { activationHeights: {} };
for (fork in forks) {
activations.activationHeights[fork] = forks[fork].activationHeight;
}
return activations;
};

var federateConfig = Object.assign({}, config, {
stderr: fedStderr,
logbackFile: config.logbackFile ? config.logbackFile : logbackFile,
forks: parseActivations(Runners.common.forks)
forks: { activationHeights: { ...Runners.common.forks } }
});

federateConfig.customConfig['miner.client.enabled'] = false;
Expand Down
6 changes: 5 additions & 1 deletion lib/hsm-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ const spawnProcessVersion2NoDocker = (

let parseNetworkUpgrades = (forks) => {
let upgrades = {};
Object.values(forks).map(f => upgrades[f.name] = f.activationHeight);
Object.entries(forks).forEach(entry => {
const forkName = entry[0];
const forkHeight = entry[1];
upgrades[forkName] = forkHeight;
});
let networkUpgrades = {network_upgrades:upgrades}
return JSON.stringify(networkUpgrades);
};
Expand Down
137 changes: 11 additions & 126 deletions lib/precompiled-abi-forks-util.js
Original file line number Diff line number Diff line change
@@ -1,147 +1,32 @@

const orchidPrecompiled = require("precompiled-orchid");
const wasabi100Precompiled = require("precompiled-wasabi100");
const papyrus200Precompiled = require("precompiled-papyrus200");
const iris300Precompiled = require("precompiled-iris300");
const hop400Precompiled = require("precompiled-hop400");
const precompiledFingerroot500 = require("precompiled-fingerroot500");
const precompiledArrowhead600 = require("precompiled-arrowhead600");
const precompiledLovell700 = require("precompiled-lovell700");

const ORCHID = 'orchid';
const WASABI = 'wasabi';
const PAPYRUS = 'papyrus';
const IRIS = 'iris';
const HOP = 'hop';
const HOP401 = 'hop401';
const FINGERROOT = 'fingerroot';
const ARROWHEAD = 'arrowhead';
const LOVELL = 'lovell';

// Map to access the pre fork names of certain fork in constant time O(1)
const preForkMap = {
[ORCHID]: ORCHID, // orchid pre is itself
[WASABI]: ORCHID,
[PAPYRUS]: WASABI,
[IRIS]: PAPYRUS,
[HOP]: IRIS,
[HOP401]: HOP,
[FINGERROOT]: HOP401,
[ARROWHEAD]: FINGERROOT,
[LOVELL]: ARROWHEAD
}

const cache = new Map();
let bridgeCache;

/**
* Creates a bridge instance for the given fork name. If no fork name is provided, then the latest bridge is returned.
* The bridge instance is cached using the forkname for future use.
* Returns a bridge instance and caches it.
* @param {Web3} rskClient
* @param {string} forkName
* @returns {Bridge}
*/
const getBridge = (rskClient, forkName = '') => {
const getBridge = (rskClient) => {

const { orchid, wasabi100, papyrus200, iris300, hop400, hop401, fingerroot500, arrowhead600, lovell700 } = Runners.common.forks;
if(cache.has(forkName)) {
return cache.get(forkName);
if(bridgeCache) {
return bridgeCache;
}

let bridge;
switch(forkName) {
case lovell700.name:
bridge = precompiledLovell700.bridge.build(rskClient);
break;
case arrowhead600.name:
bridge = precompiledArrowhead600.bridge.build(rskClient);
break;
case fingerroot500.name:
bridge = precompiledFingerroot500.bridge.build(rskClient);
break;
case hop400.name:
case hop401.name:
bridge = hop400Precompiled.bridge.build(rskClient);
break;
case iris300.name:
bridge = iris300Precompiled.bridge.build(rskClient);
break;
case papyrus200.name:
bridge = papyrus200Precompiled.bridge.build(rskClient);
break;
case wasabi100.name:
bridge = wasabi100Precompiled.bridge.build(rskClient);
break;
case orchid.name:
bridge = orchidPrecompiled.bridge.build(rskClient);
break;
default:
// return latest bridge
bridge = precompiledLovell700.bridge.build(rskClient);
}
cache.set(forkName, bridge);
return bridge;
}
bridgeCache = precompiledArrowhead600.bridge.build(rskClient);

/**
* Returns the abi of the bridge for the given fork name. If no fork name is provided, then the latest bridge abi is returned.
* @param {string} forkName
* @returns {json} The bridge abi in json format
*/
const getBridgeAbi = (forkName) => {

const { orchid, wasabi100, papyrus200, iris300, hop400, hop401, fingerroot500, arrowhead600, lovell700 } = Runners.common.forks;
switch(forkName) {
case lovell700.name:
return precompiledLovell700.bridge.abi;
case arrowhead600.name:
return precompiledArrowhead600.bridge.abi;
case fingerroot500.name:
return precompiledFingerroot500.bridge.abi;
case hop400.name:
case hop401.name:
return hop400Precompiled.bridge.abi;
case iris300.name:
return iris300Precompiled.bridge.abi;
case papyrus200.name:
return papyrus200Precompiled.bridge.abi;
case wasabi100.name:
return wasabi100Precompiled.bridge.abi;
case orchid.name:
return orchidPrecompiled.bridge.abi;
default:
// return latest abi
return precompiledArrowhead600.bridge.abi;
}
};

/**
* Returns the name of the fork right before the given `currentForkName`
* @param {string} currentForkName
* @returns {string} The name of the fork right before the given `currentForkName`
*/
const getPreForkName = (currentForkName) => {
return preForkMap[currentForkName];
return bridgeCache;
}

/**
* Returns the most recent activated fork name
* @returns {Promise<string>} the most recent activated fork name
* Returns the abi of the bridge for the latest fork.
* @returns {json} The bridge abi in json format
*/
const getLatestActiveForkName = async () => {
const forks = Object.values(Runners.common.forks);
for(let i = forks.length - 1; i > -1; i--) {
const fork = forks[i];
const isForkAlreadyActive = await fork.isAlreadyActive();
if(isForkAlreadyActive) {
return fork.name;
}
}
return Runners.common.forks.orchid.name;
const getBridgeAbi = () => {
return precompiledArrowhead600;
};

module.exports = {
getBridge,
getBridgeAbi,
getLatestActiveForkName,
getPreForkName,
};
13 changes: 5 additions & 8 deletions lib/rsk-utils-legacy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const expect = require('chai').expect;
const btcClientProvider = require('./btc-client-provider');
const { sequentialPromise, wait, interval } = require('./utils');
const { getBridgeAbi, getLatestActiveForkName } = require('./precompiled-abi-forks-util');
const { getBridgeAbi } = require('./precompiled-abi-forks-util');
const waitForBlockAttemptTimeMillis = process.env.WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS || 200;
const waitForBlockMaxAttempts = process.env. WAIT_FOR_BLOCK_MAX_ATTEMPTS || 600;

Expand Down Expand Up @@ -102,10 +102,7 @@ let triggerRelease2 = async(rskClients, releaseCreatedCallback, releaseConfirmed
};

let triggerPegoutEvent = async(rskClients, releaseCreatedCallback, releaseConfirmedCallback) => {
const isHop400AlreadyActive = await Runners.common.forks.hop400.isAlreadyActive();
if (isHop400AlreadyActive) {
await increaseBlockToNextPegoutHeight(rskClients[0]);
}
await increaseBlockToNextPegoutHeight(rskClients[0]);
await triggerRelease2(rskClients, releaseCreatedCallback, releaseConfirmedCallback);
};

Expand Down Expand Up @@ -206,12 +203,12 @@ const waitForBtcToReturn = (btcClient, rskClient) => async (btcAddress) => {
};

const getBridgeEventInBlockAndRunAssertions = async(block, eventName, eventAssertions, rsk, rskClient) => {
const latestActiveForkName = await getLatestActiveForkName();
const abi = getBridgeAbi(latestActiveForkName);

const abi = getBridgeAbi();

let txs = block.transactions;
let eventJson = abi.find((methods) => methods.name == eventName && methods.type == 'event');
expect(eventJson, `Event with name "${eventName}" was not found in the "${latestActiveForkName}" abi`).to.not.be.undefined;
expect(eventJson, `Event with name "${eventName}" was not found in the abi`).to.not.be.undefined;
let signature = rskClient.eth.abi.encodeEventSignature(eventJson);
for (tx of txs) {
let txReceipt = await rskClient.eth.getTransactionReceipt(tx);
Expand Down
Loading