@abtnode/core 1.16.2 → 1.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ const pRetry = require('p-retry');
|
|
|
5
5
|
const Client = require('@ocap/client');
|
|
6
6
|
const urlFriendly = require('@blocklet/meta/lib/url-friendly').default;
|
|
7
7
|
const { slugify } = require('transliteration');
|
|
8
|
+
const Lock = require('@abtnode/util/lib/lock');
|
|
8
9
|
|
|
9
10
|
const logger = require('@abtnode/logger')('@abtnode/core:migrate-application-to-struct-v2');
|
|
10
11
|
|
|
@@ -41,6 +42,8 @@ const sortMoveListBySrc = (list) => {
|
|
|
41
42
|
return list.sort((a, b) => (a.src.length > b.src.length ? -1 : 1));
|
|
42
43
|
};
|
|
43
44
|
|
|
45
|
+
const lock = new Lock('migrate-application-to-struct-v2');
|
|
46
|
+
|
|
44
47
|
const validateDataMoveList = (list) => {
|
|
45
48
|
const srcList = list.map((x) => x.src);
|
|
46
49
|
const distList = list.map((x) => x.dist);
|
|
@@ -179,7 +182,12 @@ const migrateAppOnChain = async (blocklet, oldSk, newSk) => {
|
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
|
|
182
|
-
|
|
185
|
+
// should not throw error because signAccountMigrateTx is already happened
|
|
186
|
+
try {
|
|
187
|
+
await ensureAccountOnMainChain(blocklet, newWallet);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
logger.error('ensureAccountOnMainChain failed', { error });
|
|
190
|
+
}
|
|
183
191
|
};
|
|
184
192
|
|
|
185
193
|
const migrateApplicationToStructV2 = async ({ did, appSk: newAppSk, context = {}, manager, states }) => {
|
|
@@ -381,6 +389,18 @@ const migrateApplicationToStructV2 = async ({ did, appSk: newAppSk, context = {}
|
|
|
381
389
|
);
|
|
382
390
|
siteData.domainAliases.push({ value: getIpDnsDomainForBlocklet(blockletData), isProtected: true });
|
|
383
391
|
|
|
392
|
+
await lock.acquire();
|
|
393
|
+
// check if blocklet already migrated
|
|
394
|
+
try {
|
|
395
|
+
const checkBlocklet = await manager.getBlocklet(did, { throwOnNotExist: true, ensureIntegrity: false });
|
|
396
|
+
if (checkBlocklet.structVersion) {
|
|
397
|
+
throw new Error('Blocklet already migrated in a few seconds', pick(oldBlocklet, ['structVersion', 'externalSk']));
|
|
398
|
+
}
|
|
399
|
+
} catch (error) {
|
|
400
|
+
lock.release();
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
|
|
384
404
|
// update state
|
|
385
405
|
let newBlocklet;
|
|
386
406
|
try {
|
|
@@ -443,28 +463,35 @@ const migrateApplicationToStructV2 = async ({ did, appSk: newAppSk, context = {}
|
|
|
443
463
|
retries: 3,
|
|
444
464
|
onFailedAttempt: console.error,
|
|
445
465
|
});
|
|
466
|
+
lock.release();
|
|
446
467
|
} catch (error) {
|
|
447
468
|
logger.error('Migrate application state failed: ', { did, error });
|
|
448
469
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
470
|
+
try {
|
|
471
|
+
await states.blocklet.remove({ _id: backupBlocklet._id });
|
|
472
|
+
await states.blocklet.remove({ 'meta.did': blockletData.meta.did });
|
|
473
|
+
await states.blocklet.insert(backupBlocklet);
|
|
474
|
+
await states.blockletExtras.remove({ _id: backupExtra._id });
|
|
475
|
+
await states.blockletExtras.insert(backupExtra);
|
|
476
|
+
await states.site.remove({ _id: backupSite._id });
|
|
477
|
+
await states.site.insert(backupSite);
|
|
478
|
+
|
|
479
|
+
logger.info('Rollback application state');
|
|
480
|
+
|
|
481
|
+
// rollback data
|
|
482
|
+
fs.ensureDirSync(dataDirSrc);
|
|
483
|
+
for (let i = currentMoveIndex; i >= 0; i--) {
|
|
484
|
+
const { src, dist } = sortedDataMoveList[i];
|
|
485
|
+
fs.moveSync(dist, src);
|
|
486
|
+
}
|
|
487
|
+
fs.removeSync(dataDirDist);
|
|
458
488
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const { src, dist } = sortedDataMoveList[i];
|
|
463
|
-
fs.moveSync(dist, src);
|
|
489
|
+
logger.info('Rollback application data');
|
|
490
|
+
} catch (err) {
|
|
491
|
+
logger.error('Rollback application failed', { error, err });
|
|
464
492
|
}
|
|
465
|
-
fs.removeSync(dataDirDist);
|
|
466
493
|
|
|
467
|
-
|
|
494
|
+
lock.release();
|
|
468
495
|
|
|
469
496
|
throw error;
|
|
470
497
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.3",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.
|
|
24
|
-
"@abtnode/constant": "1.16.
|
|
25
|
-
"@abtnode/cron": "1.16.
|
|
26
|
-
"@abtnode/db": "1.16.
|
|
27
|
-
"@abtnode/logger": "1.16.
|
|
28
|
-
"@abtnode/queue": "1.16.
|
|
29
|
-
"@abtnode/rbac": "1.16.
|
|
30
|
-
"@abtnode/router-provider": "1.16.
|
|
31
|
-
"@abtnode/static-server": "1.16.
|
|
32
|
-
"@abtnode/timemachine": "1.16.
|
|
33
|
-
"@abtnode/util": "1.16.
|
|
22
|
+
"@abtnode/auth": "1.16.3",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.3",
|
|
24
|
+
"@abtnode/constant": "1.16.3",
|
|
25
|
+
"@abtnode/cron": "1.16.3",
|
|
26
|
+
"@abtnode/db": "1.16.3",
|
|
27
|
+
"@abtnode/logger": "1.16.3",
|
|
28
|
+
"@abtnode/queue": "1.16.3",
|
|
29
|
+
"@abtnode/rbac": "1.16.3",
|
|
30
|
+
"@abtnode/router-provider": "1.16.3",
|
|
31
|
+
"@abtnode/static-server": "1.16.3",
|
|
32
|
+
"@abtnode/timemachine": "1.16.3",
|
|
33
|
+
"@abtnode/util": "1.16.3",
|
|
34
34
|
"@arcblock/did": "1.18.65",
|
|
35
35
|
"@arcblock/did-motif": "^1.1.10",
|
|
36
36
|
"@arcblock/did-util": "1.18.65",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@arcblock/jwt": "^1.18.65",
|
|
39
39
|
"@arcblock/pm2-events": "^0.0.5",
|
|
40
40
|
"@arcblock/vc": "1.18.65",
|
|
41
|
-
"@blocklet/constant": "1.16.
|
|
42
|
-
"@blocklet/meta": "1.16.
|
|
43
|
-
"@blocklet/sdk": "1.16.
|
|
41
|
+
"@blocklet/constant": "1.16.3",
|
|
42
|
+
"@blocklet/meta": "1.16.3",
|
|
43
|
+
"@blocklet/sdk": "1.16.3",
|
|
44
44
|
"@did-space/client": "^0.2.45",
|
|
45
45
|
"@fidm/x509": "^1.2.1",
|
|
46
46
|
"@ocap/client": "1.18.65",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"express": "^4.18.2",
|
|
94
94
|
"jest": "^27.5.1"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "a21d48225c6f89963796871f404a2318a335701d"
|
|
97
97
|
}
|