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

Bonsai accounts don't have equals() or hashCode() implementations #7845

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

matthew1001
Copy link
Contributor

@matthew1001 matthew1001 commented Oct 31, 2024

PR description

Unlike StateTrieAccountValue, BonsaiAccount is missing overrides for equals() and hashCode(). This is causing unnecessary entries in the trie logs for accounts that have been loaded but which haven't changed.

An example is invoking a method that only emits an event but which doesn't update storage. The account is loaded, the method is invoked, but nothing in the account has changed. It is then (unnecessarily) recorded in the trie-log for that block.

Signed-off-by: Matthew Whitehead <[email protected]>
@garyschulte
Copy link
Contributor

garyschulte commented Oct 31, 2024

We might actually rely on this unintended behavior for linea-shomei zk-trielog plugin. The primary difference between the TrieLogFactoryImpl and ZkTrieLogFactory implementation is that we add block number and zero reads to the trielog. But the zk state needs to know about updates and reads.

The value of having reads in the trielogs goes beyond just having a diff to apply, but rather is a log of all state access as well as modifications. Incidentally, this is useful for historical block tracing (very cheap historical/archive worldstate).

I don't know that adding equals and hashCode implementations will break this. Before we merge we should probably either assert that either this doesn't break anything or make explicit provision for persisting reads (and zero reads) if we are relying on unintended consequences of not having these methods for the zk trielog factory impl
@matkt for visibility

@@ -173,6 +173,22 @@ public String toString() {
+ '}';
}

@Override
public boolean equals(final Object o) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move as much of this up into DiffBasedAccount as possible so that other implementations inherit this (like Verkle). perhaps implement equals in DiffBasedAccount and delegate to an abstract method that implementations are forced to provide.

@matthew1001
Copy link
Contributor Author

matthew1001 commented Nov 1, 2024

Thanks for the comments @garyschulte I did wonder if the existing behaviour was in any way intentional.

In the case I've given in the PR description, there isn't even a state access, just an event. I'm not sure how realistic that is in the real world but it does need considering in terms of whether we want try logs for those types of invocation.

If the answer is "this is intentional/needed/useful" then I'm happy to close the PR with that explanation. I think I'll need to take your call on whether that's the case?

@matkt
Copy link
Contributor

matkt commented Nov 4, 2024

It's something we saw while coding Verkle, but we decided not to include it for now until we have time to test that it won't have any side effects on the trielog shipping part. I think before we merge it, we will need to conduct some tests. We need to be sure about these kinds of things to avoid consensus problems as well. Because an account that seems identical, is it really? Since BonsaiAccount inherits from DiffBasedAccount, which has a list of updatedStorage. I don't think we update the stateroot directly when we update this map. So, two accounts can seem identical without actually being so. Maybe it’s fine, but I haven’t had time to verify. I think it will take time to ensure that this modification is safe.

Copy link
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

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

we need more tests around trielog shipping and consensus parts before merge

@matthew1001
Copy link
Contributor Author

I've addressed the code comment re. moving most of the equals() implementation into DiffBaseAccount. Regarding any additional testing required to prove that the change hasn't regressed anything or caused problems for verkle implementation, I think I'll need to wait for feedback from @matkt

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.

3 participants