Skip to content

Commit ccaa1be

Browse files
committedSep 24, 2024
feat: deleting instances/classes + extended test
1 parent 6403d34 commit ccaa1be

File tree

6 files changed

+232
-89
lines changed

6 files changed

+232
-89
lines changed
 

‎yarn-project/archiver/src/archiver/archiver.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ describe('Archiver', () => {
349349
// Should also see the block number be reduced
350350
latestBlockNum = await archiver.getBlockNumber();
351351
expect(latestBlockNum).toEqual(numL2BlocksInTest - 1);
352+
353+
const txHash = blocks[1].body.txEffects[0].txHash;
354+
expect(await archiver.getTxEffect(txHash)).resolves.toBeUndefined;
355+
expect(await archiver.getBlock(2)).resolves.toBeUndefined;
356+
357+
[LogType.NOTEENCRYPTED, LogType.ENCRYPTED, LogType.UNENCRYPTED].forEach(async t => {
358+
expect(await archiver.getLogs(2, 1, t)).toEqual([]);
359+
});
360+
361+
// The random blocks don't include contract instances nor classes we we cannot look for those here.
352362
}, 10_000);
353363

354364
// logs should be created in order of how archiver syncs.

‎yarn-project/archiver/src/archiver/archiver.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export class Archiver implements ArchiveSource {
290290
};
291291

292292
// This is an edge case that we only hit if there are no proposed blocks.
293+
// If we have 0 blocks locally and there are no blocks onchain there is nothing to do.
293294
const noBlocks = localPendingBlockNumber === 0n && pendingBlockNumber === 0n;
294295
if (noBlocks) {
295296
await this.store.setBlockSynchedL1BlockNumber(currentL1BlockNumber);
@@ -358,6 +359,7 @@ export class Archiver implements ArchiveSource {
358359

359360
if (retrievedBlocks.length === 0) {
360361
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
362+
// See further details in earlier comments.
361363
this.log.verbose(`Retrieved no new blocks from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}`);
362364
return;
363365
}
@@ -590,7 +592,7 @@ class ArchiverStoreHelper
590592
if (operation == Operation.Store) {
591593
return await this.store.addContractClasses(contractClasses, blockNum);
592594
} else if (operation == Operation.Delete) {
593-
// return await this.store.deleteContractClasses(contractClasses, blockNum);
595+
return await this.store.deleteContractClasses(contractClasses, blockNum);
594596
}
595597
}
596598
return true;
@@ -609,7 +611,7 @@ class ArchiverStoreHelper
609611
if (operation == Operation.Store) {
610612
return await this.store.addContractInstances(contractInstances, blockNum);
611613
} else if (operation == Operation.Delete) {
612-
// return await this.store.deleteContractInstances(contractInstances, blockNum);
614+
return await this.store.deleteContractInstances(contractInstances, blockNum);
613615
}
614616
}
615617
return true;
@@ -696,7 +698,8 @@ class ArchiverStoreHelper
696698
throw new Error(`Can only remove from the tip`);
697699
}
698700

699-
const blocks = await this.getBlocks(from - blocksToUnwind, blocksToUnwind);
701+
// from - blocksToUnwind = the new head, so + 1 for what we need to remove
702+
const blocks = await this.getBlocks(from - blocksToUnwind + 1, blocksToUnwind);
700703

701704
return [
702705
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them

‎yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class BlockStore {
8686
*/
8787
unwindBlocks(from: number, blocksToUnwind: number) {
8888
return this.db.transaction(() => {
89-
// We should only allow deleting the very last ye, otherwise we can really get some messy shit.
9089
const last = this.getSynchedL2BlockNumber();
9190
if (from != last) {
9291
throw new Error(`Can only remove from the tip`);

‎yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ export class MemoryArchiverStore implements ArchiverDataStore {
332332
logType: TLogType,
333333
): Promise<L2BlockL2Logs<FromLogType<TLogType>>[]> {
334334
if (from < INITIAL_L2_BLOCK_NUM || limit < 1) {
335-
throw new Error(`Invalid limit: ${limit}`);
335+
return Promise.resolve([]);
336336
}
337337

338338
if (from > this.l2Blocks.length) {
339-
throw new Error(`"from" cannot be in the future`);
339+
return Promise.resolve([]);
340340
}
341341

342342
const logMap = (() => {

0 commit comments

Comments
 (0)