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

Buffer to Uint8Array cleanup #2607

Merged
merged 19 commits into from
Apr 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correctly parse heads from DB
  • Loading branch information
acolytec3 committed Mar 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f16ebde3efb62a3ed0187c73bacd61f1321628ae
7 changes: 5 additions & 2 deletions packages/blockchain/src/db/manager.ts
Original file line number Diff line number Diff line change
@@ -65,7 +65,11 @@ export class DBManager {
async getHeads(): Promise<{ [key: string]: Uint8Array }> {
const heads = await this.get(DBTarget.Heads)
for (const key of Object.keys(heads)) {
heads[key] = Uint8Array.from(heads[key])
// DB incorrectly stores the `uint8Array` representation of each head hash
// as a JSON object of key value pairs where the key is the array index
// and the value is the uint8 from that index of the original array
// so we convert it back to a Uint8Array before storing the heads
heads[key] = Uint8Array.from(Object.values(heads[key]))
}
return heads
}
@@ -236,7 +240,6 @@ export class DBManager {
const convertedOps: DBOpData[] = ops.map((op) => op.baseDBOp)
// update the current cache for each operation
ops.map((op) => op.updateCache(this._cache))

return this._db.batch(convertedOps as any)
}
}