kindelia / Kindelia

An efficient, secure cryptocomputer
https://kindelia.org/
602 stars 41 forks source link

Set initial peers and genesis code alongside network id #243

Open steinerkelvin opened 1 year ago

steinerkelvin commented 1 year ago

It's interesting to be able to associate both with the network id in the node configuration.

[node.network]
network_id = "0xCAFE0004"

[node.networks.0xCAFE0004]
genesis_code = '~/.kindelia/genesis/cafe0004.kdl'
initial_peers = [
  "64.227.110.69",
  "188.166.3.140",
]

[node.networks.0xCAFE0005]
genesis_code = '~/.kindelia/genesis/cafe0005.kdl'
initial_peers = [
  ...
]
dan-da commented 1 year ago

I think I could take this one.

dan-da commented 1 year ago

@steinerkelvin can you provide an example of what might go in ~/.kindelia/genesis/cafe0004.kdl? and cafe0005.kdl?

is it different than kindelia_core/genesis.kdl?

btw, initial_peers is already defined per-network as of #235. See default.toml.

steinerkelvin commented 1 year ago

Yeap, it's kindelia_core/genesis.kdl.

~/.kindelia/genesis/0xCAFE00XX.kdl would store an specific version of kindelia_core/genesis.kdl.

dan-da commented 1 year ago
[node.networks.0xCAFE0004]
genesis_code = '~/.kindelia/genesis/cafe0004.kdl'

It occurs to me that the path of the genesis block file could be deterministic (automagic) based on network ID.

Eg for [node.networks.0xCAFE0004] the node would automatically look for the matching file ~/.kindelia/genesis/0xCAFE0004.kdl and print an error with the path if not found. So it is not necessary to specify genesis_code (line 2 above goes away) and that's one less thing to possibly get wrong in the config.

Of course it sacrifices flexibility in terms of naming and path. So that's the tradeoff.

Counter-argument is that the deterministic approach is more regular and predictable. Less chance for users to screw up and use the wrong genesis block for a given network.

thoughts?

I will start with the deterministic approach because it is a bit faster to impl and after make it configurable if that is the consensus.

steinerkelvin commented 1 year ago

I think is fine to do it deterministically. Less bloat and it could be added in the future as an optional field if it feels necessary.