feat: 上链确认改为提交即查一次,重试间隔调整为 10s/30s
- AUTO_CONFIRM_DELAYS_MS=[0,10s,30s] 共 3 次自动确认,之后停等手动重新确认 - 实测提交同秒即查到 mint 进块直接 ONCHAIN
This commit is contained in:
@@ -13,9 +13,10 @@ interface OnchainJobData {
|
||||
manual?: boolean;
|
||||
}
|
||||
|
||||
const FIRST_CONFIRM_DELAY_MS = 30_000;
|
||||
const SECOND_CONFIRM_DELAY_MS = 60_000;
|
||||
const MAX_AUTO_CONFIRM_ATTEMPTS = 2;
|
||||
// 自动确认延迟序列(毫秒):第 1 次提交后立即查、未到再 10s、再 30s,共 3 次;之后停等手动重新确认。
|
||||
// 第 attempt 次(从 1 起)的延迟 = AUTO_CONFIRM_DELAYS_MS[attempt - 1]。
|
||||
const AUTO_CONFIRM_DELAYS_MS = [0, 10_000, 30_000];
|
||||
const MAX_AUTO_CONFIRM_ATTEMPTS = AUTO_CONFIRM_DELAYS_MS.length;
|
||||
|
||||
function requestMeta(raw: unknown): Record<string, unknown> | undefined {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
@@ -87,7 +88,8 @@ export class OnchainProcessor extends WorkerHost {
|
||||
},
|
||||
});
|
||||
if (result.confirmationRequired) {
|
||||
await this.scheduleConfirm(proofId, 1, FIRST_CONFIRM_DELAY_MS);
|
||||
// 提交完立即发起第 1 次确认查询(delay=0)
|
||||
await this.scheduleConfirm(proofId, 1, AUTO_CONFIRM_DELAYS_MS[0]);
|
||||
this.logger.log(`存证 ${proofId} 已提交链上,等待确认:txHash=${result.txHash} 存证链接=${result.explorerUrl ?? '-'}`);
|
||||
} else {
|
||||
this.logger.log(`存证 ${proofId} 上链成功:txHash=${result.txHash} blockHeight=${result.blockHeight ?? '-'}`);
|
||||
@@ -159,17 +161,16 @@ export class OnchainProcessor extends WorkerHost {
|
||||
this.logger.warn(`存证 ${proofId} 尚未查询到链上确认信息,等待手动重新确认`);
|
||||
return;
|
||||
}
|
||||
await this.scheduleConfirm(proofId, attempt + 1, SECOND_CONFIRM_DELAY_MS);
|
||||
await this.scheduleConfirm(proofId, attempt + 1, AUTO_CONFIRM_DELAYS_MS[attempt]);
|
||||
} catch (e) {
|
||||
const message = (e as Error).message;
|
||||
this.logger.warn(`存证 ${proofId} 链上确认查询失败(第 ${attempt} 次):${message}`);
|
||||
await this.recordWaiting(proofId, proof.rawResponse, { error: message }, attempt, manual);
|
||||
if (manual || attempt >= MAX_AUTO_CONFIRM_ATTEMPTS) {
|
||||
await this.recordWaiting(proofId, proof.rawResponse, { error: message }, attempt, manual);
|
||||
this.logger.warn(`存证 ${proofId} 自动确认已达上限,等待手动重新确认`);
|
||||
return;
|
||||
}
|
||||
await this.recordWaiting(proofId, proof.rawResponse, { error: message }, attempt, manual);
|
||||
await this.scheduleConfirm(proofId, attempt + 1, SECOND_CONFIRM_DELAY_MS);
|
||||
await this.scheduleConfirm(proofId, attempt + 1, AUTO_CONFIRM_DELAYS_MS[attempt]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user