This repository was archived by the owner on Jun 25, 2024. It is now read-only.
forked from near/nearcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Genesis config patch #9
Draft
mercepluka
wants to merge
28
commits into
master
Choose a base branch
from
genesis-config-patch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
497fe67
Added genesis config patch struct
mercepluka 5a792c5
Added dec_format to import
mercepluka c73c714
Added Read import
mercepluka 253a38e
Renamed from_file function
mercepluka e22cc10
Added apply_patch function
mercepluka c389e33
Fixed return type
mercepluka 64bb246
Fixed typo
mercepluka ae032c0
Removed self
mercepluka e7b6c4a
added self to function call
mercepluka 43c1e3c
Fixed ownership
mercepluka 0256113
Added patching
mercepluka 668b7d4
Removed None
mercepluka e9fd9f3
Added skipping of patch genesis
mercepluka b2e769f
Added print debug statement
mercepluka b81f26c
Added patch_config to cli
mercepluka dfcbd32
Added debug
mercepluka e5d35f1
Added more debug
mercepluka f24dbc2
Formated debug
mercepluka 9ed8681
Formated debug
mercepluka d13af72
Formated debug
mercepluka e5e09e5
Fixing recursion
mercepluka da527e1
Fixing recursion
mercepluka 134382f
removed recursion
mercepluka f05e893
removed comments and debug code
mercepluka f97f955
fixed patch -> skip
mercepluka 2b309d8
added debug
mercepluka e914b87
removed debug
mercepluka 0389cba
added comment for field patch_config
mercepluka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use near_config_utils::ValidationError; | ||
| use near_primitives::shard_layout::ShardLayout; | ||
| use near_primitives::{ | ||
| serialize::dec_format, | ||
| types::{ | ||
| AccountId, AccountInfo, Balance, BlockHeightDelta, Gas, NumBlocks, NumSeats | ||
| }, | ||
| }; | ||
| use num_rational::Rational32; | ||
| use std::fs::File; | ||
| use std::io::Read; | ||
| use std::path::Path; | ||
|
|
||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct GenesisConfigPatch { | ||
| pub num_block_producer_seats: Option<NumSeats>, | ||
| pub num_block_producer_seats_per_shard: Option<Vec<NumSeats>>, | ||
| pub avg_hidden_validator_seats_per_shard: Option<Vec<NumSeats>>, | ||
| pub dynamic_resharding: Option<bool>, | ||
| pub protocol_upgrade_stake_threshold: Option<Rational32>, | ||
| pub epoch_length: Option<BlockHeightDelta>, | ||
| pub gas_limit: Option<Gas>, | ||
| #[serde(with = "dec_format")] | ||
| #[serde(default)] | ||
| pub min_gas_price: Option<Balance>, | ||
| #[serde(with = "dec_format")] | ||
| #[serde(default)] | ||
| pub max_gas_price: Option<Balance>, | ||
| pub block_producer_kickout_threshold: Option<u8>, | ||
| pub chunk_producer_kickout_threshold: Option<u8>, | ||
| pub online_min_threshold: Option<Rational32>, | ||
| pub online_max_threshold: Option<Rational32>, | ||
| pub gas_price_adjustment_rate: Option<Rational32>, | ||
| pub validators: Option<Vec<AccountInfo>>, | ||
| pub transaction_validity_period: Option<NumBlocks>, | ||
| pub protocol_reward_rate: Option<Rational32>, | ||
| pub max_inflation_rate: Option<Rational32>, | ||
| #[serde(with = "dec_format")] | ||
| #[serde(default)] | ||
| pub total_supply: Option<Balance>, | ||
| pub num_blocks_per_year: Option<NumBlocks>, | ||
| pub protocol_treasury_account: Option<AccountId>, | ||
| #[serde(with = "dec_format")] | ||
| #[serde(default)] | ||
| pub fishermen_threshold: Option<Balance>, | ||
| pub minimum_stake_divisor: Option<u64>, | ||
| pub shard_layout: Option<ShardLayout>, | ||
| pub num_chunk_only_producer_seats: Option<NumSeats>, | ||
| pub minimum_validators_per_shard: Option<NumSeats>, | ||
| pub max_kickout_stake_perc: Option<u8>, | ||
| pub minimum_stake_ratio: Option<Rational32>, | ||
| } | ||
|
|
||
| impl GenesisConfigPatch { | ||
| pub fn from_file<P: AsRef<Path>>(path: P) -> Result<GenesisConfigPatch, ValidationError> { | ||
| let mut file = File::open(&path).map_err(|_| ValidationError::GenesisFileError { | ||
| error_message: format!( | ||
| "Could not open genesis patch config file at path {}.", | ||
| &path.as_ref().display() | ||
| ), | ||
| })?; | ||
|
|
||
| let mut json_str = String::new(); | ||
| file.read_to_string(&mut json_str).map_err(|_| ValidationError::GenesisFileError { | ||
| error_message: "Failed to read genesis patch config file to string. ".to_string(), | ||
| })?; | ||
|
|
||
| let json_str_without_comments = near_config_utils::strip_comments_from_json_str(&json_str) | ||
| .map_err(|_| ValidationError::GenesisFileError { | ||
| error_message: "Failed to strip comments from genesis patch config file".to_string(), | ||
| })?; | ||
|
|
||
| let genesis_patch = serde_json::from_str::<GenesisConfigPatch>(&json_str_without_comments) | ||
| .map_err(|_| ValidationError::GenesisFileError { | ||
| error_message: "Failed to deserialize the genesis patch records.".to_string(), | ||
| })?; | ||
|
|
||
| Ok(genesis_patch) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: order properties alphabetically by name to improve readability
Btw, some of the fields from initial GenesisConfig are ommitted, how did you choose which to include in the patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the order, I would prefer that order is the same as in the original genesis config struct. I do not have any preferences in fields being in alphabetical or current order. I can change it in both structs, but my guess is that they are ok with the current order of fields. Probably @mhalambek would know more about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have omitted the first 4 fields from the original genesis config struct (
protocol_version,genesis_time,chain_id, andgenesis_height).I have omitted them because it seemed to me that Calimero (or similar Near forks) would not use override of those fields as discussed earlier with Hala. I have no strong preference here, I can also include all fields for the simplicity