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

History: in-memory blockhash index #626

Merged
merged 8 commits into from
Sep 18, 2024
Merged

History: in-memory blockhash index #626

merged 8 commits into from
Sep 18, 2024

Conversation

ScottyPoi
Copy link
Collaborator

Refactors the BlockIndex into an in-memory attribute of the HistoryNetwork class.

  1. Removes async blockIndex getter/setter from BaseNetwork
  2. Adds this.blockHashIndex to HistoryNetwork
  3. Moves hashToNumber and numberToHash helpers to HistoryNetwork
  4. Makes helper functions syncronous
  5. In history.indexBlockHash(...), updated index is also stored in DB
  6. Stored block index is retrieved from DB during client.start() to set history.blockHashIndex

history.blockHashIndex is type Map<string,string>

Map index entries stored in both directions (num > hash / hash > num)

blockNumber is 0x prefixed hex
blockHash is 0x prefixed hex

e.g.

 Map {
   "0x1" => "0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6",
   "0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6" => "0x1",
 }

Copy link
Collaborator

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM

@acolytec3 acolytec3 merged commit a25a873 into master Sep 18, 2024
4 checks passed
@acolytec3 acolytec3 deleted the memory-index branch September 18, 2024 19:28
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.

2 participants