Skip to content

Commit

Permalink
fix: same to te/gc_investigate_4 but do not add misc change
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jun 28, 2024
1 parent ab76885 commit 7372a7b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 31 deletions.
7 changes: 1 addition & 6 deletions packages/ssz/src/viewDU/arrayComposite.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
getNodeAtDepth,
getNodesAtDepth,
Node,
setNodesAtDepth,
} from "@chainsafe/persistent-merkle-tree";
import {getNodeAtDepth, getNodesAtDepth, Node, setNodesAtDepth} from "@chainsafe/persistent-merkle-tree";
import {ValueOf} from "../type/abstract";
import {CompositeType, CompositeView, CompositeViewDU} from "../type/composite";
import {ArrayCompositeType} from "../view/arrayComposite";
Expand Down
5 changes: 1 addition & 4 deletions packages/ssz/src/viewDU/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ class ContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> extends
* Same method to `type/container.ts` that call ViewDU.serializeToBytes() of internal fields.
*/
serializeToBytes(output: ByteViews, offset: number): number {
// it's the responsibility of consumer to call commit() before calling this method
if (this.nodesChanged.size !== 0 || this.viewsChanged.size !== 0) {
throw Error(`Must commit changes before serializeToBytes(Uint8Array(${output.uint8Array.length}, ${offset})`);
}
this.commit();

let fixedIndex = offset;
let variableIndex = offset + this.type.fixedEnd;
Expand Down
4 changes: 0 additions & 4 deletions packages/ssz/src/viewDU/containerNodeStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ class ContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> extends

commit(): void {
if (this.valueChanged === null) {
// this does not suppor batch hash
// this._rootNode.root;
return;
}

const value = this.valueChanged;
this.valueChanged = null;

this._rootNode = this.type.value_toTree(value) as BranchNodeStruct<ValueOfFields<Fields>>;
// this does not suppor batch hash
// this._rootNode.root;
}

protected clearCache(): void {
Expand Down
13 changes: 4 additions & 9 deletions packages/ssz/src/viewDU/listBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ export class ListBasicTreeViewDU<ElementType extends BasicType<unknown>> extends
*/
sliceTo(index: number): this {
if (index < 0) {
throw Error(`Does not support sliceTo() with negative index ${index}`);
throw new Error(`Does not support sliceTo() with negative index ${index}`);
}

// it's the responsibility of consumer to call commit() before calling this method
if (this.nodesChanged.size > 0) {
throw Error(`Must commit changes before sliceTo(${index})`);
}
// Commit before getting rootNode to ensure all pending data is in the rootNode
this.commit();

// All nodes beyond length are already zero
if (index >= this._length - 1) {
Expand Down Expand Up @@ -86,10 +84,7 @@ export class ListBasicTreeViewDU<ElementType extends BasicType<unknown>> extends
* Same method to `type/listBasic.ts` leveraging cached nodes.
*/
serializeToBytes(output: ByteViews, offset: number): number {
// it's the responsibility of consumer to call commit() before calling this method
if (this.nodesChanged.size > 0) {
throw Error(`Must commit changes before serializeToBytes(Uint8Array(${output.uint8Array.length}), ${offset})`);
}
this.commit();
const {nodes, nodesPopulated} = this.cache;
const chunksNode = this.type.tree_getChunksNode(this._rootNode);
return tree_serializeToBytesArrayBasic(
Expand Down
11 changes: 3 additions & 8 deletions packages/ssz/src/viewDU/listComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ export class ListCompositeTreeViewDU<
* Note: Using index = -1, returns an empty list of length 0.
*/
sliceTo(index: number): this {
// it's the responsibility of consumer to call commit() before calling this method
if (this.viewsChanged.size > 0) {
throw Error(`Must commit changes before sliceTo(${index})`);
}
// Commit before getting rootNode to ensure all pending data is in the rootNode
this.commit();
const rootNode = this._rootNode;
const length = this._length;

Expand Down Expand Up @@ -113,10 +111,7 @@ export class ListCompositeTreeViewDU<
* Same method to `type/listComposite.ts` leveraging cached nodes.
*/
serializeToBytes(output: ByteViews, offset: number): number {
// it's the responsibility of consumer to call commit() before calling this method
if (this.viewsChanged.size > 0) {
throw Error(`Must commit changes before serializeToBytes(Uint8Array(${output.uint8Array.length}, ${offset})`);
}
this.commit();
this.populateAllNodes();
const chunksNode = this.type.tree_getChunksNode(this._rootNode);
return tree_serializeToBytesArrayComposite(
Expand Down

0 comments on commit 7372a7b

Please sign in to comment.