-
Notifications
You must be signed in to change notification settings - Fork 33
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
DVT-1057 replace block data structure with LRU cache to fix memory leak #158
Conversation
cmd/monitor/monitor.go
Outdated
} | ||
return nil | ||
} | ||
const maxDataPoints = 1000 |
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.
I think we should put this value at the top of the file with a comment that explains exactly what it does. I can imagine myself checking the code in 3 months wondering what this is about :)
blms = append(blms, ethrpc.BatchElem{ | ||
Method: "eth_getBlockByNumber", | ||
Args: []interface{}{"0x" + i.Text(16), true}, | ||
Result: r, | ||
Error: err, | ||
Error: nil, |
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.
nice catch
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.
I didn't review all the code as there are many changes in monitor.go
but I went trough the code quickly. I tested and it looks good to me.
Side note: last PR, polycli monitor
was working fine for me and not crashing at all (which is weird) but not for others so maybe wait for another review. :)
added functions
isBlockInCache
: Determines if a given block number is already available in the LRU cache to avoid unnecessary network requests.checkAndFetchMissingBlocks
: Identifies blocks not present in the cache within a specified range and fetches them from the Ethereum network to fill the cache.removed
currIdx
,selectedBlock
,Max/MinBlockRetrieved
to clean up logic variablesfix after PR was reverted. Add back LRU lock when being read/written to prevent race condition.