Skip to content

Commit 346db2e

Browse files
refactor(shared-log): remove persistCoordinate hash guard fallback
1 parent 1c1086c commit 346db2e

File tree

2 files changed

+9
-54
lines changed

2 files changed

+9
-54
lines changed

packages/programs/data/shared-log/src/index.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,27 +4498,7 @@ export class SharedLog<
44984498
return; // no change
44994499
}
45004500

4501-
const entryHash = (properties.entry as any)?.hash;
4502-
if (typeof entryHash !== "string" || entryHash.length === 0) {
4503-
warn("Skipping persistCoordinate for entry without hash");
4504-
return;
4505-
}
4506-
4507-
let cidObject: ReturnType<typeof cidifyString>;
4508-
try {
4509-
cidObject = cidifyString(entryHash);
4510-
} catch (error) {
4511-
warn(
4512-
`Skipping persistCoordinate for invalid hash '${entryHash}': ${
4513-
(error as any)?.message ?? error
4514-
}`,
4515-
);
4516-
return;
4517-
}
4518-
if (!cidObject?.multihash?.digest) {
4519-
warn(`Skipping persistCoordinate for entry '${entryHash}' without digest`);
4520-
return;
4521-
}
4501+
const cidObject = cidifyString(properties.entry.hash);
45224502
const hashNumber = this.indexableDomain.numbers.bytesToNumber(
45234503
cidObject.multihash.digest,
45244504
);
@@ -4528,19 +4508,22 @@ export class SharedLog<
45284508
assignedToRangeBoundary,
45294509
coordinates: properties.coordinates,
45304510
meta: properties.entry.meta,
4531-
hash: entryHash,
4511+
hash: properties.entry.hash,
45324512
hashNumber,
45334513
}),
45344514
);
45354515

45364516
for (const coordinate of properties.coordinates) {
4537-
this.coordinateToHash.add(coordinate, entryHash);
4517+
this.coordinateToHash.add(coordinate, properties.entry.hash);
45384518
}
45394519

4540-
const next = properties.entry.meta?.next ?? [];
4541-
if (next.length > 0) {
4520+
if (properties.entry.meta.next.length > 0) {
45424521
await this.entryCoordinatesIndex.del({
4543-
query: new Or(next.map((x) => new StringMatch({ key: "hash", value: x }))),
4522+
query: new Or(
4523+
properties.entry.meta.next.map(
4524+
(x) => new StringMatch({ key: "hash", value: x }),
4525+
),
4526+
),
45444527
});
45454528
}
45464529
}

packages/programs/data/shared-log/test/wait-for-replicator.spec.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,4 @@ describe("waitForReplicator", () => {
8585
}
8686
});
8787

88-
it("ignores persistCoordinate for missing or invalid hashes", async () => {
89-
session = await TestSession.connected(1);
90-
db = await session.peers[0].open(new EventStore<string, any>(), {
91-
args: {
92-
timeUntilRoleMaturity: 0,
93-
},
94-
});
95-
96-
const persistCoordinate = (db.log as any).persistCoordinate.bind(db.log);
97-
98-
await expect(
99-
persistCoordinate({
100-
coordinates: [0n],
101-
entry: { hash: undefined, meta: { next: [] } },
102-
leaders: new Map(),
103-
replicas: 1,
104-
}),
105-
).to.not.be.rejected;
106-
107-
await expect(
108-
persistCoordinate({
109-
coordinates: [0n],
110-
entry: { hash: "not-a-cid", meta: { next: [] } },
111-
leaders: new Map(),
112-
replicas: 1,
113-
}),
114-
).to.not.be.rejected;
115-
});
11688
});

0 commit comments

Comments
 (0)