ChainSafe / gossamer

🕸️ Go Implementation of the Polkadot Host
https://chainsafe.github.io/gossamer
GNU Lesser General Public License v3.0
430 stars 112 forks source link

cli: generate account key if not specified #3255

Open kanishkatn opened 1 year ago

kanishkatn commented 1 year ago

Issue summary

If the account key is not specified in the cli flags, we need to generate one for the user.

danforbes commented 1 year ago

What is the current behavior?

kanishkatn commented 1 year ago

What is the current behavior?

For westend-dev and westend-local, it defaults to alice. For the rest,

In substrate, if we're using custom keys, the docs takes us through creating the keystore first before running the node.

1garo commented 11 months ago

wanted to contribute to this issue, is it okay?

kanishkatn commented 11 months ago

Of course @1garo ! I am off at the moment and can provide more context in a couple of days!

1garo commented 11 months ago

Of course @1garo ! I am off at the moment and can provide more context in a couple of days!

Sounds great, in the meantime I'm gonna take a look if I can have some progress.

kanishkatn commented 11 months ago

Hey @1garo, Here's where the account is being parsed: https://github.com/ChainSafe/gossamer/blob/development/cmd/gossamer/commands/utils.go#L322

With the current default config setup, we won't have a scenario where the account would be empty. We want to remove the default values for account and generate one it if it is empty.

Happy to answer any questions you have!

1garo commented 11 months ago

I was able to generate the default keypair, I added a "default" case to LoadKeystore, and used ed25519.GenerateKeypair() and sr25519.GenerateKeypair() to generate the pairs (ed25519 for grandpa).

It passes but later on broke at:

2023-11-16T13:56:37-03:00 CRITICAL failed to run block production engine: cannot handle epoch: cannot initiate and get epoch handler: failed to initiate epoch: cannot get epoch data and start slot: cannot get latest epoch data: cannot get authority index: key not in BABE authority data  pkg=babe
1garo commented 11 months ago

Seems like that by generating this new pair, their public key is not understood as a Authority, because it fails in the getAuthorityIndex function in the following code:

    for i, auth := range Authorities {
        if bytes.Equal(pub.Encode(), auth.Key.Encode()) {
            return uint32(i), nil
        }
    }
kanishkatn commented 11 months ago

Hey @1garo , could you create a draft PR? We could move the conversation there!

1garo commented 11 months ago

Of course, it's created: https://github.com/ChainSafe/gossamer/pull/3587

kanishkatn commented 11 months ago

I believe we don't have the need to generate an account if not specified since we're still in development and only need development accounts. @EclesioMeloJunior could you confirm?

Further, If we want to support the use of auto-generated or external accounts, we'll have to

Thank you for your time and patience @1garo ! I believe this separation isn't a priority for us (core contributors) at the moment. If you're interested in contributing to CLI, I can create issues.

1garo commented 11 months ago

Thank you for your time and patience @1garo ! I believe this separation isn't a priority for us (core contributors) at the moment. If you're interested in contributing to CLI, I can create issues.

I would love to! I feel that contributing to the CLI could help me understand gossamer better, so it's a win-win.