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

Check if resolver needs imports and if bridge needs sync separately #944

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 50 additions & 23 deletions publish/src/commands/connect-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const connectLayer = async ({
dryRun,
}) => {
// ---------------------------------
// Compare with on-chain values
// Check if the AddressResolver has all the correct addresses
// ---------------------------------

const filteredNames = [];
Expand All @@ -127,39 +127,66 @@ const connectLayer = async ({
}
}

const needToImportAddresses = filteredNames.length > 0;

// ---------------------------------
// Update on-chain values
// Update AddressResolver if needed
// ---------------------------------

let tx;

if (filteredNames.length === 0) {
console.log(gray(' > Bridge is already connected on this layer. Skipping...'));
return;
}

console.log(yellow(' > Setting these values:'));
console.log(yellow(` > ${names[0]} => ${addresses[0]}`));
console.log(yellow(` > ${names[1]} => ${addresses[1]}`));

const params = {
from: account,
gasPrice: Web3.utils.toWei(gasPrice.toString(), 'gwei'),
gas: gasLimit,
};

if (!dryRun) {
console.log(yellow(' > AddressResolver.importAddresses()...'));
tx = await AddressResolver.methods
.importAddresses(names.map(toBytes32), addresses)
.send(params);
console.log(JSON.stringify(tx, null, 2));
let tx;

console.log(yellow(' > SynthetixBridge.rebuildCache()...'));
tx = await SynthetixBridge.methods.rebuildCache().send(params);
console.log(JSON.stringify(tx, null, 2));
if (needToImportAddresses) {
console.log(yellow(' > Setting these values:'));
console.log(yellow(` > ${names[0]} => ${addresses[0]}`));
console.log(yellow(` > ${names[1]} => ${addresses[1]}`));

if (!dryRun) {
console.log(yellow(' > AddressResolver.importAddresses()...'));
tx = await AddressResolver.methods
.importAddresses(names.map(toBytes32), addresses)
.send(params);
console.log(JSON.stringify(tx, null, 2));
} else {
console.log(yellow(' > Skipping, since this is a DRY RUN'));
}
} else {
console.log(
gray(' > Bridge is already does not need to import any addresses in this layer. Skipping...')
);
}

// ---------------------------------
// Sync cache on bridge if needed
// ---------------------------------

let needToSyncCacheOnBridge = needToImportAddresses;
if (!needToSyncCacheOnBridge) {
const isResolverCached = await SynthetixBridge.methods
.isResolverCached(AddressResolver.options.address)
Copy link
Contributor

Choose a reason for hiding this comment

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

This has changed now due to SIP-100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

.call();
if (!isResolverCached) {
needToSyncCacheOnBridge = true;
}
}

if (needToSyncCacheOnBridge) {
console.log(yellow(' > Rebuilding cache on bridge...'));

if (!dryRun) {
console.log(yellow(' > SynthetixBridge.rebuildCache()...'));
tx = await SynthetixBridge.methods.rebuildCache().send(params);
console.log(JSON.stringify(tx, null, 2));
} else {
console.log(yellow(' > Skipping, since this is a DRY RUN'));
}
} else {
console.log(yellow(' > Skipping, since this is a DRY RUN'));
console.log(gray(' > Bridge cache is synced in this layer. Skipping...'));
}
};

Expand Down