Skip to content

Commit

Permalink
Use hashed tries
Browse files Browse the repository at this point in the history
  • Loading branch information
scorbajio committed Aug 6, 2023
1 parent 7bf3148 commit d026655
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/client/src/sync/fetcher/accountfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ export class AccountFetcher extends Fetcher<JobTask, AccountData[], AccountData>
this.root = options.root
this.first = options.first
this.count = options.count ?? BigInt(2) ** BigInt(256) - this.first
this.codeTrie = new Trie({ useKeyHashing: true })
this.accountTrie = new Trie({ useKeyHashing: true })
this.codeTrie = new Trie({ useKeyHashing: false })
this.accountTrie = new Trie({ useKeyHashing: false })
this.accountToStorageTrie = new Map()

this.debug = createDebugLogger('client:AccountFetcher')
this.storageFetcher = new StorageFetcher({
config: this.config,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/sync/fetcher/bytecodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ByteCodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>
constructor(options: ByteCodeFetcherOptions) {
super(options)
this.hashes = options.hashes ?? []
this.trie = options.trie ?? new Trie({ useKeyHashing: true })
this.trie = options.trie ?? new Trie({ useKeyHashing: false })
this.debug = createDebugLogger('client:ByteCodeFetcher')
if (this.hashes.length > 0) {
const fullJob = { task: { hashes: this.hashes } } as Job<JobTask, Uint8Array[], Uint8Array>
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/sync/fetcher/storagefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class StorageFetcher extends Fetcher<JobTask, StorageData[][], StorageDat
const accountHash = result.requests[i].accountHash
const storageTrie =
this.accountToStorageTrie.get(bytesToUnprefixedHex(accountHash)) ??
new Trie({ useKeyHashing: true })
new Trie({ useKeyHashing: false })
for (const slot of slotArray as any) {
slotCount++
void storageTrie.put(slot.hash, slot.body)
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/sync/fetcher/trienodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class TrieNodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>
this.pathToNodeRequestData = new OrderedMap<string, NodeRequestData>()
this.requestedNodeToPath = new Map<string, string>()
this.fetchedAccountNodes = new Map<string, FetchedNodeData>()
this.accountTrie = options.accountTrie ?? new Trie({ useKeyHashing: true })
this.codeTrie = options.codeTrie ?? new Trie({ useKeyHashing: true })
this.accountTrie = options.accountTrie ?? new Trie({ useKeyHashing: false })
this.codeTrie = options.codeTrie ?? new Trie({ useKeyHashing: false })
this.accountToStorageTrie = options.accountToStorageTrie ?? new Map<String, Trie>()
this.nodeCount = 0
this.debug = createDebugLogger('client:TrieNodeFetcher')
Expand Down Expand Up @@ -323,7 +323,7 @@ export class TrieNodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>

// add storage data for account if it has fetched nodes
// TODO figure out what the key should be for mapping accounts to storage tries
const storageTrie = new Trie({ useKeyHashing: true })
const storageTrie = new Trie({ useKeyHashing: false })
const storageTrieOps: BatchDBOp[] = []
if (pathToStorageNode !== undefined && pathToStorageNode.size > 0) {
for (const [path, data] of pathToStorageNode) {
Expand Down

0 comments on commit d026655

Please sign in to comment.