feat(configs): add Shelley config structs (#359)

This commit is contained in:
Santiago Carmuega 2023-12-13 21:27:31 -03:00 committed by GitHub
parent ccef8795f1
commit b4b7b93db2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 240 additions and 0 deletions

View file

@ -1,3 +1,4 @@
//! Genesis data structs and utilities
pub mod byron;
pub mod shelley;

View file

@ -0,0 +1,103 @@
use serde::Deserialize;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GenDelegs {
pub delegate: Option<String>,
pub vrf: Option<String>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolVersion {
pub minor: Option<u32>,
pub major: Option<u32>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExtraEntropy {
pub tag: Option<String>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolParams {
pub protocol_version: Option<ProtocolVersion>,
pub decentralisation_param: Option<u32>,
pub e_max: Option<u32>,
pub extra_entropy: Option<ExtraEntropy>,
pub max_tx_size: Option<u32>,
pub max_block_body_size: Option<u32>,
pub max_block_header_size: Option<u32>,
pub min_fee_a: Option<u32>,
pub min_fee_b: Option<u32>,
pub min_u_tx_o_value: Option<u32>,
pub pool_deposit: Option<u64>,
pub min_pool_cost: Option<u64>,
pub key_deposit: Option<u32>,
pub n_opt: Option<u32>,
pub rho: Option<f32>,
pub tau: Option<f32>,
pub a0: Option<f32>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Staking {
pub pools: Option<HashMap<String, String>>,
pub stake: Option<HashMap<String, String>>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GenesisFile {
pub active_slots_coeff: Option<f32>,
pub epoch_length: Option<u32>,
pub gen_delegs: Option<HashMap<String, GenDelegs>>,
pub initial_funds: Option<HashMap<String, String>>,
pub max_kes_evolutions: Option<u32>,
pub max_lovelace_supply: Option<u64>,
pub network_id: Option<String>,
pub network_magic: Option<u32>,
pub protocol_params: Option<ProtocolParams>,
pub security_param: Option<u32>,
pub slot_length: Option<u32>,
pub slots_per_kes_period: Option<u32>,
pub staking: Option<Staking>,
pub system_start: Option<String>,
pub update_quorum: Option<u32>,
}
pub fn from_file(path: &std::path::Path) -> Result<GenesisFile, std::io::Error> {
let file = std::fs::File::open(path)?;
let reader = std::io::BufReader::new(file);
let parsed: GenesisFile = serde_json::from_reader(reader)?;
Ok(parsed)
}
#[cfg(test)]
mod tests {
use super::*;
fn load_test_data_config(network: &str) -> GenesisFile {
let path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("..")
.join("test_data")
.join(format!("{network}-shelley-genesis.json"));
from_file(&path).unwrap()
}
#[test]
fn test_preview_json_loads() {
load_test_data_config("preview");
}
#[test]
fn test_mainnet_json_loads() {
load_test_data_config("mainnet");
}
}

View file

@ -0,0 +1,68 @@
{
"activeSlotsCoeff": 0.05,
"protocolParams": {
"protocolVersion": {
"minor": 0,
"major": 2
},
"decentralisationParam": 1,
"eMax": 18,
"extraEntropy": {
"tag": "NeutralNonce"
},
"maxTxSize": 16384,
"maxBlockBodySize": 65536,
"maxBlockHeaderSize": 1100,
"minFeeA": 44,
"minFeeB": 155381,
"minUTxOValue": 1000000,
"poolDeposit": 500000000,
"minPoolCost": 340000000,
"keyDeposit": 2000000,
"nOpt": 150,
"rho": 0.003,
"tau": 0.20,
"a0": 0.3
},
"genDelegs": {
"ad5463153dc3d24b9ff133e46136028bdc1edbb897f5a7cf1b37950c": {
"delegate": "d9e5c76ad5ee778960804094a389f0b546b5c2b140a62f8ec43ea54d",
"vrf": "64fa87e8b29a5b7bfbd6795677e3e878c505bc4a3649485d366b50abadec92d7"
},
"b9547b8a57656539a8d9bc42c008e38d9c8bd9c8adbb1e73ad529497": {
"delegate": "855d6fc1e54274e331e34478eeac8d060b0b90c1f9e8a2b01167c048",
"vrf": "66d5167a1f426bd1adcc8bbf4b88c280d38c148d135cb41e3f5a39f948ad7fcc"
},
"60baee25cbc90047e83fd01e1e57dc0b06d3d0cb150d0ab40bbfead1": {
"delegate": "7f72a1826ae3b279782ab2bc582d0d2958de65bd86b2c4f82d8ba956",
"vrf": "c0546d9aa5740afd569d3c2d9c412595cd60822bb6d9a4e8ce6c43d12bd0f674"
},
"f7b341c14cd58fca4195a9b278cce1ef402dc0e06deb77e543cd1757": {
"delegate": "69ae12f9e45c0c9122356c8e624b1fbbed6c22a2e3b4358cf0cb5011",
"vrf": "6394a632af51a32768a6f12dac3485d9c0712d0b54e3f389f355385762a478f2"
},
"162f94554ac8c225383a2248c245659eda870eaa82d0ef25fc7dcd82": {
"delegate": "4485708022839a7b9b8b639a939c85ec0ed6999b5b6dc651b03c43f6",
"vrf": "aba81e764b71006c515986bf7b37a72fbb5554f78e6775f08e384dbd572a4b32"
},
"2075a095b3c844a29c24317a94a643ab8e22d54a3a3a72a420260af6": {
"delegate": "6535db26347283990a252313a7903a45e3526ec25ddba381c071b25b",
"vrf": "fcaca997b8105bd860876348fc2c6e68b13607f9bbd23515cd2193b555d267af"
},
"268cfc0b89e910ead22e0ade91493d8212f53f3e2164b2e4bef0819b": {
"delegate": "1d4f2e1fda43070d71bb22a5522f86943c7c18aeb4fa47a362c27e23",
"vrf": "63ef48bc5355f3e7973100c371d6a095251c80ceb40559f4750aa7014a6fb6db"
}
},
"updateQuorum": 5,
"networkId": "Mainnet",
"initialFunds": {},
"maxLovelaceSupply": 45000000000000000,
"networkMagic": 764824073,
"epochLength": 432000,
"systemStart": "2017-09-23T21:44:51Z",
"slotsPerKESPeriod": 129600,
"slotLength": 1,
"maxKESEvolutions": 62,
"securityParam": 2160
}

View file

@ -0,0 +1,68 @@
{
"activeSlotsCoeff": 0.05,
"epochLength": 86400,
"genDelegs": {
"12b0f443d02861948a0fce9541916b014e8402984c7b83ad70a834ce": {
"delegate": "7c54a168c731f2f44ced620f3cca7c2bd90731cab223d5167aa994e6",
"vrf": "62d546a35e1be66a2b06e29558ef33f4222f1c466adbb59b52d800964d4e60ec"
},
"3df542796a64e399b60c74acfbdb5afa1e114532fa36b46d6368ef3a": {
"delegate": "c44bc2f3cc7e98c0f227aa399e4035c33c0d775a0985875fff488e20",
"vrf": "4f9d334decadff6eba258b2df8ae1f02580a2628bce47ae7d957e1acd3f42a3c"
},
"93fd5083ff20e7ab5570948831730073143bea5a5d5539852ed45889": {
"delegate": "82a02922f10105566b70366b07c758c8134fa91b3d8ae697dfa5e8e0",
"vrf": "8a57e94a9b4c65ec575f35d41edb1df399fa30fdf10775389f5d1ef670ca3f9f"
},
"a86cab3ea72eabb2e8aafbbf4abbd2ba5bdfd04eea26a39b126a78e4": {
"delegate": "10257f6d3bae913514bdc96c9170b3166bf6838cca95736b0e418426",
"vrf": "1b54aad6b013145a0fc74bb5c2aa368ebaf3999e88637d78e09706d0cc29874a"
},
"b799804a28885bd49c0e1b99d8b3b26de0fac17a5cf651ecf0c872f0": {
"delegate": "ebe606e22d932d51be2c1ce87e7d7e4c9a7d1f7df4a5535c29e23d22",
"vrf": "b3fc06a1f8ee69ff23185d9af453503be8b15b2652e1f9fb7c3ded6797a2d6f9"
},
"d125812d6ab973a2c152a0525b7fd32d36ff13555a427966a9cac9b1": {
"delegate": "e302198135fb5b00bfe0b9b5623426f7cf03179ab7ba75f945d5b79b",
"vrf": "b45ca2ed95f92248fa0322ce1fc9f815a5a5aa2f21f1adc2c42c4dccfc7ba631"
},
"ef27651990a26449a40767d5e06cdef1670a3f3ff4b951d385b51787": {
"delegate": "0e0b11e80d958732e587585d30978d683a061831d1b753878f549d05",
"vrf": "b860ec844f6cd476c4fabb4aa1ca72d5c74d82f3835aed3c9515a35b6e048719"
}
},
"initialFunds": {},
"maxKESEvolutions": 62,
"maxLovelaceSupply": 45000000000000000,
"networkId": "Testnet",
"networkMagic": 2,
"protocolParams": {
"protocolVersion": {
"minor": 0,
"major": 6
},
"decentralisationParam": 1,
"eMax": 18,
"extraEntropy": {
"tag": "NeutralNonce"
},
"maxTxSize": 16384,
"maxBlockBodySize": 65536,
"maxBlockHeaderSize": 1100,
"minFeeA": 44,
"minFeeB": 155381,
"minUTxOValue": 1000000,
"poolDeposit": 500000000,
"minPoolCost": 340000000,
"keyDeposit": 2000000,
"nOpt": 150,
"rho": 0.003,
"tau": 0.20,
"a0": 0.3
},
"securityParam": 432,
"slotLength": 1,
"slotsPerKESPeriod": 129600,
"systemStart": "2022-10-25T00:00:00Z",
"updateQuorum": 5
}