Skip to content

Commit

Permalink
Add configuration file for node initialisation (#138)
Browse files Browse the repository at this point in the history
* Working parsing of config file, need to implement file creation + improve code organisation

* make clippy happy

* applied changes, improved congfig file + encapsulated logic in genesis.rs

* make clippy happy

* Creation of genesis.dat file

* Move hex_str_to_byte_array() to utils

* removed async for make_genesis(), created start.rs, added genesis test

* Added back doc + added doc

* Accounts are successfully added to accounts folder + genesis.dat created

* Added testing for account files existing

* refactor AccountData struct

* Fixed first half of comments

* Use miden_crypto::utils::hex_to_bytes() for hex deserialization

* Added Option<>

* Changed NodeTopLevelConfig to StartCommandConfig

* Added new(), fixed functions, added try_from

* Added manual Serialization / Deserialization for AuthSchemeInput and AccountData

* AccountData structs are correctly serialised and deserialised

* Added testing for serialization / deserialization, bugs

* Removed unused crates

* changed seed to init_seed

* Updated with miden-base AccountData and AuthData additions

* Updated file structure + re-wrote test

* Fix formatting

* refactor: code organization

* Added requested changes

* Accounts folder is created in same folder as genesis file

* Removed folder removal + removed mode + improved comment

* Updated documentation

* Fixed readme + adjusted if statement for account dir creation

---------

Co-authored-by: Bobbin Threadbare <bobbinth@protonmail.com>
  • Loading branch information
phklive and bobbinth authored Jan 19, 2024
1 parent f860b4b commit 58be273
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 202 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ miden-lib = { package = "miden-lib", git = "https://github.com/0xPolygonMiden/mi
miden_objects = { package = "miden-objects", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "main" }
thiserror = "1.0"
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["fmt", "json", "env-filter"] }
tracing-subscriber = { version = "0.3", features = [
"fmt",
"json",
"env-filter",
] }
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ Currently, the only difference between the two is how long the `make-genesis` co

### Generating the genesis file

Before running the node, you must first generate the genesis file. The contents of the genesis file are currently hardcoded in Rust, but we intend to make these configurable shortly. The genesis block currently sets up 2 accounts: a faucet account for a `POL` token, as well as a wallet account.
Before running the node, you must first generate the genesis file. The contents of the genesis file are fully configurable through a genesis inputs file written in TOML. An example genesis inputs file can be found here: [genesis.toml](node/genesis.toml)


To generate the genesis file, run:
```sh
miden-node make-genesis
```

This will generate 3 files in the current directory:
By default this will generate 1 file and 1 folder in the current directory:
- `genesis.dat`: the genesis file.
- `faucet.fsk` and `wallet.fsk`: the public/private keys of the faucet and wallet accounts, respectively.
- `accounts` directory containing `.mac` files (one per account) for the accounts defined in the genesis inputs file. Each `.mac` file contains full serialization of an account, including code, storage, and authentication info.

### Running the node

Expand Down
19 changes: 19 additions & 0 deletions node/genesis.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is an example genesis input file for the Miden node.

version = 1
timestamp = 1672531200

[[accounts]]
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"

[[accounts]]
type = "BasicFungibleFaucet"
init_seed = "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xd123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
token_symbol = "POL"
decimals = 12
max_supply = 1000000
152 changes: 0 additions & 152 deletions node/src/commands.rs

This file was deleted.

43 changes: 43 additions & 0 deletions node/src/commands/genesis/inputs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use serde::Deserialize;

// INPUT HELPER STRUCTS
// ================================================================================================

/// Input types are helper structures designed for parsing and deserializing genesis input files.
/// They serve as intermediary representations, facilitating the conversion from
/// placeholder types (like `GenesisInput`) to internal types (like `GenesisState`).
#[derive(Debug, Clone, Deserialize)]
pub struct GenesisInput {
pub version: u64,
pub timestamp: u64,
pub accounts: Vec<AccountInput>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
pub enum AccountInput {
BasicWallet(BasicWalletInputs),
BasicFungibleFaucet(BasicFungibleFaucetInputs),
}

#[derive(Debug, Clone, Deserialize)]
pub struct BasicWalletInputs {
pub init_seed: String,
pub auth_scheme: AuthSchemeInput,
pub auth_seed: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct BasicFungibleFaucetInputs {
pub init_seed: String,
pub auth_scheme: AuthSchemeInput,
pub auth_seed: String,
pub token_symbol: String,
pub decimals: u8,
pub max_supply: u64,
}

#[derive(Debug, Clone, Copy, Deserialize)]
pub enum AuthSchemeInput {
RpoFalcon512,
}
Loading

0 comments on commit 58be273

Please sign in to comment.