Skip to content

Commit

Permalink
feat: add satp logging in all satges
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh01000100 <[email protected]>
  • Loading branch information
Yogesh01000100 committed Dec 2, 2024
1 parent 3039f23 commit 188a2d3
Show file tree
Hide file tree
Showing 16 changed files with 520 additions and 128 deletions.
6 changes: 5 additions & 1 deletion packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module.exports = {
development: {
client: "sqlite3",
connection: {
filename: path.join(__dirname, "data", "/.dev-" + uuidv4() + ".sqlite3"),
filename: path.resolve(
__dirname,
"data",
".dev.local-" + uuidv4() + ".sqlite3",
),
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import { IntegrationsEndpointV1 } from "../web-services/integrations-endpoint";
import { executeGetHealthCheck } from "./admin/get-healthcheck-handler-service";
import { executeGetStatus } from "./admin/get-status-handler-service";
import { executeTransact } from "./transaction/transact-handler-service";
import {
ILocalLogRepository,
IRemoteLogRepository,
} from "../repository/interfaces/repository";

export interface BLODispatcherOptions {
logger: Logger;
Expand All @@ -41,6 +45,8 @@ export interface BLODispatcherOptions {
signer: JsObjectSigner;
bridgesManager: SATPBridgesManager;
pubKey: string;
localRepository: ILocalLogRepository;
remoteRepository: IRemoteLogRepository;
}

export class BLODispatcher {
Expand All @@ -54,19 +60,26 @@ export class BLODispatcher {
private manager: SATPManager;
private orchestrator: GatewayOrchestrator;
private bridgeManager: SATPBridgesManager;
private localRepository: ILocalLogRepository;
private remoteRepository: IRemoteLogRepository;

constructor(public readonly options: BLODispatcherOptions) {
const fnTag = `${BLODispatcher.CLASS_NAME}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);

this.level = this.options.logLevel || "INFO";
this.label = this.className;
this.logger = LoggerProvider.getOrCreate({ level: this.level, label: this.label });
this.logger = LoggerProvider.getOrCreate({
level: this.level,
label: this.label,
});
this.instanceId = options.instanceId;
this.logger.info(`Instantiated ${this.className} OK`);
this.orchestrator = options.orchestrator;
const signer = options.signer;
const ourGateway = this.orchestrator.ourGateway;
this.localRepository = options.localRepository;
this.remoteRepository = options.remoteRepository;

this.bridgeManager = options.bridgesManager;

Expand All @@ -78,6 +91,8 @@ export class BLODispatcher {
bridgeManager: this.bridgeManager,
orchestrator: this.orchestrator,
pubKey: options.pubKey,
localRepository: this.localRepository,
remoteRepository: this.remoteRepository,
};

this.manager = new SATPManager(SATPManagerOpts);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { bufArray2HexStr, getHash, sign } from "../../../gateway-utils";
import {
bufArray2HexStr,
getHash,
sign,
storeLog,
} from "../../../gateway-utils";
import {
MessageType,
WrapAssertionClaim,
Expand Down Expand Up @@ -58,6 +63,9 @@ export class Stage0ClientService extends SATPService {
serviceName: ops.serviceName,
signer: ops.signer,
serviceType: Stage0ClientService.SERVICE_TYPE,
localRepository: ops.localRepository,
remoteRepository: ops.remoteRepository,
pubKey: ops.pubKey,
};
super(commonOptions);
if (ops.bridgeManager == undefined) {
Expand Down Expand Up @@ -109,6 +117,20 @@ export class Stage0ClientService extends SATPService {
getHash(newSessionRequestMessage),
);

await storeLog(
{
sessionID: sessionData.id,
type: "newSessionRequest",
operation: "create",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);

this.Log.info(`${fnTag}, sending NewSessionRequest...`);

return newSessionRequestMessage;
Expand Down Expand Up @@ -270,6 +292,20 @@ export class Stage0ClientService extends SATPService {
getHash(preSATPTransferRequest),
);

await storeLog(
{
sessionID: sessionData.id,
type: "preSATPTransferRequest",
operation: "create",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);

this.Log.info(`${fnTag}, sending PreSATPTransferRequest...`);

return preSATPTransferRequest;
Expand Down Expand Up @@ -323,6 +359,19 @@ export class Stage0ClientService extends SATPService {
sessionData.senderWrapAssertionClaim.signature = bufArray2HexStr(
sign(this.Signer, sessionData.senderWrapAssertionClaim.receipt),
);
await storeLog(
{
sessionID: sessionData.id,
type: "wrapToken",
operation: "execute",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);
} catch (error) {
this.logger.debug(`Crash in ${fnTag}`, error);
throw new FailedToProcessError(fnTag, "WrapToken");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
TransferClaims,
NetworkCapabilities,
} from "../../../generated/proto/cacti/satp/v02/common/message_pb";
import { bufArray2HexStr, getHash, sign } from "../../../gateway-utils";
import {
bufArray2HexStr,
getHash,
sign,
storeLog,
} from "../../../gateway-utils";
import {
getMessageHash,
saveHash,
Expand Down Expand Up @@ -51,6 +56,9 @@ export class Stage1ClientService extends SATPService {
serviceName: ops.serviceName,
signer: ops.signer,
serviceType: Stage1ClientService.SERVICE_TYPE,
localRepository: ops.localRepository,
remoteRepository: ops.remoteRepository,
pubKey: ops.pubKey,
};
super(commonOptions);
}
Expand Down Expand Up @@ -196,14 +204,19 @@ export class Stage1ClientService extends SATPService {
getHash(transferProposalRequestMessage),
);

/*
await storeLog(gateway, {
sessionID: sessionID,
type: "transferProposalRequest",
operation: "validate",
data: safeStableStringify(sessionData),
});
*/
await storeLog(
{
sessionID: sessionData.id,
type: "transferProposalRequest",
operation: "validate",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);
this.Log.info(`${fnTag}, sending TransferProposalRequest...`);

return transferProposalRequestMessage;
Expand Down Expand Up @@ -267,14 +280,20 @@ export class Stage1ClientService extends SATPService {
getHash(transferCommenceRequestMessage),
);

/*
await storeLog(gateway, {
sessionID: sessionData.id,
type: "transferCommenceRequest",
operation: "validate",
data: safeStableStringify(sessionData),
});
*/
await storeLog(
{
sessionID: sessionData.id,
type: "transferCommenceRequest",
operation: "validate",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);

this.Log.info(`${fnTag}, sending TransferCommenceRequest...`);

return transferCommenceRequestMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
MessageType,
} from "../../../generated/proto/cacti/satp/v02/common/message_pb";
import { LockAssertionRequestMessage } from "../../../generated/proto/cacti/satp/v02/stage_2_pb";
import { bufArray2HexStr, getHash, sign } from "../../../gateway-utils";
import {
bufArray2HexStr,
getHash,
sign,
storeLog,
} from "../../../gateway-utils";
import {
getMessageHash,
saveHash,
Expand Down Expand Up @@ -49,6 +54,9 @@ export class Stage2ClientService extends SATPService {
signer: ops.signer,
serviceType: Stage2ClientService.SERVICE_TYPE,
bridgeManager: ops.bridgeManager,
localRepository: ops.localRepository,
remoteRepository: ops.remoteRepository,
pubKey: ops.pubKey,
};
super(commonOptions);

Expand Down Expand Up @@ -140,14 +148,20 @@ export class Stage2ClientService extends SATPService {
getHash(lockAssertionRequestMessage),
);

/*
await storeLog(gateway, {
sessionID: sessionData.id,
type: "lockAssertionRequest",
operation: "lock",
data: safeStableStringify(sessionData),
});
*/
await storeLog(
{
sessionID: sessionData.id,
type: "lockAssertionRequest",
operation: "lock",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);

this.Log.info(`${fnTag}, sending LockAssertionMessage...`);

return lockAssertionRequestMessage;
Expand Down Expand Up @@ -240,6 +254,19 @@ export class Stage2ClientService extends SATPService {
sessionData.lockAssertionClaim.signature = bufArray2HexStr(
sign(this.Signer, sessionData.lockAssertionClaim.receipt),
);
await storeLog(
{
sessionID: sessionData.id,
type: "lockAssertionRequest",
operation: "lock",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
},
this.localRepository,
this.remoteRepository,
this.Signer,
this.pubKey,
);
} catch (error) {
this.logger.debug(`Crash in ${fnTag}`, error);
throw new FailedToProcessError(fnTag, "LockAsset");
Expand Down
Loading

0 comments on commit 188a2d3

Please sign in to comment.