Skip to content
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

EVM: Make genesis.json field optional #2066

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/ain-evm/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,18 @@ pub fn new_block_from_json(path: PathBuf, state_root: H256) -> Result<BlockAny,
Ok(Block::new(
PartialHeader {
state_root,
beneficiary: genesis.coinbase,
timestamp: genesis.timestamp,
difficulty: genesis.difficulty,
extra_data: genesis.extra_data,
number: U256::zero(),
parent_hash: Default::default(),
timestamp: genesis.timestamp.unwrap_or_default().as_u64(),
beneficiary: genesis.coinbase.unwrap_or_default(),
difficulty: genesis.difficulty.unwrap_or_default(),
extra_data: genesis.extra_data.unwrap_or_default(),
parent_hash: genesis.parent_hash.unwrap_or_default(),
gas_limit: genesis.gas_limit.unwrap_or_default(),
mix_hash: genesis.mix_hash.unwrap_or_default(),
nonce: genesis.nonce.unwrap_or_default(),
receipts_root: Default::default(),
logs_bloom: Default::default(),
gas_limit: Default::default(),
gas_used: Default::default(),
mix_hash: Default::default(),
nonce: Default::default(),
},
Vec::new(),
Vec::new(),
Expand Down
16 changes: 9 additions & 7 deletions lib/ain-evm/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ pub struct Alloc {
#[serde(rename_all = "camelCase")]
pub struct GenesisData {
// config: Config,
pub coinbase: H160,
pub difficulty: U256,
pub extra_data: Vec<u8>,
pub gas_limit: U256,
pub nonce: H64,
pub timestamp: u64,
pub alloc: HashMap<H160, Alloc>,
pub coinbase: Option<H160>,
pub difficulty: Option<U256>,
pub extra_data: Option<Vec<u8>>,
pub gas_limit: Option<U256>,
pub nonce: Option<H64>,
pub timestamp: Option<U256>,
pub alloc: Option<HashMap<H160, Alloc>>,
pub parent_hash: Option<H256>,
pub mix_hash: Option<H256>,
}
36 changes: 19 additions & 17 deletions lib/ain-evm/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,26 @@ impl TrieDBStore {
let reader = BufReader::new(file);
let genesis: GenesisData = serde_json::from_reader(reader)?;

for (address, data) in genesis.alloc {
debug!("Setting data {:#?} for address {:x?}", data, address);
let basic = backend.basic(address);
if let Some(alloc) = genesis.alloc {
for (address, data) in alloc {
debug!("Setting data {:#?} for address {:x?}", data, address);
let basic = backend.basic(address);

let new_basic = Basic {
balance: data.balance,
..basic
};
backend
.apply(
address,
new_basic,
data.code,
data.storage.unwrap_or_default(),
false,
)
.expect("Could not set account data");
backend.commit();
let new_basic = Basic {
balance: data.balance,
..basic
};
backend
.apply(
address,
new_basic,
data.code,
data.storage.unwrap_or_default(),
false,
)
.expect("Could not set account data");
backend.commit();
}
}

let state_root = backend.commit();
Expand Down