Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Flexible roots #18

Closed
wants to merge 3 commits into from
Closed

Flexible roots #18

wants to merge 3 commits into from

Conversation

aakilfernandes
Copy link

@aakilfernandes aakilfernandes commented Dec 31, 2016

This makes two changes

  1. _findPath takes a root as second argument. This avoids the race condition where multiple gets/sets are taking place with changing roots

https://github.com/ethereumjs/merkle-patricia-tree/compare/getWithRoot?expand=1#diff-66120f21e6456d8c708592f111155feeR277

  1. Creates a public getWithRoot function that allows a custom root. This is necessary to fix a race condition in testRPC where the root is being manipulated

trufflesuite/ganache-cli-archive#234

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 87.46% when pulling 7dd851c on getWithRoot into 828febf on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 87.46% when pulling 7dd851c on getWithRoot into 828febf on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 87.46% when pulling c81da6e on getWithRoot into 828febf on master.

@benjamincburns
Copy link

@aakilfernandes - can you please update this to resolve the conflicts?

@jwasinger - is this repo under your purview? If so, I think this is a fairly important issue for the TestRPC, due to trufflesuite/ganache-cli-archive#234. It's especially bad because when this is happening we'll possibly return bad data rather than firing off an error.

@jwasinger
Copy link
Contributor

@benjamincburns yeah let me take a look to make sure I understand the changes here. An easy fix for this issue is to make a copy of the trie before doing operations on it.

There's overhead incurred but it should mitigate the issue.

@jwasinger
Copy link
Contributor

e.g.

let tmptrie = state.trie.copy()
tmptrie.root = someroot

// do stuff

@benjamincburns
Copy link

Thanks for the quick response! And yeah, that's likely what we'll do if these changes pose problems.

@benjamincburns
Copy link

@jwasinger it seems that .copy() doesn't do much.

Trie.prototype.copy = function () {
return new Trie(this.db, this.root)
}

@jwasinger
Copy link
Contributor

Okay that's even better. There is no actual data copying involved because the db backend is reused. I'd say based on that, we can close this issue and recommend that users utilize the code I posted above to enable concurrent access to the trie.

@benjamincburns
Copy link

benjamincburns commented Nov 8, 2017

@jwasinger is it better? Are there any operations performed by the VM involving the trie which aren't idempotent? For example, some operation which fails if some data already exists in the trie?

@ryanio
Copy link
Contributor

ryanio commented Apr 23, 2020

Okay that's even better. There is no actual data copying involved because the db backend is reused. I'd say based on that, we can close this issue and recommend that users utilize the code I posted above to enable concurrent access to the trie.

great, thanks :) i will close this PR then.

trie op race conditions should also be totally resolved with moving to sync with #113.

@ryanio ryanio closed this Apr 23, 2020
@benjamincburns
Copy link

@ryanio since #113 has been closed, should this be reopened?

@ryanio
Copy link
Contributor

ryanio commented May 17, 2020

@benjamincburns ah sorry about that. Would you not agree with this reply from @jwasinger:

I'd say based on that, we can close this issue and recommend that users utilize the code I posted above to enable concurrent access to the trie.

@benjamincburns
Copy link

I defer to @davidmurdoch, as he manages Ganache these days. I just was going through my (long list of rather old) notifications and noticed that this was closed in favor of another issue that had also been closed, and figured I should flag it.

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

Successfully merging this pull request may close these issues.

None yet

7 participants