@typeberry/jam 0.3.0-bf18f09 → 0.3.0-fd0344b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap-importer.mjs +1 -8
- package/bootstrap-importer.mjs.map +1 -1
- package/index.js +14 -12
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -36587,15 +36587,19 @@ class InMemorySerializedStates {
|
|
|
36587
36587
|
async updateAndSetState(header, state, update) {
|
|
36588
36588
|
const blake2b = this.blake2b;
|
|
36589
36589
|
const updatedValues = serializeStateUpdate(this.spec, blake2b, update);
|
|
36590
|
-
|
|
36590
|
+
// make sure to clone the leafs before writing, since the collection is re-used.
|
|
36591
|
+
const newLeafs = SortedSet.fromSortedArray(leafComparator, state.backend.leafs.array);
|
|
36592
|
+
const { values, leafs } = updateLeafs(newLeafs, blake2b, updatedValues);
|
|
36593
|
+
// make sure to reset the cache and re-create leafsdb lookup
|
|
36594
|
+
state.updateBackend(LeafDb.fromLeaves(leafs, state.backend.db));
|
|
36591
36595
|
// insert values to the db
|
|
36592
36596
|
// valuesdb can be shared between all states because it's just
|
|
36593
36597
|
// <valuehash> -> <value> mapping and existence is managed by trie leafs.
|
|
36594
36598
|
for (const val of values) {
|
|
36595
36599
|
this.valuesDb.set(val[0], val[1]);
|
|
36596
36600
|
}
|
|
36597
|
-
//
|
|
36598
|
-
this.db.set(header,
|
|
36601
|
+
// store new set of leaves
|
|
36602
|
+
this.db.set(header, leafs);
|
|
36599
36603
|
return result_Result.ok(result_OK);
|
|
36600
36604
|
}
|
|
36601
36605
|
getState(header) {
|
|
@@ -36884,7 +36888,12 @@ class LmdbStates {
|
|
|
36884
36888
|
async updateAndSetState(headerHash, state, update) {
|
|
36885
36889
|
const updatedValues = serializeStateUpdate(this.spec, this.blake2b, update);
|
|
36886
36890
|
// and finally we insert new values and store leaves in the DB.
|
|
36887
|
-
|
|
36891
|
+
const res = await this.updateAndCommit(headerHash, state.backend.leafs, updatedValues);
|
|
36892
|
+
if (res.isOk) {
|
|
36893
|
+
// update the internal backend with new leaves.
|
|
36894
|
+
state.updateBackend(LeafDb.fromLeaves(state.backend.leafs, state.backend.db));
|
|
36895
|
+
}
|
|
36896
|
+
return res;
|
|
36888
36897
|
}
|
|
36889
36898
|
async getStateRoot(state) {
|
|
36890
36899
|
return state.backend.getStateRoot(this.blake2b);
|
|
@@ -49690,13 +49699,6 @@ class Importer {
|
|
|
49690
49699
|
logger.error `🧱 Unable to update state: ${result_resultToString(updateResult)}`;
|
|
49691
49700
|
return importerError(ImporterErrorKind.Update, updateResult);
|
|
49692
49701
|
}
|
|
49693
|
-
const newState = this.states.getState(headerHash);
|
|
49694
|
-
if (newState === null) {
|
|
49695
|
-
throw new Error("Freshly updated state not in the DB?");
|
|
49696
|
-
}
|
|
49697
|
-
// TODO [ToDr] This is a temporary measure. We should rather read
|
|
49698
|
-
// the state of a parent block to support forks and create a fresh STF.
|
|
49699
|
-
this.state.updateBackend(newState.backend);
|
|
49700
49702
|
this.prepareForNextEpoch();
|
|
49701
49703
|
this.currentHash = headerHash;
|
|
49702
49704
|
logger.log `${timerState()}`;
|
|
@@ -49705,7 +49707,7 @@ class Importer {
|
|
|
49705
49707
|
const writeBlocks = this.blocks.insertBlock(new hash_WithHash(headerHash, block));
|
|
49706
49708
|
// Computation of the state root may happen asynchronously,
|
|
49707
49709
|
// but we still need to wait for it before next block can be imported
|
|
49708
|
-
const stateRoot = await this.states.getStateRoot(
|
|
49710
|
+
const stateRoot = await this.states.getStateRoot(this.state);
|
|
49709
49711
|
logger.log `🧱 Storing post-state-root for ${headerHash}: ${stateRoot}.`;
|
|
49710
49712
|
const writeStateRoot = this.blocks.setPostStateRoot(headerHash, stateRoot);
|
|
49711
49713
|
await Promise.all([writeBlocks, writeStateRoot]);
|