-
Notifications
You must be signed in to change notification settings - Fork 717
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
Blockchain/Ethash/Trie: remove level dependency from blockchain #2669
Changes from 4 commits
7c444cb
ec3a913
510b0c6
89f4741
6c9d0b1
98dd481
9c2e40d
29579c6
9810b92
a752c60
ab7fc78
c7ea77a
ccd8be3
abcd64d
d35960e
86cea58
521d164
2b1e081
238626d
e1faad9
c8d95df
aca0e1d
ef57f9b
b5fa536
7f1d7e0
7d807cf
cd0ab87
ac004af
b1346f2
d6d5387
16a5ab9
9d3e04b
1b5af37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DB, BatchDBOp } from '@ethereumjs/util' | ||
import { bytesToHex } from 'ethereum-cryptography/utils' | ||
|
||
export class MapDB<TKey extends Uint8Array | string, TValue extends Uint8Array | string> | ||
implements DB<TKey, TValue> | ||
{ | ||
_database: Map<TKey, TValue> | ||
|
||
constructor(database?: Map<TKey, TValue>) { | ||
this._database = database ?? new Map<TKey, TValue>() | ||
} | ||
|
||
async get(key: TKey): Promise<TValue | null> { | ||
const result = this._database.get(key) | ||
|
||
return result ?? null | ||
} | ||
|
||
async put(key: TKey, val: TValue): Promise<void> { | ||
this._database.set(key, val) | ||
} | ||
|
||
async del(key: TKey): Promise<void> { | ||
this._database.delete(key) | ||
} | ||
|
||
async batch(opStack: BatchDBOp<TKey, TValue>[]): Promise<void> { | ||
for (const op of opStack) { | ||
if (op.type === 'del') { | ||
await this.del(op.key) | ||
} | ||
|
||
if (op.type === 'put') { | ||
await this.put(op.key, op.value) | ||
} | ||
} | ||
} | ||
|
||
copy(): DB<TKey, TValue> { | ||
return new MapDB<TKey, TValue>(this._database) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this 1:1 the same as the Trie version? Wonder if we want to move this to Util as well? (Code) bloat seems limited to me, not such an extensive implementation. Would this make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it. I'll move it and adjust the imports accordingly. |
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.
memory-level
also already ready for removal here? Just asking.