spacemeshos / go-spacemesh

Go Implementation of the Spacemesh protocol full node. 💾⏰💪
https://spacemesh.io
MIT License
748 stars 211 forks source link

Testnets and Devnets genesis accounts #2493

Closed avive closed 3 years ago

avive commented 3 years ago

Motivation

We'd like to easily enable devs to have accounts with funds to test transactions before one of their accounts got coins view rewards. This will make it easier to work with transactions on devnets and on testnets.

We have recently added features to smrepl to restore a wallet from a mnemonic so we can use this to empower dev to quickly create a wallet with the genesis accounts in a localnet / devnet. The public keys below are accounts from wallets we have the mnemonic for.

Current genesis account were generated ad-hoc and we don't have the mnemonic for them to be able to restore a wallet for them.

So the workflow for testing transactions on a localnet becomes:

  1. use smrepl to connect to one of the localnet nodes.
  2. restore a walllet from the dev builds mnemonic (will be shared in smrepl readme and in go-sm readme)
  3. transact with one of the genesis accounts - the first account that is auto created for a new restored wallet will be one of the genesis accounts.

We can also provide a pre-configured wallet file and share its password, so the alt flow will be top open this wallet in smrepl from file.

For public testnets, this change will enable testing of transactions more quickly as soon as epoch 2 starts without having to wait for a coinbase address to get rewards in order to transact.

So the flow for interactive transaction testing on epoch 2 or later becomes:

  1. Restore wallet account from mnemonic.
  2. Transact using first tap account in smrepl - first generated account will be the first tap account.

Requested Changes

Testnet Builds

Config node to use the following public keys for genesis accounts:

Localnet and dev builds:

Config node to use the following public keys for genesis accounts:

noamnelke commented 3 years ago

Just to be clear, it's also possible to restore a wallet from a private key, right?

A mnemonic can be derived from a private key or vice-versa the private key can be derived from the mnemonic. So if we have the private key for the tap accounts whose public keys are used today - we can derive a mnemonic for them. Have we lost the private keys? We should store them in 1Password if we aren't already.

Also, I'm not sure what change should be made to the code based on this issue... Setting the config for testnet is currently done manually and I'm not sure how the config for the devnet is generated, but it's not in this repo's code AFAIK. Maybe @narayanprusty can help direct you to the right repository.

avive commented 3 years ago

the pub keys for genesis accounts are currently hard coded in go-sm for both dev and testnets. It would be nice to have the testnet genesis public account keys come from the config file.

regarding mnemonic - it is derived from entropy - not from ec key pairs following bip39 and friends but in the node we only need to include pub keys of derived accounts.

So this request is just to replace the currently hard-coded public keys with keys that we can easily restore in spacemesh wallets given the seed entropy / mnemonic.

lrettig commented 3 years ago

Related: #2004

avive commented 3 years ago

I think we can agree that ideally:

  1. Testnet genesis accounts should be defined in TN config file and not hard-coded in go-sm - a {pubKey, balance} tuple.
  2. Localnet genesis accounts should be defined in TN config file for each localnet nodes - similar to tn.
  3. Genesis accounts should only be hard-coded in go-sm if they are needed for CI for tests of nodes that are started w/o a config file - I believe that we still have some tests that use these. Ideally these tests can also configure genesis account via config files.
dshulyak commented 3 years ago

@avive @noamnelke is there a case when we want to configure a nonce for an initial account? I am working on this issue, and considering if I can simplify config a bit

avive commented 3 years ago

I'm not 100% sure what you mean. The nonce in genesis accounts should always be 0 as these accounts didn't execute any transactions - similar to you sending some coins to an account that was not on the mesh - it is created with a balance and a zero nonce.

dshulyak commented 3 years ago

Thats what i thought as well, GenesisConfig allowed setting account nonce to a non-zero value. I removed it

avive commented 3 years ago

One thing to check - the non-zero nonce might have been used in some tests so they might need to be updated.

avive commented 3 years ago

So to summarize, what we need to do is to add support to a node config file which will have user node settings such as post and an immutable network config file that has the network params which are on consensus on genesis. The genesis accounts should be part of the network config file.

avive commented 3 years ago

Next step on this task is to publish a config file for 0.2 devnets that has the requested tap account as part of a devnet release flow. @moshababo

dshulyak commented 3 years ago

i think we can add it to all configs that are used in go-spacraft.

dshulyak commented 3 years ago

@avive what balance is enough? 10^5 SMH is good?

avive commented 3 years ago

yes and to be clear devnet accounts should be the same as testnet accounts.

dshulyak commented 3 years ago

@avive i will use 4 public keys that you provided in the issue, both for testnets and devnet. but where is can find:

Account 3 - use the public tap account public address already used in recent testnet builds.

dshulyak commented 3 years ago

Did you mean keys that we have in internal default config?

avive commented 3 years ago

Please use this community tap public address: 0xafed9a1c17ca7eaa7a6795dbc7bee1b1d992c7ba

avive commented 3 years ago

From Yael - this is the address fo the testnet's community tap.