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

Fixing vertex dependencies issue #247

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
52 changes: 38 additions & 14 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ function updateHandler(node: TopologyNode, data: Uint8Array) {
console.error("topology::node::updateHandler", "Object not found");
return false;
}
const _merge = () => {
object.merge(
updateMessage.vertices.map((v) => {
return {
hash: v.hash,
nodeId: v.nodeId,
operation: {
type: v.operation?.type ?? "",
value: v.operation?.value,
},
dependencies: v.dependencies,
};
}),
);
};

object.merge(
updateMessage.vertices.map((v) => {
return {
hash: v.hash,
nodeId: v.nodeId,
operation: {
type: v.operation?.type ?? "",
value: v.operation?.value,
},
dependencies: v.dependencies,
};
}),
);
try{
_merge();
}catch(err){
if (updateMessage.vertices.length === 0) {
return false;
} else {
const peerId = updateMessage.vertices[0].nodeId;
node.syncObject(object.id, peerId);
_merge();
}
}

node.objectStore.put(object.id, object);

return true;
Expand Down Expand Up @@ -173,7 +187,17 @@ function syncAcceptHandler(
});

if (vertices.length !== 0) {
object.merge(vertices);
try{
object.merge(vertices);
}catch(err){
node.syncObject(object.id, sender);
try{
object.merge(vertices);
}catch(err){
console.error("topology::node::syncAcceptHandler", "Error merging vertices", err);
return;
}
}
node.objectStore.put(object.id, object);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.3.0";
export const VERSION = "0.3.1";
3 changes: 1 addition & 2 deletions packages/object/src/hashgraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ export class HashGraph {
if (
!deps.every((dep) => this.forwardEdges.has(dep) || this.vertices.has(dep))
) {
console.error("Invalid dependency detected.");
return "";
throw new Error("Invalid dependency detected.");
elielnfinic marked this conversation as resolved.
Show resolved Hide resolved
}

const vertex: Vertex = {
Expand Down
Loading
Loading