Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions scripts/src/public/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function checkMigrationNeeded(req: AuthenticatedRequest): Promise<boolean>
const deviceId = req.context.token.deviceId;

if (blockchainVersionHeader === "3") {
logger().info(`kin3 user - dont migrate ${ user.id }`);
logger().debug(`kin3 user - dont migrate ${ user.id }`);
// TODO user gets stuck in kin2
return false; // TODO should we make assertions that the current wallet is on kin3?
}
Expand All @@ -117,7 +117,7 @@ async function checkMigrationNeeded(req: AuthenticatedRequest): Promise<boolean>
}
if (app.config.blockchain_version === "3") {
metrics.migrationTrigger(app.id, "app_on_kin3");
logger().info(`app on kin3 - should migrate ${ user.id }`);
logger().debug(`app on kin3 - should migrate ${ user.id }`);
return true;
}
if (app.shouldApplyGradualMigration() && !await checkedMigrationRecently(user.id)) {
Expand All @@ -130,18 +130,18 @@ async function checkMigrationNeeded(req: AuthenticatedRequest): Promise<boolean>
const walletApplication = await WalletApplication.get(wallet.address);
if (walletApplication && walletApplication.createdDateKin3) {
metrics.migrationTrigger(app.id, "wallet_on_kin3");
logger().info(`current wallet already on kin3 - should migrate ${ wallet.address } ${ user.id }`);
logger().debug(`current wallet already on kin3 - should migrate ${ wallet.address } ${ user.id }`);
return true;
}
const whitelist = await GradualMigrationUser.findOneById(user.id);
if (whitelist && (whitelist.migrationDate || await withinMigrationRateLimit(app.id))) {
await GradualMigrationUser.setAsMigrated([user.id]);
metrics.migrationTrigger(app.id, "gradual_migration");
logger().info(`kin2 user in migration list - should migrate ${ wallet.address } ${ user.id }`);
logger().debug(`kin2 user in migration list - should migrate ${ wallet.address } ${ user.id }`);
return true;
}
}
logger().info(`kin2 user not in migration list - dont migrate ${ user.id }`);
logger().debug(`kin2 user not in migration list - dont migrate ${ user.id }`);
return false;
}

Expand Down
16 changes: 8 additions & 8 deletions scripts/src/public/services/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ async function canSkipMigration(walletAddress: string): Promise<boolean> {
try {
await migrateZeroBalance(walletAddress);
// XXX - this is called by migration servic: await WalletApplication.updateCreatedDate(walletAddress, "createdDateKin3")
logger().info(`can skip migration for ${ walletAddress }`);
logger().debug(`can skip migration for ${ walletAddress }`);
return true;
} catch (e) {
logger().warn("migration on behalf of user failed ", { reason: (e as Error).message });
// fail to call migrate - let user call it instead
}
}
logger().info(`can NOT skip migration for ${ walletAddress }`);
logger().debug(`can NOT skip migration for ${ walletAddress }`);
return false;
}

// return blockchainVersion for a wallet
async function getBlockchainVersionForWallet(wallet: WalletApplication, app: Application): Promise<{ blockchainVersion: BlockchainVersion, shouldMigrate: boolean }> {

if (wallet.createdDateKin3) {
logger().info(`wallet created on kin3 - dont migrate ${ wallet.walletAddress }`);
logger().debug(`wallet created on kin3 - dont migrate ${ wallet.walletAddress }`);
metrics.migrationInfo(app.id, "wallet_on_kin3");
return { blockchainVersion: "3", shouldMigrate: false };
}

if (app.config.blockchain_version === "3") {
logger().info(`app on kin3 - should migrate ${ wallet.walletAddress }`);
logger().debug(`app on kin3 - should migrate ${ wallet.walletAddress }`);
metrics.migrationInfo(app.id, "app_on_kin3");
return { blockchainVersion: "3", shouldMigrate: true };
}
Expand All @@ -67,13 +67,13 @@ async function getBlockchainVersionForWallet(wallet: WalletApplication, app: App
const whitelisted = await GradualMigrationUser.findByWallet(wallet.walletAddress);
if (whitelisted.length > 0 && (whitelisted.some(w => !!w.migrationDate) || await withinMigrationRateLimit(app.id))) {
await GradualMigrationUser.setAsMigrated(whitelisted.map(w => w.userId));
logger().info(`kin2 user on migration list - should migrate ${ wallet.walletAddress }`);
logger().debug(`kin2 user on migration list - should migrate ${ wallet.walletAddress }`);
metrics.migrationInfo(app.id, "gradual_migration");
return { blockchainVersion: "3", shouldMigrate: true };
}
// else, user is not whitelisted or is whitelisted but rate limit applied
}
logger().info(`kin2 user not on migration list - dont migrate ${ wallet.walletAddress }`);
logger().debug(`kin2 user not on migration list - dont migrate ${ wallet.walletAddress }`);
return { blockchainVersion: "2", shouldMigrate: false };
}

Expand All @@ -84,7 +84,7 @@ export const accountStatus = async function(req: AccountStatusRequest, res: expr
if (!app) {
throw NoSuchApp(appId);
}
logger().info(`handling account status request app_id: ${ appId } public_address: ${ publicAddress }`);
logger().debug(`handling account status request app_id: ${ appId } public_address: ${ publicAddress }`);
const wallet = await WalletApplication.get(publicAddress);

let blockchainVersion: BlockchainVersion;
Expand All @@ -99,7 +99,7 @@ export const accountStatus = async function(req: AccountStatusRequest, res: expr
shouldMigrate = false;
}
}
logger().info(`handling account status response app_id: ${ appId } public_address: ${ publicAddress }, ${ shouldMigrate }, ${ blockchainVersion }`);
logger().debug(`handling account status response app_id: ${ appId } public_address: ${ publicAddress }, ${ shouldMigrate }, ${ blockchainVersion }`);

res.status(200).send({
should_migrate: shouldMigrate,
Expand Down