-
Notifications
You must be signed in to change notification settings - Fork 38
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(core): load genesis file by network id #250
base: dev
Are you sure you want to change the base?
Conversation
I think tests are failing in CI because the genesis file does not exist yet. They pass on my machine, where it does exist. Probably I need to update the |
Totally. It should be done inside (or beside) |
Ok, so I just pushed a commit that does the Getting the init functionality working was a bit tricky. I had to think about how these genesis files will be stored in the git repo and installed. I figured it makes sense that they would have same filename in the repo as in user's homedir. I put them in Previously the genesis code was loaded into the executable with However that gets me thinking: with this The tradeoff is that users would not be able to define their own networks without recompiling. I am unsure that users would typically need to define their own networks though...? I hope I am being clear. ;-) See also the kindelia/genesis/README.md |
f6435eb
to
3911d3a
Compare
rebased to dev tip. |
I don't understand why the tests are failing in CI. The errors indicate that But it works fine for me, provided that I run
So either the CI is somehow not running |
I think this is useful for development / experimentation. But it's indeed not strictly necessary.
I was thinking of keeping It's important to keep
It's indeed not run, this should not be necessary to run tests. |
I thought I had accounted for this by creating genesis-tests.kdl which the tests include_str!(). What I missed is that some tests actually invoke the kindelia binary with a kindelia!() macro and then check its output. And since I had already run I think what I can do is change the Anyway, I will be sure and run the tests without the ~/.kindelia directory existing before pushing to this branch again. |
I went back to the drawing board a little on this, thinking about what is useful and makes sense for the end user. The general approach is to make it easy for user to create a new network and genesis block for testing and local development, but also make it difficult to inadvertently screw up the genesis block for an "official" network. Overview:
|
rebased on latest dev. |
rebased on latest dev to resolve conflict. |
Addresses kindelia#163 Previously chain state was stored under a path such as: ~/.kindelia/state/{blocks,heaps} With this change, the data is stored at: ~/.kindelia/state/<network_id>/{blocks,heaps} This enables for example flipping back and forth between a testnet and mainnet just by changing network_id in the config, or even via cli arg.
Addresses kindelia#243 Support for loading a different genesis block for each network. The genesis block is loaded from a file whose path is the pattern: ~/.kindelia/genesis/<network-id>.kdl Changes: core: * add util::genesis_path() with associated error enum * add util::genesis_code() with associated error enum * modify hvm::test_statements*() to accept network_id and load genesis block from file instead of compiled string * modify node::new() to to accept network_id and load genesis block from file instead of compiled string cli: * add network_id to test command, required by hvm::test_statements() * fix parsing of hex values for --network_id * add clap_num dep for parsing hex values
kindelia_core: * genesis.kdl file removed. (moved into kindelia/genesis/networks) * genesis Statements are passed to kindelia_core api, not network_id * added kindelia_core/genesis-tests.kdl for core test cases * updated test cases * remove empty constants.rs * remove genesis_path(). (moved into kindelia/src/genesis.rs) kindelia: * all genesis files get compiled into kindelia executable * latest (by name) genesis file gets installed by kindelia init * add kindelia/genesis/README.md * add genesis.rs and move some util fn into it * cargo add include_dir * cargo fmt fixes * parse genesis statements in 'node start' and 'test' * update test(s)
This fixes some test cases that were failing when run before `kindelia init`. This failed because the tests invoke the kindelia executable and depend on statements in the genesis block. The fix is to: 1) load code from ../kindelia_core/genesis-tests.kdl by default 2) allow user to supply an alternate file with --genesis arg. cli.rs * add --genesis to test cmd main.rs * read genesis arg and load code from file if present * load code from ../kindelia_core/genesis-tests.kdl if not present * test_code() accepts genesis_code arg instead of network_id
Simplifies loading of the genesis block (prelude) because we simply load the code from static string compiled into executable. Previously, we wrote the code to a file on disk during the `init` command and later read it in for other commands. genesis.rs: * remove genesis_path() and GenesisPathError * remove init_genesis() and InitGenesisError * modify genesis_code() to read from static string instead of a file main.rs: * remove call to init_genesis() README.rs: * remove note about init command installing genesis files.
Adds ability for user to specify genesis statements for a network. To avoid confusion, it is not allowed to override the genesis statements for a network_id that is built into the executable. cli.rs: * node command accepts optional genesis argument main.rs: * retrieve genesis path from: env: KINDELIA_GENESIS config: node.network.<network_id>.genesis cli arg: genesis * load genesis statements from file if provided and verify the network_id is not compiled into executable.
Fixes a "property X not found in config" error when the missing property has a default value.
rebased on latest dev to resolve conflict. |
Addresses #243
Support for loading a different genesis block for each network.
edit: see this summary of latest changes
The genesis block is loaded from a file whose path is the pattern:~/.kindelia/genesis/<network-id>.kdl
Changes:
core:
note: the error enums are based on the style/pattern recommended in this article, which is well worth a read. The pre-existing calling functions still call unwrap() on the result, but intent is to address that in #247.
cli:
I will note that this change might have security implications. In particular, when a genesis block is loaded from a static string in the executable then a checksum of the executable binary will also include the genesis block. By moving the block out into the filesystem we lose that guarantee. So both the binary and corresponding block file must be summed independently. Of course the benefit is that the system can cleanly handle an arbitrary number of networks. It could be that for mainnet, we use a hybrid approach, whereby mainnet and perhaps present testnet(s) genesis blocks are included in the binary, but others can be created by users at will.