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

feat: add flag to execute scripts in parallel w.r.t. chains #203

Merged
merged 9 commits into from
Apr 5, 2024

Conversation

blockchainguyy
Copy link
Contributor

@blockchainguyy blockchainguyy commented Apr 1, 2024

@blockchainguyy blockchainguyy marked this pull request as ready for review April 1, 2024 12:32
@blockchainguyy blockchainguyy requested a review from a team as a code owner April 1, 2024 12:32
@blockchainguyy blockchainguyy self-assigned this Apr 1, 2024
@blockchainguyy blockchainguyy marked this pull request as draft April 1, 2024 13:50
@blockchainguyy blockchainguyy marked this pull request as ready for review April 1, 2024 15:09
evm/utils.js Outdated Show resolved Hide resolved
@blockchainguyy blockchainguyy merged commit dc7607b into main Apr 5, 2024
4 checks passed
@blockchainguyy blockchainguyy deleted the feat/parallel-flag branch April 5, 2024 07:16
function saveConfig(config, env) {
writeJSON(config, `${__dirname}/../axelar-chains-config/info/${env}.json`);
}

function saveParallelExecutionConfig(config, env, chain) {
Copy link
Member

@milapsheth milapsheth Jun 4, 2024

Choose a reason for hiding this comment

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

Note that the implementation of this function is not tied to a notion of parallel execution, so the naming isn't quite right. Furthermore, it's pretty much the same as existing functions. So instead of a new helper, generalize loadConfig/saveConfig to take a filename/relative path. It can default to null meaning the current setting, but otherwise allows customizing the name. Using a different info directory is confusing as well since it's still saving the config.

@@ -852,6 +861,73 @@ const mainProcessor = async (options, processCommand, save = true, catchErr = fa
}
}

if (options.parallel && chains.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid making functions so complex. Use clear and concise helper functions to organize the code

let chainCommandIndex = -1;
let skipPrompt = false;

for (let commandIndex = 0; commandIndex < cmds.length; commandIndex++) {
Copy link
Member

@milapsheth milapsheth Jun 4, 2024

Choose a reason for hiding this comment

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

this is a weird way to run it parallely (like what you'd need to do in bash). Why not run processCommand without an await for each chain and wait at the end?

Copy link
Member

@milapsheth milapsheth Jun 4, 2024

Choose a reason for hiding this comment

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

I imagine it was to separate stdout capture between parallel runs. I'm wondering if we can capture the console.log separately or reassign .log field to something that stores the output in a list so we can output, or use a process library to do the above more cleanly. If there's no good way to do this in JS, then we can do the above but refactor it to make it cleaner


return;
}

Copy link
Member

@milapsheth milapsheth Jun 4, 2024

Choose a reason for hiding this comment

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

i don't see a need for separate code like above to handle parallel execution. Create a chainProcessor function that handles most of the for loop body. Depending on sequential/parallel mode, it can be run with an await or the promise can be collected (or if needed using an exec in the chainProcessor function), and we await at the end.

To deal with configs in parallel mode, you can give a copy of it to each call so they don't write to the same object. And then you can merge the chain specific changes at the end. No need to save configs separately.

Copy link
Member

Choose a reason for hiding this comment

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

An initial complex solution is usually not the right one, I recommend spending more time to come up with a more elegant approach and discuss it during syncs if needed, otherwise codebase can easily become unmaintainable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants