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

[Proposal] Update finalize_root derivation #1965

Draft
wants to merge 4 commits into
base: testnet3
Choose a base branch
from

Conversation

raychu86
Copy link
Contributor

@raychu86 raychu86 commented Sep 8, 2023

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 the FinalizeStore atomic_write_batch instead. We simply hash it to construct the new finalize_root (which can be renamed as it is no longer a root).

The finalize root is now derived when VM::speculate or VM::finalize is called, instead of being derived from the FinalizeOperation state in Transactions, which means we can safely remove FinalizeOperations 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

macro_rules! process_map {
($map:expr, $result:expr) => {
for (key, value) in $map.iter_pending() {
$result.extend(key.to_bytes_le()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result.extend(key.to_bytes_le()?);
key.write_le(&mut $result)?;

match value {
Some(value) => {
$result.push(1u8);
$result.extend(value.to_bytes_le()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result.extend(key.to_bytes_le()?);
key.write_le(&mut $result)?;

match value {
Some(value) => {
$result.push(1u8);
$result.extend(value.to_bytes_le()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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()?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants