Skip to content

Commit

Permalink
make importer optional
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Dec 5, 2024
1 parent e87e716 commit d7c9a87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, injectable, tagged } from "@mainsail/container";
import { inject, injectable, optional, tagged } from "@mainsail/container";
import { Contracts, Identifiers } from "@mainsail/contracts";
import { EvmCallBuilder } from "@mainsail/crypto-transaction-evm-call";
import { Deployer, Identifiers as EvmConsensusIdentifiers } from "@mainsail/evm-consensus";
Expand All @@ -23,7 +23,8 @@ export class GenesisBlockGenerator extends Generator {
private readonly transactionVerifier!: Contracts.Crypto.TransactionVerifier;

@inject(Identifiers.Snapshot.Legacy.Importer)
private readonly snapshotLegacyImporter!: Contracts.Snapshot.LegacyImporter;
@optional()
private readonly snapshotLegacyImporter?: Contracts.Snapshot.LegacyImporter;

@inject(Identifiers.Evm.Instance)
@tagged("instance", "evm")
Expand Down Expand Up @@ -329,6 +330,7 @@ export class GenesisBlockGenerator extends Generator {

async #buildFromLegacySnapshot(options: Contracts.NetworkGenerator.GenesisBlockOptions) {
Utils.assert.defined(options.snapshot);
Utils.assert.defined(this.snapshotLegacyImporter);

// Load snapshot into EVM
const result = await this.snapshotLegacyImporter.import({
Expand Down
11 changes: 8 additions & 3 deletions packages/processor/source/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
@inject(Identifiers.State.State)
private readonly state!: Contracts.State.State;

@inject(Identifiers.Snapshot.Legacy.Importer)
private readonly snapshotImporter!: Contracts.Snapshot.LegacyImporter;

@inject(Identifiers.Cryptography.Configuration)
private readonly configuration!: Contracts.Crypto.Configuration;

Expand Down Expand Up @@ -50,6 +47,10 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
@inject(Identifiers.Evm.Worker)
private readonly evmWorker!: Contracts.Evm.Worker;

@inject(Identifiers.Snapshot.Legacy.Importer)
@optional()
private readonly snapshotImporter?: Contracts.Snapshot.LegacyImporter;

@inject(Identifiers.ApiSync.Service)
@optional()
private readonly apiSync?: Contracts.ApiSync.Service;
Expand Down Expand Up @@ -187,6 +188,10 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
return;
}

if (!this.snapshotImporter) {
throw new Error("snapshot importer not loaded");
}

const milestone = this.configuration.getMilestone();

// assume snapshot is present if the previous block points to a non-zero hash
Expand Down

0 comments on commit d7c9a87

Please sign in to comment.