-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Proposal] Update finalize_root
derivation
#1965
base: testnet3
Are you sure you want to change the base?
Conversation
macro_rules! process_map { | ||
($map:expr, $result:expr) => { | ||
for (key, value) in $map.iter_pending() { | ||
$result.extend(key.to_bytes_le()?); |
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.
$result.extend(key.to_bytes_le()?); | |
key.write_le(&mut $result)?; |
match value { | ||
Some(value) => { | ||
$result.push(1u8); | ||
$result.extend(value.to_bytes_le()?); |
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.
$result.extend(value.to_bytes_le()?); | |
value.write_le(&mut $result)?; |
macro_rules! process_map { | ||
($map:expr, $result:expr) => { | ||
for (key, value) in $map.iter_pending() { | ||
$result.extend(key.to_bytes_le()?); |
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.
$result.extend(key.to_bytes_le()?); | |
key.write_le(&mut $result)?; |
match value { | ||
Some(value) => { | ||
$result.push(1u8); | ||
$result.extend(value.to_bytes_le()?); |
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.
$result.extend(value.to_bytes_le()?); | |
value.write_le(&mut $result)?; |
macro_rules! process_map_nested { | ||
($map:expr, $result:expr) => { | ||
for (key, value) in $map.iter_pending() { | ||
$result.extend(key.to_bytes_le()?); |
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.
$result.extend(key.to_bytes_le()?); | |
key.write_le(&mut $result)?; |
$result.push(1u8); | ||
(values.len() as u32).write_le(&mut $result)?; | ||
for v in values.iter() { | ||
$result.extend(v.to_bytes_le()?); |
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.
$result.extend(v.to_bytes_le()?); | |
v.write_le(&mut $result)?; |
self.atomic_speculate(state, ratifications, solutions, transactions)?; | ||
|
||
// TODO (raychu86): Optimize this. We can use any hash function. | ||
// Compute the finalize digest. | ||
let input = write_batch.iter().flat_map(|b| b.to_bits_le()).collect::<Vec<_>>(); |
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.
let input = write_batch.iter().flat_map(|b| b.to_bits_le()).collect::<Vec<_>>(); | |
let mut input = Vec::new(); | |
for b in write_batch.iter() { | |
b.write_bits_le(&mut input); | |
} |
|
||
// TODO (raychu86): Optimize this. We can use any hash function. | ||
// Compute the finalize digest. | ||
let input = write_batch.iter().flat_map(|b| b.to_bits_le()).collect::<Vec<_>>(); |
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.
let input = write_batch.iter().flat_map(|b| b.to_bits_le()).collect::<Vec<_>>(); | |
let mut input = Vec::new(); | |
for b in write_batch.iter() { | |
b.write_bits_le(&mut input); | |
} |
Motivation
This PR explores a new method of deriving the finalize root. Instead of using
FinalizeOperations
to create a tree and find the root, we use theFinalizeStore
atomic_write_batch
instead. We simply hash it to construct the newfinalize_root
(which can be renamed as it is no longer a root).The finalize root is now derived when
VM::speculate
orVM::finalize
is called, instead of being derived from theFinalizeOperation
state inTransactions
, which means we can safely removeFinalizeOperations
entirely if desired.Note: The
FinalizeOperations
have not been removed in this proposal, but will be removed if we decide to go down this route.TODO: Resample genesis block