Добавить учёт публикации блоков и обновить загрузку UI

This commit is contained in:
AidarKC
2026-12-01 20:39:18 +03:00
parent 3fa1e681d9
commit a320c12bdd
30 changed files with 714 additions and 60 deletions
+44 -18
View File
@@ -41,6 +41,8 @@ import {
saveSessionMaterial,
} from './key-vault.js';
import { signEventContainer, submitSignedEvent, readStoredLineMeta } from './core-content.js';
import { showToast } from './channels-ux.js';
import { t } from '../i18n/index.js';
import { defaultServerWs } from '../deploy-config.js';
import { readPendingHeaderIdentity, clearPendingHeaderIdentity } from './pending-header-identity.js';
@@ -1172,6 +1174,14 @@ export class AuthService {
const connectionScope = String(createResp?.payload?.connectionScope || '').trim().toUpperCase();
const canonicalLogin = await this.resolveCanonicalDisplayLogin(cleanLogin);
void (async () => {
try {
const user = await this.getUser(canonicalLogin);
const { publishPendingBlocks } = await import('./block-publication-service.js');
await publishPendingBlocks({ ws: this.ws, login: canonicalLogin, storagePwd,
blockchainName: String(user?.blockchainName || `${canonicalLogin}-${BCH_SUFFIX}`) });
} catch (error) { console.warn('Block publication resume failed', error); }
})();
return {
login: canonicalLogin,
@@ -1350,6 +1360,14 @@ export class AuthService {
const connectionScope = String(loginResp?.payload?.connectionScope || '').trim().toUpperCase();
const canonicalLogin = await this.resolveCanonicalDisplayLogin(cleanLogin);
void (async () => {
try {
const user = await this.getUser(canonicalLogin);
const { publishPendingBlocks } = await import('./block-publication-service.js');
await publishPendingBlocks({ ws: this.ws, login: canonicalLogin, storagePwd,
blockchainName: String(user?.blockchainName || `${canonicalLogin}-${BCH_SUFFIX}`) });
} catch (error) { console.warn('Block publication resume failed', error); }
})();
return {
login: canonicalLogin,
@@ -1723,26 +1741,34 @@ export class AuthService {
}
async runAddBlockWithRetry({ login, storagePwd, resolveFreshState, event }) {
const freshState = await resolveFreshState();
const blockchainName = String(freshState?.blockchainName || '').trim();
if (!blockchainName) throw new Error('runAddBlockWithRetry: blockchainName is empty');
const tryAdd = cursor => this.submitPreparedAddBlock({ login, storagePwd, blockchainName,
blockNumber: Number(cursor?.serverLastGlobalNumber ?? -1) + 1,
prevBlockHash: normalizeHex32(cursor?.serverLastGlobalHash, ZERO64), event });
let response = await tryAdd(freshState.cursor);
// Only a definitive global cursor conflict allows a new signature. An ambiguous
// delivery is handled by submitSignedEvent using the original signed bytes.
const code = String(response?.payload?.code || response?.code || '').toLowerCase();
if (response.status !== 200 && ['bad_block_number', 'bad_prev_hash'].includes(code)) {
const refreshed = await resolveFreshState();
if (refreshed.blockchainName !== blockchainName) throw new Error('Blockchain changed during AddBlock');
// HEADER must never be recreated at a nonzero number.
if (!(event.msgType === MSG_TYPE_TECH && event.msgSubType === MSG_SUBTYPE_TECH_HEADER)) {
response = await tryAdd(refreshed.cursor);
try {
const freshState = await resolveFreshState();
const blockchainName = String(freshState?.blockchainName || '').trim();
if (!blockchainName) throw new Error('runAddBlockWithRetry: blockchainName is empty');
const tryAdd = cursor => this.submitPreparedAddBlock({ login, storagePwd, blockchainName,
blockNumber: Number(cursor?.serverLastGlobalNumber ?? -1) + 1,
prevBlockHash: normalizeHex32(cursor?.serverLastGlobalHash, ZERO64), event });
let response = await tryAdd(freshState.cursor);
// Only a definitive global cursor conflict allows a new signature. An ambiguous
// delivery is handled by submitSignedEvent using the original signed bytes.
const code = String(response?.payload?.code || response?.code || '').toLowerCase();
if (response.status !== 200 && ['bad_block_number', 'bad_prev_hash'].includes(code)) {
const refreshed = await resolveFreshState();
if (refreshed.blockchainName !== blockchainName) throw new Error('Blockchain changed during AddBlock');
// HEADER must never be recreated at a nonzero number.
if (!(event.msgType === MSG_TYPE_TECH && event.msgSubType === MSG_SUBTYPE_TECH_HEADER)) {
response = await tryAdd(refreshed.cursor);
}
}
if (response.status !== 200) throw opError('AddBlock', response);
void import('./block-publication-service.js').then(({ publishPendingBlocks }) =>
publishPendingBlocks({ ws: this.ws, login, storagePwd, blockchainName }))
.catch(error => console.warn('Block publication start failed', error));
return { response, blockchainName };
} catch (error) {
showToast(t('block_publication.add_failed'), { kind: 'error' });
throw error;
}
if (response.status !== 200) throw opError('AddBlock', response);
return { response, blockchainName };
}
async addBlockSigned({ login, storagePwd, msgType, msgSubType, msgVersion = 1, bodyBytes, channelSlug = '', _skipHeaderEnsure = false }) {