-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Non-canonical state-change parameter #8406
Changes from 6 commits
8f5b89d
0b46a70
ec054db
fff42f2
891e633
5e2321d
e30f4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
//! Parameters for a block chain. | ||
|
||
use std::collections::BTreeMap; | ||
use std::collections::{BTreeMap, HashMap}; | ||
use std::io::Read; | ||
use std::path::Path; | ||
use std::sync::Arc; | ||
|
@@ -53,6 +53,39 @@ fn fmt_err<F: ::std::fmt::Display>(f: F) -> String { | |
format!("Spec json is invalid: {}", f) | ||
} | ||
|
||
/// Ireegular state change accounts applied at specific blocks. | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum IrregularStateChangeAccount { | ||
/// Force setting values on an account. | ||
Set { | ||
/// New nonce forced setting. | ||
nonce: Option<U256>, | ||
/// New code forced setting. | ||
code: Option<Bytes>, | ||
/// New balance forced setting. | ||
balance: Option<U256>, | ||
/// Storage values forced setting. | ||
storage: Vec<(H256, H256)>, | ||
} | ||
} | ||
|
||
impl From<::ethjson::spec::IrregularStateChangeAccount> for IrregularStateChangeAccount { | ||
fn from(p: ::ethjson::spec::IrregularStateChangeAccount) -> Self { | ||
match p { | ||
::ethjson::spec::IrregularStateChangeAccount::Set { | ||
nonce, code, balance, storage | ||
} => { | ||
IrregularStateChangeAccount::Set { | ||
nonce: nonce.map(Into::into), | ||
code: code.map(Into::into), | ||
balance: balance.map(Into::into), | ||
storage: storage.unwrap_or_default().into_iter().map(|(k, v)| (k.into(), v.into())).collect(), | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
|
||
/// Parameters common to ethereum-like blockchains. | ||
/// NOTE: when adding bugfix hard-fork parameters, | ||
/// add to `contains_bugfix_hard_fork` | ||
|
@@ -123,6 +156,8 @@ pub struct CommonParams { | |
pub max_code_size_transition: BlockNumber, | ||
/// Transaction permission managing contract address. | ||
pub transaction_permission_contract: Option<Address>, | ||
/// Irregular state change list. | ||
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. Would be good to mention that the irregular state changes are applied at the very beginning of the block to avoid confusion. |
||
pub irregular_state_changes: HashMap<u64, Vec<(Address, IrregularStateChangeAccount)>>, | ||
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. What does |
||
} | ||
|
||
impl CommonParams { | ||
|
@@ -244,6 +279,7 @@ impl From<ethjson::spec::Params> for CommonParams { | |
BlockNumber::max_value(), | ||
Into::into | ||
), | ||
irregular_state_changes: p.irregular_state_changes.unwrap_or_else(HashMap::new).into_iter().map(|(k, v)| (k.into(), v.into_iter().map(|(k, v)| (k.into(), v.into())).collect())).collect(), | ||
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. Perhaps split it into multiple lines for readability? p.irregular_state_changes
.unwrap_or_else(HashMap::new)
.into_iter()
.map(|(k, v)| (
k.into(),
v.into_iter().map(|(k, v)| (k.into(), v.into())).collect()
))
.collect() |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -652,6 +652,12 @@ impl<B: Backend> State<B> { | |
Ok(()) | ||
} | ||
|
||
/// Directly set the balance of account `a`. | ||
pub fn set_balance(&mut self, a: &Address, bala: &U256) -> trie::Result<()> { | ||
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.
|
||
self.require(a, false)?.set_balance(bala); | ||
Ok(()) | ||
} | ||
|
||
/// Subtracts `by` from the balance of `from` and adds it to that of `to`. | ||
pub fn transfer_balance(&mut self, from: &Address, to: &Address, by: &U256, mut cleanup_mode: CleanupMode) -> trie::Result<()> { | ||
self.sub_balance(from, by, &mut cleanup_mode)?; | ||
|
@@ -664,6 +670,11 @@ impl<B: Backend> State<B> { | |
self.require(a, false).map(|mut x| x.inc_nonce()) | ||
} | ||
|
||
/// Set the nonce of an account. | ||
pub fn set_nonce(&mut self, a: &Address, nonce: &U256) -> trie::Result<()> { | ||
self.require(a, false).map(|mut x| x.set_nonce(nonce)) | ||
} | ||
|
||
/// Mutate storage of account `a` so that it is `value` for `key`. | ||
pub fn set_storage(&mut self, a: &Address, key: H256, value: H256) -> trie::Result<()> { | ||
trace!(target: "state", "set_storage({}:{:x} to {:x})", a, key, value); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,35 @@ | |
|
||
//! Spec params deserialization. | ||
|
||
use std::collections::HashMap; | ||
use uint::{self, Uint}; | ||
use hash::{H256, Address}; | ||
use bytes::Bytes; | ||
|
||
/// See main CommonParams docs. | ||
#[derive(Clone, Debug, PartialEq, Deserialize)] | ||
pub enum IrregularStateChangeAccount { | ||
/// See main CommonParams docs. | ||
#[serde(rename="set")] | ||
Set { | ||
/// See main CommonParams docs. | ||
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. Not super clear from |
||
#[serde(rename="nonce")] | ||
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 don't think the renames are actually required. |
||
nonce: Option<Uint>, | ||
|
||
/// See main CommonParams docs. | ||
#[serde(rename="code")] | ||
code: Option<Bytes>, | ||
|
||
/// See main CommonParams docs. | ||
#[serde(rename="balance")] | ||
balance: Option<Uint>, | ||
|
||
/// See main CommonParams docs. | ||
#[serde(rename="storage")] | ||
storage: Option<HashMap<H256, H256>>, | ||
} | ||
} | ||
|
||
/// Spec params. | ||
#[derive(Debug, PartialEq, Deserialize)] | ||
pub struct Params { | ||
|
@@ -122,6 +147,9 @@ pub struct Params { | |
/// Wasm activation block height, if not activated from start | ||
#[serde(rename="wasmActivationTransition")] | ||
pub wasm_activation_transition: Option<Uint>, | ||
/// See main CommonParams docs. | ||
#[serde(rename="irregularStateChanges")] | ||
pub irregular_state_changes: Option<HashMap<Uint, HashMap<Address, IrregularStateChangeAccount>>>, | ||
} | ||
|
||
#[cfg(test)] | ||
|
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.
This block does not depend on
ethash_params
, does it have to be inside that particularif
? If yes could you please add a comment explaining that.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.
definitely should be moved outside. other engines might have irregular state changes too.