Skip to content

Commit

Permalink
server: capture and return errors from debugMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ar committed Oct 28, 2024
1 parent 440dd3a commit 9d5e221
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions desci-server/src/controllers/admin/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,36 @@ const debugDpid = async (dpid?: number) => {
return { present: true, error: false, mappedStream };
};

type DebugMigrationReponse = {
error: boolean;
hasLegacyHistory: boolean;
hasStreamHistory: boolean;
ownerMatches?: boolean;
allVersionsPresent?: boolean;
allVersionsOrdered?: boolean;
zipped?: [string, string][];
};
type DebugMigrationReponse =
| {
error: boolean;
hasLegacyHistory: boolean;
hasStreamHistory: boolean;
ownerMatches?: boolean;
allVersionsPresent?: boolean;
allVersionsOrdered?: boolean;
zipped?: [string, string][];
}
| {
error: true;
name: string;
message: string;
stack: unknown;
};

/*
* Checks if the theres a signature signer mismatch between the legacy contract RO and the stream
*/
const debugMigration = async (uuid?: string, stream?: DebugStreamResponse): Promise<DebugMigrationReponse> => {
// Establish if there is a token history
const legacyHistoryResponse = await _getIndexedResearchObjects([uuid]);
let legacyHistoryResponse;
try {
legacyHistoryResponse = await _getIndexedResearchObjects([uuid]);
} catch (err) {
logger.error({ uuid, err }, 'Failed to query legacy history');
return { error: true, name: err.name, message: err.message, stack: err.stack };
}

const hasLegacyHistory = !!legacyHistoryResponse?.researchObjects?.length;

if (!hasLegacyHistory || !stream.present) {
Expand All @@ -278,6 +292,15 @@ const debugMigration = async (uuid?: string, stream?: DebugStreamResponse): Prom

const legacyHistory = legacyHistoryResponse.researchObjects[0];

let streamHistoryResponse;
try {
streamHistoryResponse = await getIndexedResearchObjects([uuid]);
} catch (err) {
logger.error({ uuid, err }, 'Failed to query stream history');
return { error: true, name: err.name, message: err.message, stack: err.stack };
}

const streamResearchObject = streamHistoryResponse.researchObjects[0];
const streamController =
stream.present && 'state' in stream.raw ? stream.raw.state.metadata.controllers[0].split(':').pop() : undefined;
const legacyOwner = legacyHistory.owner;
Expand All @@ -286,8 +309,7 @@ const debugMigration = async (uuid?: string, stream?: DebugStreamResponse): Prom
const ownerMatches = streamController?.toLowerCase() === legacyOwner?.toLowerCase();

// All Versions Migrated check
const { researchObjects: streamResearchObjects } = await getIndexedResearchObjects([uuid]);
const streamManifestCids = streamResearchObjects[0].versions.map((v) => v.cid);
const streamManifestCids = streamResearchObject.versions.map((v) => v.cid);
const legacyManifestCids = legacyHistory.versions.map((v) => v.cid);

const zipped = Array.from(
Expand Down

0 comments on commit 9d5e221

Please sign in to comment.