-
Notifications
You must be signed in to change notification settings - Fork 71
Adding session use for RPC, along with shared cache and fixed Latest Block #861
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
Conversation
592984f to
22f3de4
Compare
98ed1f7 to
fece723
Compare
Update cabal too Updating Latest correctly
fece723 to
41dcea7
Compare
blishko
left a comment
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.
Looks good!
I am just wondering if we can push the creation of the session a bit down the pipeline.
It seems we need to create the session in too many places right now.
No idea why it was changed
blishko
left a comment
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.
LGTM!
Description
This PR changes the way we do RPC. Basically, we have a mutable cache that is inside Session. We also have a mutable latestBlockNum. The latestBlockNum is updated only ONCE, from Nothing to Just, the first time something with
Latestis fetched. This way,Latestwill become a fixed block, and from then on, we use that instead ofLatest. The cache is such that we keep everything there that we ever fetched.Cache: due to threads asking for the same data, it is possible that two threads both fetch the same data. However, since the blockchain is immutable, they'd get the same data back, so they'd store the same thing in the cache. So there is no hazard of concurrency, worst case we fetch the same data twice.
The only issue that can arise is that two threads could potentially ask for the Latest, and they get different values back. However, for
test, the first thing we do normally is to:rpcDat = Fetch.mkRpcInfo blockUrlInfo mockDatabefore launching any symbolic execution. So at that point, theLatestwill be replaced with a value. Forrunthere is no issue, as it's not multi-threaded. Forsymbolic, first thing we do isJust url -> liftIO $ Fetch.fetchBlockWithSession conf sess block urlso that's also OK. For equivalence, block number does not matter.Old cache in EVM.hs
This as the old cache in EVM.hs:
But that cache was PER VM:
So each thread would inherit their parent's cache:
A -> (B,C)fork A into B and C. B and C inherit A's cache. Now:B->(D,F)Another fork. B into D, F. Now, if C fetched some data, D would have no idea, and would re-fetch it. And F would re-fetch it. Actually, also B would re-fetch it. etc. So it's a huge mess, and tons of re-fetches.Another annoyance was that this "cache" was abused to store the paths visited, which were then used to detect loops:
This had nothing to do with a cache. It was simply tracking where we have been. This
cache.pathhas now been renamedpathsVisited.Small Changes
sess :: NetSession.SessioninsideSession. This reduces latency and pressure on the RPC host.Overall effect
Overall, this PR should make working with RPC a lot faster. It should also make sure we don't overwhelm the RPC host and get data faster.
Fixes #528
Checklist