@typeberry/lib 0.3.0 → 0.3.1

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/index.cjs CHANGED
@@ -11350,15 +11350,19 @@ class InMemorySerializedStates {
11350
11350
  async updateAndSetState(header, state, update) {
11351
11351
  const blake2b = this.blake2b;
11352
11352
  const updatedValues = serializeStateUpdate(this.spec, blake2b, update);
11353
- const { values, leafs } = updateLeafs(state.backend.leafs, blake2b, updatedValues);
11353
+ // make sure to clone the leafs before writing, since the collection is re-used.
11354
+ const newLeafs = SortedSet.fromSortedArray(leafComparator, state.backend.leafs.array);
11355
+ const { values, leafs } = updateLeafs(newLeafs, blake2b, updatedValues);
11356
+ // make sure to reset the cache and re-create leafsdb lookup
11357
+ state.updateBackend(LeafDb.fromLeaves(leafs, state.backend.db));
11354
11358
  // insert values to the db
11355
11359
  // valuesdb can be shared between all states because it's just
11356
11360
  // <valuehash> -> <value> mapping and existence is managed by trie leafs.
11357
11361
  for (const val of values) {
11358
11362
  this.valuesDb.set(val[0], val[1]);
11359
11363
  }
11360
- // make sure to clone the leafs before writing, since the collection is re-used.
11361
- this.db.set(header, SortedSet.fromSortedArray(leafComparator, leafs.slice()));
11364
+ // store new set of leaves
11365
+ this.db.set(header, leafs);
11362
11366
  return Result$1.ok(OK);
11363
11367
  }
11364
11368
  getState(header) {
package/index.d.ts CHANGED
@@ -13131,7 +13131,11 @@ declare class InMemorySerializedStates implements StatesDb<SerializedState<LeafD
13131
13131
  ): Promise<Result$2<OK, StateUpdateError>> {
13132
13132
  const blake2b = this.blake2b;
13133
13133
  const updatedValues = serializeStateUpdate(this.spec, blake2b, update);
13134
- const { values, leafs } = updateLeafs(state.backend.leafs, blake2b, updatedValues);
13134
+ // make sure to clone the leafs before writing, since the collection is re-used.
13135
+ const newLeafs = SortedSet.fromSortedArray(leafComparator, state.backend.leafs.array);
13136
+ const { values, leafs } = updateLeafs(newLeafs, blake2b, updatedValues);
13137
+ // make sure to reset the cache and re-create leafsdb lookup
13138
+ state.updateBackend(LeafDb.fromLeaves(leafs, state.backend.db));
13135
13139
 
13136
13140
  // insert values to the db
13137
13141
  // valuesdb can be shared between all states because it's just
@@ -13140,8 +13144,8 @@ declare class InMemorySerializedStates implements StatesDb<SerializedState<LeafD
13140
13144
  this.valuesDb.set(val[0], val[1]);
13141
13145
  }
13142
13146
 
13143
- // make sure to clone the leafs before writing, since the collection is re-used.
13144
- this.db.set(header, SortedSet.fromSortedArray(leafComparator, leafs.slice()));
13147
+ // store new set of leaves
13148
+ this.db.set(header, leafs);
13145
13149
 
13146
13150
  return Result.ok(OK);
13147
13151
  }
package/index.js CHANGED
@@ -11347,15 +11347,19 @@ class InMemorySerializedStates {
11347
11347
  async updateAndSetState(header, state, update) {
11348
11348
  const blake2b = this.blake2b;
11349
11349
  const updatedValues = serializeStateUpdate(this.spec, blake2b, update);
11350
- const { values, leafs } = updateLeafs(state.backend.leafs, blake2b, updatedValues);
11350
+ // make sure to clone the leafs before writing, since the collection is re-used.
11351
+ const newLeafs = SortedSet.fromSortedArray(leafComparator, state.backend.leafs.array);
11352
+ const { values, leafs } = updateLeafs(newLeafs, blake2b, updatedValues);
11353
+ // make sure to reset the cache and re-create leafsdb lookup
11354
+ state.updateBackend(LeafDb.fromLeaves(leafs, state.backend.db));
11351
11355
  // insert values to the db
11352
11356
  // valuesdb can be shared between all states because it's just
11353
11357
  // <valuehash> -> <value> mapping and existence is managed by trie leafs.
11354
11358
  for (const val of values) {
11355
11359
  this.valuesDb.set(val[0], val[1]);
11356
11360
  }
11357
- // make sure to clone the leafs before writing, since the collection is re-used.
11358
- this.db.set(header, SortedSet.fromSortedArray(leafComparator, leafs.slice()));
11361
+ // store new set of leaves
11362
+ this.db.set(header, leafs);
11359
11363
  return Result$1.ok(OK);
11360
11364
  }
11361
11365
  getState(header) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",