-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Tendermint max block size param to genesis config file #843
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
Changes from 21 commits
4b57678
e771a3e
5144e29
cf8444c
1ecff45
d557635
8bdbbf7
ca6d785
fadca13
02f0970
d1301b5
8bc924f
fafb161
0da5567
9daea84
08b6741
a98aae8
fd7cc4c
2e93732
2c6baec
f19e839
f0fc770
0e02760
844f209
878d2d3
da9f3aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ use super::storage::types::{decode, encode}; | |
| use super::storage::{types, Storage}; | ||
| use crate::ledger::storage::{self as ledger_storage}; | ||
| use crate::types::address::{Address, InternalAddress}; | ||
| use crate::types::chain::ProposalBytes; | ||
| use crate::types::storage::Key; | ||
| use crate::types::time::DurationSecs; | ||
|
|
||
|
|
@@ -32,6 +33,8 @@ pub struct Parameters { | |
| pub epoch_duration: EpochDuration, | ||
| /// Maximum expected time per block (read only) | ||
| pub max_expected_time_per_block: DurationSecs, | ||
| /// Max payload size, in bytes, for a tx batch proposal. | ||
| pub max_proposal_bytes: ProposalBytes, | ||
| /// Whitelisted validity predicate hashes (read only) | ||
| pub vp_whitelist: Vec<String>, | ||
| /// Whitelisted tx hashes (read only) | ||
|
|
@@ -101,6 +104,7 @@ impl Parameters { | |
| let Self { | ||
| epoch_duration, | ||
| max_expected_time_per_block, | ||
| max_proposal_bytes, | ||
| vp_whitelist, | ||
| tx_whitelist, | ||
| implicit_vp, | ||
|
|
@@ -111,6 +115,16 @@ impl Parameters { | |
| pos_inflation_amount, | ||
| } = self; | ||
|
|
||
| // write max proposal bytes parameter | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add validation somewhere that the input isn't insane. Here perhaps?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe it' crazy to validate genesis input. But we will need some mechanism for validation if it is changed by governance. Tomas mentioned something about guarding it with VPs. Maybe a separate pr.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're grabbing this parameter from the toml config, whose deserialization already has some logic that checks if it is in the range [1 B, 90 MiB]
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if that's enough?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I missed that. So good enough for now. For governance, I'm not so sure as it doesn't require a hard fork but just a change in storage. So we might need this VP idea. But that can be a separate PR.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw I think I misinterpreted the Tendermint specs. https://github.com/tendermint/tendermint/blob/v0.34.x/spec/abci/apps.md#blockparamsmaxbytes I think the hard cap for a block might be |
||
| let max_proposal_bytes_key = storage::get_max_proposal_bytes_key(); | ||
| let max_proposal_bytes_value = encode(&max_proposal_bytes); | ||
| storage | ||
| .write(&max_proposal_bytes_key, max_proposal_bytes_value) | ||
| .expect( | ||
| "Max proposal bytes parameter must be initialized in the \ | ||
| genesis block", | ||
| ); | ||
|
|
||
| // write epoch parameters | ||
| let epoch_key = storage::get_epoch_duration_storage_key(); | ||
| let epoch_value = encode(epoch_duration); | ||
|
|
@@ -382,6 +396,17 @@ where | |
| DB: ledger_storage::DB + for<'iter> ledger_storage::DBIter<'iter>, | ||
| H: ledger_storage::StorageHasher, | ||
| { | ||
| // read max proposal bytes | ||
| let (max_proposal_bytes, gas_proposal_bytes) = { | ||
| let key = storage::get_max_proposal_bytes_key(); | ||
| let (value, gas) = | ||
| storage.read(&key).map_err(ReadError::StorageError)?; | ||
| let value: ProposalBytes = | ||
| decode(value.ok_or(ReadError::ParametersMissing)?) | ||
| .map_err(ReadError::StorageTypeError)?; | ||
| (value, gas) | ||
| }; | ||
|
|
||
| // read epoch duration | ||
| let (epoch_duration, gas_epoch) = read_epoch_duration_parameter(storage) | ||
| .expect("Couldn't read epoch duration parameters"); | ||
|
|
@@ -464,10 +489,31 @@ where | |
| decode(value.ok_or(ReadError::ParametersMissing)?) | ||
| .map_err(ReadError::StorageTypeError)?; | ||
|
|
||
| let total_gas_cost = [ | ||
| gas_epoch, | ||
| gas_tx, | ||
| gas_vp, | ||
| gas_time, | ||
| gas_implicit_vp, | ||
| gas_epy, | ||
| gas_gain_p, | ||
| gas_gain_d, | ||
| gas_staked, | ||
| gas_reward, | ||
| gas_proposal_bytes, | ||
| ] | ||
| .into_iter() | ||
| .fold(0u64, |accum, gas| { | ||
| accum | ||
| .checked_add(gas) | ||
| .expect("u64 overflow occurred while doing gas arithmetic") | ||
| }); | ||
|
|
||
| Ok(( | ||
| Parameters { | ||
| epoch_duration, | ||
| max_expected_time_per_block, | ||
| max_proposal_bytes, | ||
| vp_whitelist, | ||
| tx_whitelist, | ||
| implicit_vp, | ||
|
|
@@ -477,15 +523,6 @@ where | |
| staked_ratio, | ||
| pos_inflation_amount, | ||
| }, | ||
| gas_epoch | ||
| + gas_tx | ||
| + gas_vp | ||
| + gas_time | ||
| + gas_implicit_vp | ||
| + gas_epy | ||
| + gas_gain_p | ||
| + gas_gain_d | ||
| + gas_staked | ||
| + gas_reward, | ||
| total_gas_cost, | ||
| )) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ const POS_GAIN_P_KEY: &str = "pos_gain_p"; | |
| const POS_GAIN_D_KEY: &str = "pos_gain_d"; | ||
| const STAKED_RATIO_KEY: &str = "staked_ratio_key"; | ||
| const POS_INFLATION_AMOUNT_KEY: &str = "pos_inflation_amount_key"; | ||
| const MAX_PROPOSAL_BYTES_KEY: &str = "max_proposal_bytes"; | ||
|
|
||
| /// Returns if the key is a parameter key. | ||
| pub fn is_parameter_key(key: &Key) -> bool { | ||
|
|
@@ -20,10 +21,19 @@ pub fn is_parameter_key(key: &Key) -> bool { | |
|
|
||
| /// Returns if the key is a protocol parameter key. | ||
| pub fn is_protocol_parameter_key(key: &Key) -> bool { | ||
| // TODO: improve this code; use some kind of prefix | ||
| // tree to efficiently match `key` | ||
| is_epoch_duration_storage_key(key) | ||
| || is_max_expected_time_per_block_key(key) | ||
| || is_tx_whitelist_key(key) | ||
| || is_vp_whitelist_key(key) | ||
| || is_implicit_vp_key(key) | ||
| || is_epochs_per_year_key(key) | ||
| || is_pos_gain_p_key(key) | ||
| || is_pos_gain_d_key(key) | ||
| || is_staked_ratio_key(key) | ||
| || is_pos_inflation_amount_key(key) | ||
| || is_max_proposal_bytes_key(key) | ||
|
Comment on lines
+24
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oic the efficiency issue now. It would be good I guess if all protocol parameters were under some subtree e.g.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was playing around with trie codegen over the weekend for this specific use-case, but I still need to improve the generated code. https://gist.github.com/sug0/1bc632eb19ebdeb2d596c1617fba4138
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, we do have the same internal address as a prefix in each of these keys |
||
| } | ||
|
|
||
| /// Returns if the key is an epoch storage key. | ||
|
|
@@ -106,6 +116,14 @@ pub fn is_pos_inflation_amount_key(key: &Key) -> bool { | |
| ] if addr == &ADDRESS && pos_inflation_amount == POS_INFLATION_AMOUNT_KEY) | ||
| } | ||
|
|
||
| /// Returns if the key is the max proposal bytes key. | ||
| pub fn is_max_proposal_bytes_key(key: &Key) -> bool { | ||
| matches!(&key.segments[..], [ | ||
| DbKeySeg::AddressSeg(addr), | ||
| DbKeySeg::StringSeg(max_proposal_bytes), | ||
| ] if addr == &ADDRESS && max_proposal_bytes == MAX_PROPOSAL_BYTES_KEY) | ||
| } | ||
|
|
||
| /// Storage key used for epoch parameter. | ||
| pub fn get_epoch_duration_storage_key() -> Key { | ||
| Key { | ||
|
|
@@ -205,3 +223,13 @@ pub fn get_pos_inflation_amount_key() -> Key { | |
| ], | ||
| } | ||
| } | ||
|
|
||
| /// Storage key used for the max proposal bytes. | ||
| pub fn get_max_proposal_bytes_key() -> Key { | ||
| Key { | ||
| segments: vec![ | ||
| DbKeySeg::AddressSeg(ADDRESS), | ||
| DbKeySeg::StringSeg(MAX_PROPOSAL_BYTES_KEY.to_string()), | ||
| ], | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.