@abtnode/core 1.16.11-next-3d2b39f7 → 1.16.11-next-d32a90d4

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.
@@ -70,6 +70,8 @@ const {
70
70
  BLOCKLET_CONFIGURABLE_KEY,
71
71
  RESTORE_PROGRESS_STATUS,
72
72
  CHAIN_PROP_MAP_REVERSE,
73
+ BLOCKLET_CONTROLLER_STATUS,
74
+ SUSPENDED_REASON,
73
75
  } = require('@blocklet/constant');
74
76
  const { consumeServerlessNFT, consumeLauncherSession } = require('../../util/launcher');
75
77
  const util = require('../../util');
@@ -111,7 +113,7 @@ const {
111
113
  getProcessState,
112
114
  getBlockletStatus,
113
115
  shouldSkipComponent,
114
- shouldCleanExpiredBlocklet,
116
+ exceedRedemptionPeriod,
115
117
  } = require('../../util/blocklet');
116
118
  const states = require('../../states');
117
119
  const BaseBlockletManager = require('./base');
@@ -457,6 +459,8 @@ class BlockletManager extends BaseBlockletManager {
457
459
  // should check blocklet integrity
458
460
  const blocklet = await this.ensureBlocklet(did, { e2eMode });
459
461
 
462
+ await this.checkControllerStatus(blocklet, 'start');
463
+
460
464
  try {
461
465
  // blocklet may be manually stopped durning starting
462
466
  // so error message would not be sent if blocklet is stopped
@@ -651,7 +655,6 @@ class BlockletManager extends BaseBlockletManager {
651
655
  }
652
656
 
653
657
  /**
654
- * FIXME: @linchen support cancel
655
658
  * @param {import('@abtnode/client').RequestRestoreBlockletInput} input
656
659
  * @memberof BlockletManager
657
660
  */
@@ -677,6 +680,8 @@ class BlockletManager extends BaseBlockletManager {
677
680
  */
678
681
  async restart({ did, componentDids }, context) {
679
682
  logger.info('restart blocklet', { did });
683
+ const blocklet = await this.getBlocklet(did);
684
+ await this.checkControllerStatus(blocklet, 'restart');
680
685
 
681
686
  await states.blocklet.setBlockletStatus(did, BlockletStatus.stopping, { componentDids });
682
687
  const result = await states.blocklet.getBlocklet(did);
@@ -712,6 +717,8 @@ class BlockletManager extends BaseBlockletManager {
712
717
  async reload({ did, componentDids: list }, context) {
713
718
  const blocklet = await this.getBlocklet(did);
714
719
 
720
+ await this.checkControllerStatus(blocklet, 'reload');
721
+
715
722
  const componentDids = (blocklet.children || [])
716
723
  .filter((x) => x.status === BlockletStatus.running)
717
724
  .filter((x) => !shouldSkipComponent(x.meta.did, list))
@@ -1042,22 +1049,9 @@ class BlockletManager extends BaseBlockletManager {
1042
1049
  }
1043
1050
  }
1044
1051
 
1045
- async list({ includeRuntimeInfo = true, query, filter } = {}, context) {
1052
+ async list({ includeRuntimeInfo = true, query } = {}, context) {
1046
1053
  const condition = { ...flat(query || {}) };
1047
- if (filter === 'external-only') {
1048
- condition.controller = {
1049
- $exists: true,
1050
- };
1051
- }
1052
-
1053
- if (filter === 'external-excluded') {
1054
- condition.controller = {
1055
- $exists: false,
1056
- };
1057
- }
1058
-
1059
1054
  const blocklets = await states.blocklet.getBlocklets(condition);
1060
-
1061
1055
  if (includeRuntimeInfo) {
1062
1056
  return this._attachBlockletListRuntimeInfo({ blocklets }, context);
1063
1057
  }
@@ -1446,7 +1440,7 @@ class BlockletManager extends BaseBlockletManager {
1446
1440
  await forEachComponentV2(
1447
1441
  blocklet,
1448
1442
  async (component) => {
1449
- if (!forceSync || !isInProgress(component.status)) {
1443
+ if (!forceSync && !util.shouldUpdateBlockletStatus(component.status)) {
1450
1444
  return;
1451
1445
  }
1452
1446
 
@@ -1457,10 +1451,24 @@ class BlockletManager extends BaseBlockletManager {
1457
1451
  try {
1458
1452
  const status = await getProcessState(component.env.processId);
1459
1453
  if (component.status !== status) {
1454
+ component.status = status;
1460
1455
  await states.blocklet.setBlockletStatus(did, status, { componentDids: [component.meta.did] });
1461
1456
  }
1462
1457
  } catch {
1463
- // do nothing
1458
+ if (
1459
+ ![
1460
+ BlockletStatus.added,
1461
+ BlockletStatus.waiting,
1462
+ BlockletStatus.downloading,
1463
+ BlockletStatus.installing,
1464
+ BlockletStatus.installed,
1465
+ BlockletStatus.upgrading,
1466
+ ].includes(component.status)
1467
+ ) {
1468
+ const status = BlockletStatus.stopped;
1469
+ component.status = status;
1470
+ await states.blocklet.setBlockletStatus(did, status, { componentDids: [component.meta.did] });
1471
+ }
1464
1472
  }
1465
1473
  },
1466
1474
  { parallel: true }
@@ -1535,6 +1543,7 @@ class BlockletManager extends BaseBlockletManager {
1535
1543
  name: 'sync-blocklet-status',
1536
1544
  time: '*/60 * * * * *', // 60s
1537
1545
  fn: this._syncBlockletStatus.bind(this),
1546
+ options: { runOnInit: false },
1538
1547
  },
1539
1548
  {
1540
1549
  name: 'sync-blocklet-list',
@@ -1544,22 +1553,29 @@ class BlockletManager extends BaseBlockletManager {
1544
1553
  {
1545
1554
  name: 'refresh-accessible-ip',
1546
1555
  time: '0 */10 * * * *', // 10min
1556
+ options: { runOnInit: true },
1547
1557
  fn: async () => {
1548
1558
  const nodeInfo = await states.node.read();
1549
1559
  await refreshAccessibleExternalNodeIp(nodeInfo);
1550
1560
  },
1551
1561
  },
1552
1562
  {
1553
- name: 'delete-expired-external-blocklet',
1563
+ name: 'check-renewed-blocklet',
1564
+ time: '0 */10 * * * *', // 10min
1565
+ options: { runOnInit: false },
1566
+ fn: () => this.checkRenewedBlocklet(),
1567
+ },
1568
+ {
1569
+ name: 'stop-expired-external-blocklet',
1554
1570
  time: '0 */30 * * * *', // 30min
1555
1571
  options: { runOnInit: false },
1556
- fn: () => this._deleteExpiredExternalBlocklet(),
1572
+ fn: () => this.stopExpiredBlocklets(),
1557
1573
  },
1558
1574
  {
1559
1575
  name: 'clean-expired-blocklet-data',
1560
1576
  time: '0 */20 0 * * *', // 每天凌晨 0 点的每 20 分钟
1561
1577
  options: { runOnInit: false },
1562
- fn: () => this._cleanExpiredBlockletData(),
1578
+ fn: () => this.cleanExpiredBlocklets(),
1563
1579
  },
1564
1580
  {
1565
1581
  name: 'record-blocklet-runtime-history',
@@ -2841,71 +2857,102 @@ class BlockletManager extends BaseBlockletManager {
2841
2857
  }
2842
2858
  }
2843
2859
 
2844
- async _deleteExpiredExternalBlocklet() {
2860
+ async checkRenewedBlocklet() {
2845
2861
  try {
2846
- logger.info('start check expired external blocklet');
2862
+ logger.info('start check renewed blocklet');
2863
+
2864
+ // 只检查因为过期而被 suspended 的 blocklet
2865
+ const blockletExtras = await states.blockletExtras.find(
2866
+ {
2867
+ 'controller.status.value': BLOCKLET_CONTROLLER_STATUS.suspended,
2868
+ 'controller.status.reason': SUSPENDED_REASON.expired,
2869
+ },
2870
+ { did: 1, meta: 1, controller: 1 }
2871
+ );
2872
+
2873
+ for (const data of blockletExtras) {
2874
+ const blocklet = await states.blocklet.getBlocklet(data.did);
2875
+ if (!blocklet) {
2876
+ logger.error('blocklet not found', { did: data.did });
2877
+ // eslint-disable-next-line no-continue
2878
+ continue;
2879
+ }
2880
+
2881
+ const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2882
+ const isExpired = isNFTExpired(assetState);
2883
+ if (isExpired === false) {
2884
+ logger.info('blocklet is renewed', { did: data.did });
2885
+ await states.blockletExtras.updateByDid(data.did, {
2886
+ ...data.controller,
2887
+ status: { value: BLOCKLET_CONTROLLER_STATUS.normal, reason: '' },
2888
+ });
2889
+
2890
+ logger.info('start to start blocklet', { did: data.did });
2891
+
2892
+ if (![BlockletStatus.starting, BlockletStatus.running].includes(blocklet.status)) {
2893
+ await this.start({ did: data.did });
2894
+ logger.info('start blocklet success', { did: data.did });
2895
+ }
2896
+ }
2897
+ }
2898
+ } catch (error) {
2899
+ logger.error('start check renewed blocklet failed', { error });
2900
+ }
2901
+ }
2902
+
2903
+ async stopExpiredBlocklets() {
2904
+ try {
2905
+ logger.info('start checking expired blocklet');
2847
2906
  const blockletExtras = await states.blockletExtras.find(
2848
2907
  {
2849
2908
  controller: {
2850
2909
  $exists: true,
2851
2910
  },
2852
- expiredAt: {
2853
- $exists: false,
2854
- },
2855
2911
  },
2856
2912
  { did: 1, meta: 1, controller: 1 }
2857
2913
  );
2858
2914
 
2859
- logger.info('external blocklet count', { count: blockletExtras.length });
2915
+ if (blockletExtras.length === 0) {
2916
+ logger.info('no expired blocklet');
2917
+ return;
2918
+ }
2919
+
2920
+ logger.info('expired blocklet count', { count: blockletExtras.length });
2860
2921
 
2861
2922
  for (const data of blockletExtras) {
2862
2923
  try {
2863
- if (isEmpty(data.controller)) {
2864
- logger.info('skip the blocklet without controller', { blockletDid: data.did, controller: data.controller });
2865
- // eslint-disable-next-line no-continue
2866
- continue;
2867
- }
2868
-
2869
2924
  const { did } = data;
2870
2925
  const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2871
2926
  const isExpired = isNFTExpired(assetState);
2927
+ const blocklet = await states.blocklet.getBlocklet(did);
2872
2928
 
2873
- if (isExpired) {
2874
- logger.info('the blocklet already expired', {
2929
+ if (isExpired && blocklet.status !== BlockletStatus.stopped) {
2930
+ const expiredAt = getNftExpirationDate(assetState);
2931
+ logger.info('the blocklet already expired and will be stopped', {
2875
2932
  blockletDid: did,
2876
2933
  nftId: data.controller.nftId,
2934
+ expiredAt,
2877
2935
  });
2878
2936
 
2879
- const blocklet = await states.blocklet.getBlocklet(did);
2880
- if (blocklet) {
2881
- // 预防 Blocklet 已经删除,但是 blocklet extra data 没有清理的场景
2882
- await this._backupToDisk({ blocklet });
2883
- logger.info('backed up the expired blocklet', {
2884
- blockletDid: did,
2885
- nftId: data.controller.nftId,
2886
- });
2887
-
2888
- await this.delete({ did, keepData: true, keepConfigs: true, keepLogsDir: true });
2889
- logger.info('the expired blocklet already deleted', {
2890
- blockletDid: did,
2891
- nftId: data.controller.nftId,
2892
- });
2893
- }
2894
-
2895
- const expiredAt = getNftExpirationDate(assetState);
2896
- await states.blockletExtras.updateExpireInfo({ did, expiredAt });
2897
- logger.info('updated expired blocklet extra info', {
2898
- nftId: data.controller.nftId,
2899
- blockletDid: did,
2937
+ await this.stop({ did });
2938
+ await states.blockletExtras.updateByDid(did, {
2939
+ controller: {
2940
+ ...data.controller,
2941
+ status: {
2942
+ value: BLOCKLET_CONTROLLER_STATUS.suspended,
2943
+ reason: SUSPENDED_REASON.expired,
2944
+ },
2945
+ },
2900
2946
  });
2947
+ logger.info('the expired blocklet is stopped', { did });
2901
2948
 
2902
- // 删除 blocklet 后会 reload nginx, 所以这里每次删除一个
2949
+ // 为了减小服务器压力,每次删除一个 blocklet 后,休息 10s
2903
2950
  if (process.env.NODE_ENV !== 'test') {
2904
2951
  await sleep(10 * 1000);
2905
2952
  }
2906
2953
  }
2907
2954
  } catch (error) {
2908
- logger.error('delete expired blocklet failed', {
2955
+ logger.error('stop expired blocklet failed', {
2909
2956
  blockletDid: data.did,
2910
2957
  nftId: data.controller?.nftId,
2911
2958
  error,
@@ -2919,62 +2966,68 @@ class BlockletManager extends BaseBlockletManager {
2919
2966
  }
2920
2967
  }
2921
2968
 
2922
- async _cleanExpiredBlockletData() {
2969
+ async cleanExpiredBlocklets() {
2923
2970
  try {
2924
- logger.info('start clean expired blocklet data');
2925
- const blockletExtras = await states.blockletExtras.getExpiredList();
2971
+ logger.info('start checking exceeding the redemption period blocklet');
2972
+ const blockletExtras = await states.blockletExtras.find(
2973
+ {
2974
+ 'controller.status.value': BLOCKLET_CONTROLLER_STATUS.suspended,
2975
+ },
2976
+ { did: 1, meta: 1, controller: 1 }
2977
+ );
2978
+
2926
2979
  if (blockletExtras.length === 0) {
2927
- logger.info('no expired blocklet data');
2980
+ logger.info('no exceeding the redemption blocklet need to be cleaned');
2928
2981
  return;
2929
2982
  }
2930
2983
 
2931
- const tasks = blockletExtras.map(async ({ appDid, did, meta, controller }) => {
2932
- const blocklet = await this.getBlocklet(did);
2933
- if (blocklet) {
2934
- logger.error('skip cleaning the blocklet which is not deleted', { blockletDid: did });
2935
- return;
2936
- }
2937
-
2938
- const assetState = await util.getNFTState(controller.chainHost, controller.nftId);
2939
- const expirationDate = getNftExpirationDate(assetState);
2984
+ logger.info('exceeding the redemption blocklet count', { count: blockletExtras.length });
2940
2985
 
2941
- if (!shouldCleanExpiredBlocklet(expirationDate)) {
2942
- logger.error('skip cleaning the blocklet which is not expired', { blockletDid: did, expirationDate });
2943
- await blockletExtras.updateExpireInfo({ did, expiredAt: expirationDate });
2944
- return;
2945
- }
2946
-
2947
- let blockletMeta = meta;
2948
- if (isEmpty(blockletMeta)) {
2949
- // 旧版本的 blocklet 没有 meta 信息,这里补充一下
2950
- blockletMeta = { did, name: did };
2951
- logger.error('the blocklet original meta is empty', { did, blockletMeta });
2952
- }
2986
+ for (const data of blockletExtras) {
2987
+ try {
2988
+ const { did } = data;
2989
+ const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2990
+ const expiredAt = getNftExpirationDate(assetState);
2953
2991
 
2954
- await this._cleanBlockletData({
2955
- blocklet: { meta: blockletMeta },
2956
- keepData: false,
2957
- keepLogsDir: false,
2958
- keepConfigs: false,
2959
- });
2960
- logger.info(`clean blocklet ${blockletMeta.did} extra data`);
2992
+ if (!exceedRedemptionPeriod(expiredAt)) {
2993
+ logger.error('skip cleaning the non-exceed redemption blocklet', {
2994
+ blockletDid: did,
2995
+ expiredAt,
2996
+ });
2997
+ // eslint-disable-next-line no-continue
2998
+ continue;
2999
+ }
2961
3000
 
2962
- await removeBackup(this.dataDirs.data, appDid);
2963
- logger.info(`removed blocklet ${blockletMeta.did} backup`);
3001
+ logger.info('the blocklet already exceed redemption and will be deleted', {
3002
+ blockletDid: did,
3003
+ nftId: data.controller.nftId,
3004
+ expiredAt,
3005
+ });
2964
3006
 
2965
- this.emit(BlockletEvents.dataCleaned, {
2966
- blocklet: { meta: blockletMeta },
2967
- keepRouting: false,
2968
- });
3007
+ // TODO: 如果绑定了 DID Space 备份到 DID Space
2969
3008
 
2970
- logger.info(`cleaned expired blocklet blocklet ${blockletMeta.did} data`);
2971
- });
3009
+ await this.delete({ did, keepData: false, keepConfigs: false, keepLogsDir: false });
3010
+ logger.info('the exceed redemption blocklet already deleted', {
3011
+ blockletDid: did,
3012
+ nftId: data.controller.nftId,
3013
+ });
2972
3014
 
2973
- await Promise.all(tasks);
3015
+ // 删除 blocklet 后会 reload nginx, 所以这里每次删除一个
3016
+ if (process.env.NODE_ENV !== 'test') {
3017
+ await sleep(10 * 1000);
3018
+ }
3019
+ } catch (error) {
3020
+ logger.error('delete exceed redemption blocklet failed', {
3021
+ blockletDid: data.did,
3022
+ nftId: data.controller?.nftId,
3023
+ error,
3024
+ });
3025
+ }
3026
+ }
2974
3027
 
2975
- logger.info('clean expired blocklet data done');
3028
+ logger.info('check exceeding the redemption period blocklet end');
2976
3029
  } catch (error) {
2977
- logger.error('clean expired blocklet data failed', { error });
3030
+ logger.error('checking exceeding the redemption period blocklet failed', { error });
2978
3031
  }
2979
3032
  }
2980
3033
 
@@ -3178,6 +3231,38 @@ class BlockletManager extends BaseBlockletManager {
3178
3231
  }
3179
3232
  await this._setConfigsFromMeta(did);
3180
3233
  }
3234
+
3235
+ async checkControllerStatus(blocklet, action) {
3236
+ if (isEmpty(blocklet.controller)) {
3237
+ return;
3238
+ }
3239
+
3240
+ const assetState = await util.getNFTState(blocklet.controller?.chainHost, blocklet.controller?.nftId);
3241
+
3242
+ if (isNFTExpired(assetState)) {
3243
+ logger.error(`try to ${action} an expired blocklet`, {
3244
+ did: blocklet.meta.did,
3245
+ nftId: blocklet.controller?.nftId,
3246
+ });
3247
+ throw new Error(`can not ${action} an expired blocklet`);
3248
+ }
3249
+
3250
+ if (
3251
+ blocklet.controller.status?.value === BLOCKLET_CONTROLLER_STATUS.suspended &&
3252
+ blocklet.controller.status?.reason === SUSPENDED_REASON.expired
3253
+ ) {
3254
+ // 如果是因为过期被暂停的,续期后, 并且不影响启动
3255
+ await states.blockletExtras.updateByDid(blocklet.meta.did, {
3256
+ controller: {
3257
+ ...blocklet.controller,
3258
+ status: {
3259
+ value: BLOCKLET_CONTROLLER_STATUS.normal,
3260
+ reason: '',
3261
+ },
3262
+ },
3263
+ });
3264
+ }
3265
+ }
3181
3266
  }
3182
3267
 
3183
3268
  module.exports = BlockletManager;
package/lib/index.js CHANGED
@@ -266,6 +266,7 @@ function ABTNode(options) {
266
266
  migrateApplicationToStructV2: blockletManager.migrateApplicationToStructV2.bind(blockletManager),
267
267
 
268
268
  // For diagnose purpose
269
+ syncBlockletStatus: blockletManager.status.bind(blockletManager),
269
270
  ensureBlockletIntegrity: blockletManager.ensureBlocklet.bind(blockletManager),
270
271
 
271
272
  getBlocklets: blockletManager.list.bind(blockletManager),
@@ -130,7 +130,10 @@ class BlockletRuntimeMonitor extends EventEmitter {
130
130
  appCpu += runtimeInfo.cpuUsage || 0;
131
131
  appMem += runtimeInfo.memoryUsage || 0;
132
132
  } catch (err) {
133
- this.logger.error('failed to get blocklet runtime info', { processId, error: err });
133
+ // component status in db may not sync with pm2 when server has just started
134
+ if (err.code !== 'BLOCKLET_PROCESS_404') {
135
+ this.logger.error('failed to get blocklet runtime info', { processId, error: err });
136
+ }
134
137
  }
135
138
  } else {
136
139
  delete this.data[blockletDid][componentId];
@@ -2,15 +2,13 @@
2
2
  /* eslint-disable no-underscore-dangle */
3
3
  /* eslint-disable consistent-return */
4
4
  const logger = require('@abtnode/logger')('@abtnode/core:states:blocklet-extras');
5
- const { EXPIRED_BLOCKLET_DATA_RETENTION_DAYS } = require('@abtnode/constant');
6
5
  const camelCase = require('lodash/camelCase');
7
6
  const get = require('lodash/get');
8
- const dayjs = require('dayjs');
9
7
 
10
8
  const BaseState = require('./base');
11
9
 
12
10
  const { mergeConfigs, parseConfigs, encryptConfigs } = require('../blocklet/extras');
13
- const { validateAddMeta, validateExpiredInfo } = require('../validators/blocklet-extra');
11
+ const { validateAddMeta } = require('../validators/blocklet-extra');
14
12
 
15
13
  const noop = (k) => (v) => v[k];
16
14
 
@@ -213,19 +211,6 @@ class BlockletExtrasState extends BaseState {
213
211
  return super.findOne({ did }, { did: 1, controller: 1, meta: 1 });
214
212
  }
215
213
 
216
- async updateExpireInfo({ did, expiredAt } = {}) {
217
- const entity = { did, expiredAt };
218
- await validateExpiredInfo(entity);
219
-
220
- return this.updateByDid(did, { expiredAt });
221
- }
222
-
223
- async getExpiredList() {
224
- const deadline = dayjs().subtract(EXPIRED_BLOCKLET_DATA_RETENTION_DAYS, 'days').toISOString();
225
- const docs = await super.find({ expiredAt: { $exists: true } });
226
- return docs.filter((x) => x.controller?.nftId).filter((x) => x.expiredAt <= deadline);
227
- }
228
-
229
214
  async isLauncherSessionConsumed(sessionId) {
230
215
  const count = await super.count({ 'controller.sessionId': sessionId });
231
216
  return count > 0;
@@ -104,7 +104,7 @@ class TeamManager extends EventEmitter {
104
104
  return this.getState(teamDid, 'passport');
105
105
  }
106
106
 
107
- async getConnectedAccount(teamDid) {
107
+ async getConnectedAccountState(teamDid) {
108
108
  return this.getState(teamDid, 'connectedAccount');
109
109
  }
110
110
 
@@ -1953,7 +1953,7 @@ const shouldSkipComponent = (componentDid, whiteList) => {
1953
1953
  return !arr.includes(componentDid);
1954
1954
  };
1955
1955
 
1956
- const shouldCleanExpiredBlocklet = (expirationDate) => {
1956
+ const exceedRedemptionPeriod = (expirationDate) => {
1957
1957
  return dayjs().diff(dayjs(expirationDate), 'day') > EXPIRED_BLOCKLET_DATA_RETENTION_DAYS;
1958
1958
  };
1959
1959
 
@@ -2016,6 +2016,6 @@ module.exports = {
2016
2016
  getProcessState,
2017
2017
  getBlockletStatus,
2018
2018
  shouldSkipComponent,
2019
- shouldCleanExpiredBlocklet,
2020
2019
  getBlockletURLForLauncher,
2020
+ exceedRedemptionPeriod,
2021
2021
  };
@@ -1,6 +1,7 @@
1
1
  const joinUrl = require('url-join');
2
2
  const axios = require('@abtnode/util/lib/axios');
3
3
  const { DEFAULT_IP_DOMAIN, DEFAULT_ADMIN_PATH } = require('@abtnode/constant');
4
+ const logger = require('@abtnode/logger')('@abtnode/core:util:get-accessible-external-node-ip');
4
5
  const { get: getIp } = require('./ip');
5
6
 
6
7
  const getNodeDomain = (ip) => (ip ? DEFAULT_IP_DOMAIN.replace(/^\*/, ip.replace(/\./g, '-')) : '');
@@ -23,6 +24,7 @@ const checkConnected = async ({ ip, nodeInfo }) => {
23
24
  */
24
25
  const fetch = async (nodeInfo) => {
25
26
  const { external } = await getIp();
27
+ logger.info('refresh external ip:', external);
26
28
 
27
29
  if (!external) {
28
30
  return null;
@@ -12,9 +12,13 @@ const resetOwner = async ({ teamManager }) => {
12
12
  const nodeInfo = await states.node.read();
13
13
  const teamDid = nodeInfo.did;
14
14
  const userState = await teamManager.getUserState(teamDid);
15
- const count = await userState.remove({ role: 'owner' });
15
+ const passportState = await teamManager.getPassportState(teamDid);
16
+ const connectedAccountState = await teamManager.getConnectedAccountState(teamDid);
17
+ await passportState.remove({ userDid: nodeInfo.nodeOwner.did });
18
+ await connectedAccountState.remove({ userDid: nodeInfo.nodeOwner.did });
19
+ await userState.remove({ did: nodeInfo.nodeOwner.did });
16
20
  await states.node.updateNodeInfo({ nodeOwner: null });
17
- logger.info('reset node owner', result, count);
21
+ logger.info('reset node owner', result);
18
22
  } catch (err) {
19
23
  // Do nothing
20
24
  }
@@ -69,22 +73,21 @@ const resetCertificates = async ({ certManager }) => {
69
73
  };
70
74
 
71
75
  const resetUsers = async ({ teamManager }) => {
72
- const nodeInfo = await states.node.read();
73
-
74
- const teamDid = nodeInfo.did;
75
- const userState = await teamManager.getUserState(teamDid);
76
- const users = await userState.find({});
76
+ try {
77
+ const nodeInfo = await states.node.read();
77
78
 
78
- let count = 0;
79
- for (const user of users) {
80
- if (nodeInfo.nodeOwner.did !== user.did) {
81
- // eslint-disable-next-line no-await-in-loop
82
- await userState.remove({ did: user.did });
83
- count++;
84
- }
79
+ const teamDid = nodeInfo.did;
80
+ const userState = await teamManager.getUserState(teamDid);
81
+ const passportState = await teamManager.getPassportState(teamDid);
82
+ const connectedAccountState = await teamManager.getConnectedAccountState(teamDid);
83
+ await passportState.remove({ userDid: { $ne: nodeInfo.nodeOwner.did } });
84
+ await connectedAccountState.remove({ userDid: { $ne: nodeInfo.nodeOwner.did } });
85
+ await userState.remove({ did: { $ne: nodeInfo.nodeOwner.did } });
86
+
87
+ logger.info('reset users');
88
+ } catch (error) {
89
+ logger.error('failed reset users', { error });
85
90
  }
86
-
87
- logger.info('reset users', { count });
88
91
  };
89
92
 
90
93
  const resetInvitations = async ({ teamManager }) => {
@@ -13,12 +13,6 @@ const addMeta = Joi.object({
13
13
  controller: blockletController.optional(),
14
14
  }).required();
15
15
 
16
- const updateExpiredInfo = Joi.object({
17
- did: Joi.DID().required(),
18
- expiredAt: Joi.string().required(),
19
- });
20
-
21
16
  module.exports = {
22
17
  validateAddMeta: createValidator(addMeta),
23
- validateExpiredInfo: createValidator(updateExpiredInfo),
24
18
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-3d2b39f7",
6
+ "version": "1.16.11-next-d32a90d4",
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": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.11-next-3d2b39f7",
23
- "@abtnode/certificate-manager": "1.16.11-next-3d2b39f7",
24
- "@abtnode/constant": "1.16.11-next-3d2b39f7",
25
- "@abtnode/cron": "1.16.11-next-3d2b39f7",
26
- "@abtnode/logger": "1.16.11-next-3d2b39f7",
27
- "@abtnode/models": "1.16.11-next-3d2b39f7",
28
- "@abtnode/queue": "1.16.11-next-3d2b39f7",
29
- "@abtnode/rbac": "1.16.11-next-3d2b39f7",
30
- "@abtnode/router-provider": "1.16.11-next-3d2b39f7",
31
- "@abtnode/static-server": "1.16.11-next-3d2b39f7",
32
- "@abtnode/timemachine": "1.16.11-next-3d2b39f7",
33
- "@abtnode/util": "1.16.11-next-3d2b39f7",
22
+ "@abtnode/auth": "1.16.11-next-d32a90d4",
23
+ "@abtnode/certificate-manager": "1.16.11-next-d32a90d4",
24
+ "@abtnode/constant": "1.16.11-next-d32a90d4",
25
+ "@abtnode/cron": "1.16.11-next-d32a90d4",
26
+ "@abtnode/logger": "1.16.11-next-d32a90d4",
27
+ "@abtnode/models": "1.16.11-next-d32a90d4",
28
+ "@abtnode/queue": "1.16.11-next-d32a90d4",
29
+ "@abtnode/rbac": "1.16.11-next-d32a90d4",
30
+ "@abtnode/router-provider": "1.16.11-next-d32a90d4",
31
+ "@abtnode/static-server": "1.16.11-next-d32a90d4",
32
+ "@abtnode/timemachine": "1.16.11-next-d32a90d4",
33
+ "@abtnode/util": "1.16.11-next-d32a90d4",
34
34
  "@arcblock/did": "1.18.80",
35
35
  "@arcblock/did-auth": "1.18.80",
36
36
  "@arcblock/did-ext": "^1.18.80",
@@ -41,10 +41,10 @@
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
42
  "@arcblock/validator": "^1.18.80",
43
43
  "@arcblock/vc": "1.18.80",
44
- "@blocklet/constant": "1.16.11-next-3d2b39f7",
45
- "@blocklet/meta": "1.16.11-next-3d2b39f7",
46
- "@blocklet/sdk": "1.16.11-next-3d2b39f7",
47
- "@did-space/client": "^0.2.112",
44
+ "@blocklet/constant": "1.16.11-next-d32a90d4",
45
+ "@blocklet/meta": "1.16.11-next-d32a90d4",
46
+ "@blocklet/sdk": "1.16.11-next-d32a90d4",
47
+ "@did-space/client": "^0.2.113",
48
48
  "@fidm/x509": "^1.2.1",
49
49
  "@ocap/mcrypto": "1.18.80",
50
50
  "@ocap/util": "1.18.80",
@@ -96,5 +96,5 @@
96
96
  "express": "^4.18.2",
97
97
  "jest": "^27.5.1"
98
98
  },
99
- "gitHead": "d0142bd2d1e49b94dcb5542d78e294a7b2258faa"
99
+ "gitHead": "4f39f40bf7a87767f885d3a06f785d9d76b82da4"
100
100
  }