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

Add testnet account json #769

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Add testnet account json #769

merged 5 commits into from
Apr 23, 2024

Conversation

JesseAbram
Copy link
Member

This allows for a json file to be given endowed accounts, this way accomplices can add them to our network

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

I left a couple of questions.

This will be nice so that people don't need to add accounts straight to the Rust code if they want to get some tokens.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not litter the top level of the repo with this.

I'm tempted to say that we should put it in chains, but that might be misleading. Maybe it can live in a res directory in node/cli/src/chain_spec/?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not litter the top level of the repo with this.

I'm tempted to say that we should put it in chains, but that might be misleading. Maybe it can live in a res directory in node/cli/src/chain_spec/?

Another option would be to not have this file - and if we fail to open this file, we make the list of accounts to add be an empty vector. So we only need this file if there is something to put in it.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason why you went with JSON here instead instead of just a flat text file?

Copy link
Member Author

Choose a reason for hiding this comment

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

ya I like json better, you can format it and it is usually colour coated and can enforce format better

"{}/testnet-accounts.json",
get_project_root().expect("Error getting project root").to_string_lossy()
))
.expect("file should open read only");
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the docs do say this, I'd make this error a bit more descriptive.

node/cli/src/endowed_accounts.rs Outdated Show resolved Hide resolved

for address in accounts {
inital_accounts
.push(AccountId::from_string(&address).expect("failed to convert a testnet_address"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be useful to print out what address we failed to parse as part of the error message

// handle user submitted file for tokens
let mut file = File::open(format!(
"{}/testnet-accounts.json",
get_project_root().expect("Error getting project root").to_string_lossy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure we want to_string_lossy() here? From what I understand it would mean that we accept paths with

Copy link
Contributor

@ameba23 ameba23 Apr 19, 2024

Choose a reason for hiding this comment

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

That would only happen if get_project_root found a path which contained invalid utf8 which is very unlikely so i think this is fine.

Strictly speaking though its probably better to not convert to a string - as File::open can take a PathBuf:

let mut file = File::open(get_project_root().expect("Error getting project root").join("testnet-accounts.json"))

Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Although just to be clear, the use-case for this is the local docker-compose setup, right? If i remember rightly our deployed devnet doesn't use the pre-endowed accounts.

If so i guess the use case would be for trying things out with a lot of users, eg: benchmarking. For that this would be really useful. But its not so clear to me why this is useful for accomplices - why wouldn't they just use the existing endowed accounts?

// handle user submitted file for tokens
let mut file = File::open(format!(
"{}/testnet-accounts.json",
get_project_root().expect("Error getting project root").to_string_lossy()
Copy link
Contributor

@ameba23 ameba23 Apr 19, 2024

Choose a reason for hiding this comment

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

That would only happen if get_project_root found a path which contained invalid utf8 which is very unlikely so i think this is fine.

Strictly speaking though its probably better to not convert to a string - as File::open can take a PathBuf:

let mut file = File::open(get_project_root().expect("Error getting project root").join("testnet-accounts.json"))

@HCastano
Copy link
Collaborator

Looks good to me. Although just to be clear, the use-case for this is the local docker-compose setup, right? If i remember rightly our deployed devnet doesn't use the pre-endowed accounts.

If so i guess the use case would be for trying things out with a lot of users, eg: benchmarking. For that this would be really useful. But its not so clear to me why this is useful for accomplices - why wouldn't they just use the existing endowed accounts?

So the use case that I understand here is that we would like accomplices to have endowed accounts which are persisted between testnet resets. In order to do that in such a way that doesn't require anybody to make a PR into the Rust code we can just keep a list of accomplice accounts instead.

For other use cases, e.g benchmarking I would prefer to use a more Rust based approach.

@ameba23
Copy link
Contributor

ameba23 commented Apr 19, 2024

So the use case that I understand here is that we would like accomplices to have endowed accounts which are persisted between testnet resets. In order to do that in such a way that doesn't require anybody to make a PR into the Rust code we can just keep a list of accomplice accounts instead.

Ah ok makes sense - so testnet does use the endowed accounts. Yeah i can see that would be useful.

JesseAbram and others added 2 commits April 23, 2024 07:41
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
@JesseAbram JesseAbram merged commit 94e901b into master Apr 23, 2024
11 checks passed
@JesseAbram JesseAbram deleted the testnet-account-json branch April 23, 2024 15:43
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