Skip to content

Commit 297c9a9

Browse files
committed
wip: meta-corruption in attachable-subscription.test.ts
1 parent 6d8a7d5 commit 297c9a9

File tree

19 files changed

+335
-236
lines changed

19 files changed

+335
-236
lines changed

core/base/crdt-clock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class CRDTClockImpl {
6464
prevHead,
6565
updates,
6666
})) {
67-
return this.processUpdates(updatesAcc, all, prevHead);
67+
await this.processUpdates(updatesAcc, all, prevHead);
68+
return
6869
}
6970
}
7071

@@ -216,7 +217,7 @@ async function validateBlocks(logger: Logger, newHead: ClockHead, blockstore?: B
216217
newHead.map(async (cid) => {
217218
const got = await blockstore.get(cid);
218219
if (!got) {
219-
throw logger.Error().Str("cid", cid.toString()).Msg("int_applyHead missing block").AsError();
220+
throw logger.Error().Str("cid", cid.toString()).Msg("validateBlocks missing block").AsError();
220221
}
221222
});
222223
}

core/base/crdt-helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
PARAM,
4141
NotFoundError,
4242
} from "@fireproof/core-types-base";
43-
import { Logger } from "@adviser/cement";
43+
import { exception2Result, Logger } from "@adviser/cement";
4444
import { Link, Version } from "multiformats";
4545

4646
function toString<K extends IndexKeyType>(key: K, logger: Logger): string {
@@ -58,7 +58,11 @@ export function toPailFetcher(tblocks: BlockFetcher): PailBlockFetcher {
5858
get: async <T = unknown, C extends number = number, A extends number = number, V extends Version = 1>(
5959
link: Link<T, C, A, V>,
6060
) => {
61-
const block = await tblocks.get(link);
61+
const rBlock = await exception2Result(() => tblocks.get(link));
62+
if (rBlock.isErr()) {
63+
return undefined
64+
}
65+
const block = rBlock.Ok()
6266
return block
6367
? ({
6468
cid: block.cid,

core/base/database.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Attached,
2626
NotFoundError,
2727
QueryResult,
28+
isNotFoundError,
2829
} from "@fireproof/core-types-base";
2930
import { ensureLogger, makeName } from "@fireproof/core-runtime";
3031

@@ -78,7 +79,10 @@ export class DatabaseImpl implements Database {
7879
const { doc } = got;
7980
return { ...(doc as unknown as DocWithId<T>), _id: id };
8081
} catch (e) {
81-
throw new NotFoundError(`Not found: ${id} - ${e instanceof Error ? e.message : String(e)}`);
82+
if (isNotFoundError(e)) {
83+
throw e
84+
}
85+
throw this.logger.Error().Err(e).Msg("unexpect error").AsError()
8286
}
8387
}
8488

@@ -157,7 +161,6 @@ export class DatabaseImpl implements Database {
157161
if (typeof opts.limit === "number" && opts.limit >= 0) {
158162
rows = rows.slice(0, opts.limit);
159163
}
160-
161164
return { rows, clock: head, name: this.name };
162165
}
163166

core/blockstore/loader.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ export class Loader implements Loadable {
320320
this.blockstoreParent?.crdtParent?.ledgerParent?.name,
321321
);
322322
const local = this.attachedStores.local();
323-
// console.log("ready", this.id);
324323
this.metaStreamReader = local.active.meta.stream().getReader();
325-
// console.log("attach-local", local.active.car.url().pathname);
326324
await this.waitFirstMeta(this.metaStreamReader, local, { meta: this.ebOpts.meta, origin: local.active.car.url() });
327325
});
328326
}
@@ -765,7 +763,6 @@ export class Loader implements Loadable {
765763
}
766764

767765
async getBlock(cid: AnyLink): Promise<FPBlock | Falsy> {
768-
await this.ready();
769766
const got = this.cidCache.get(cid.toString());
770767
return got.value;
771768
}

core/blockstore/register-store-protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BuildURI, ResolveOnce, runtimeFn, URI } from "@adviser/cement";
22
import { SuperThis, PARAM } from "@fireproof/core-types-base";
3-
import { SerdeGateway, Gateway } from "@fireproof/core-types-blockstore";
3+
import { SerdeGateway, Gateway, FPEnvelope } from "@fireproof/core-types-blockstore";
44
import { MemoryGateway } from "@fireproof/core-gateways-memory";
55
import { FileGateway, FILESTORE_VERSION, sysFileSystemFactory } from "@fireproof/core-gateways-file";
66
import { DefSerdeGateway, INDEXEDDB_VERSION } from "@fireproof/core-gateways-base";
@@ -165,14 +165,14 @@ if (runtimeFn().isBrowser) {
165165
});
166166
}
167167

168-
const memory = new Map<string, Uint8Array>();
168+
const memory = new Map<string, FPEnvelope<unknown>>();
169169
registerStoreProtocol({
170170
protocol: "memory:",
171171
isDefault: false,
172172
defaultURI: () => {
173173
return BuildURI.from("memory://").pathname("ram").URI();
174174
},
175-
gateway: async (sthis) => {
175+
serdegateway: async (sthis) => {
176176
return new MemoryGateway(sthis, memory);
177177
},
178178
});

core/blockstore/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ export class MetaStoreImpl extends BaseStoreImpl implements MetaStore {
219219
// console.log(
220220
// "subscribe",
221221
// this.myId,
222-
// id.str,
223222
// this.url().pathname,
224223
// dbMetas.map((i) => i.cars.map((i) => i.toString())).flat(2),
225224
// );

core/gateways/base/fp-envelope-serialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function dbMetaEvent2Serialized(
5050
);
5151
}
5252

53-
function WALState2Serialized(sthis: SuperThis, wal: WALState): SerializedWAL {
53+
export function WALState2Serialized(sthis: SuperThis, wal: WALState): SerializedWAL {
5454
const serializedWAL: SerializedWAL = {
5555
fileOperations: wal.fileOperations.map((fop) => ({
5656
cid: fop.cid.toString(),

core/gateways/base/meta-key-hack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ export function addKeyToDbMetaEncoder(ctx: SerdeGatewayCtx, version: "v1" | "v2"
218218
}
219219

220220
export class AddKeyToDbMetaGateway implements SerdeGateway {
221-
private readonly sdGw: DefSerdeGateway;
221+
private readonly sdGw: SerdeGateway;
222222
readonly version: "v1" | "v2";
223-
constructor(gw: Gateway, version: "v1" | "v2") {
224-
this.sdGw = new DefSerdeGateway(gw);
223+
constructor(gw: SerdeGateway, version: "v1" | "v2") {
224+
this.sdGw = gw;
225225
this.version = version;
226226
}
227227

0 commit comments

Comments
 (0)