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

Stateful Statediff: Implement Compressors' combination #1508

Open
Tracked by #1237 ...
kpp opened this issue Nov 22, 2024 · 0 comments
Open
Tracked by #1237 ...

Stateful Statediff: Implement Compressors' combination #1508

kpp opened this issue Nov 22, 2024 · 0 comments

Comments

@kpp
Copy link
Contributor

kpp commented Nov 22, 2024

We need this feature to merge two diffs into one. Before we implemented it like this:

pub fn merge_state_diffs(old_diff: StateDiff, new_diff: StateDiff) -> StateDiff {
    let mut new_diff_map = HashMap::<Vec<u8>, Option<Vec<u8>>>::from_iter(old_diff);

    new_diff_map.extend(new_diff);
    new_diff_map.into_iter().collect()
}

But now because of #1505 we have to implement the binary operation with multiple identities for Compressors:

For U256:

x + Add(0) = x
x + Sub(0) = x
Add(0) + x = x
Sub(0) + x = x

Transform(0) + x = x

_ + Transform(x) = Transform(x)
_ + NoCompression(x) = NoCompression(x)

Transform(x) + Sub/Add(y) = Compress(x+-y)
NoCompression(x) + Sub/Add(y) = Compress(x+-y)

Add(x) + Add(y) = Add(x + y) // handle overflow
Sub(x) + Sub(y) = Sub(x + y) // handle overflow
Add(x) + Sub(y) = Add(x - y) // handle overflow
Sub(x) + Add(y) = Sub(x - y) // handle overflow

Unfortunately for Add/Sub + Add/Sub we lose information of the original operands (lhs, rhs), so the result of combination of Add/Sub + Add/Sub may be suboptional in terms of diff size, because Compress(x, y) + Compress(a, b) may result in Transform too, not only in Add/Sub =(

TODO: implement combination for AddInlined: #1520

With #1511:

For code_hash B256:

x + Same = x
Same + x = x

_ + Removed = Removed
Removed + x = x

_ + Set(x) = Set(x)

Belongs to #1237

@kpp kpp changed the title Statefull Statediff: Implement Compressors' combination Stateful Statediff: Implement Compressors' combination Nov 22, 2024
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

No branches or pull requests

1 participant