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 e77330d
Show file tree
Hide file tree
Showing 17 changed files with 898 additions and 115 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
Expand Up @@ -58,6 +58,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
CommitReadyResponseMessage,
TransferCompleteRequestMessage,
} from "../../../generated/proto/cacti/satp/v02/stage_3_pb";
import { bufArray2HexStr, getHash, sign } from "../../../gateway-utils";
import {
bufArray2HexStr,
getHash,
sign,
storeLog,
} from "../../../gateway-utils";
import {
getMessageHash,
saveHash,
Expand Down Expand Up @@ -56,6 +61,9 @@ export class Stage3ClientService extends SATPService {
signer: ops.signer,
serviceType: Stage3ClientService.SERVICE_TYPE,
bridgeManager: ops.bridgeManager,
localRepository: ops.localRepository,
remoteRepository: ops.remoteRepository,
pubKey: ops.pubKey,
};
super(commonOptions);

Expand Down Expand Up @@ -125,14 +133,19 @@ export class Stage3ClientService extends SATPService {
getHash(commitPreparationRequestMessage),
);

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

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

Expand Down Expand Up @@ -213,14 +226,20 @@ export class Stage3ClientService extends SATPService {
getHash(commitFinalAssertionRequestMessage),
);

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

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

return commitFinalAssertionRequestMessage;
Expand Down Expand Up @@ -295,14 +314,19 @@ export class Stage3ClientService extends SATPService {
getHash(transferCompleteRequestMessage),
);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { SatpStage0Service } from "../../generated/proto/cacti/satp/v02/stage_0_
import { SatpStage1Service } from "../../generated/proto/cacti/satp/v02/stage_1_connect";
import { SatpStage2Service } from "../../generated/proto/cacti/satp/v02/stage_2_connect";
import { SatpStage3Service } from "../../generated/proto/cacti/satp/v02/stage_3_connect";
import {
ILocalLogRepository,
IRemoteLogRepository,
} from "../../repository/interfaces/repository";

export enum SATPServiceType {
Server = "Server",
Expand All @@ -24,6 +28,9 @@ export type ISATPServiceOptions = {
signer: JsObjectSigner;
serviceType: SATPServiceType;
bridgeManager?: SATPBridgesManager;
localRepository: ILocalLogRepository;
remoteRepository: IRemoteLogRepository;
pubKey: string;
};

export interface SATPServiceStatic {
Expand Down Expand Up @@ -56,13 +63,19 @@ export abstract class SATPService {
readonly serviceType: SATPServiceType;
private readonly signer: JsObjectSigner;
readonly serviceName: string;
protected localRepository: ILocalLogRepository;
protected remoteRepository: IRemoteLogRepository;
protected pubKey: string;

constructor(ops: ISATPServiceOptions) {
this.logger = LoggerProvider.getOrCreate(ops.loggerOptions);
this.serviceName = ops.serviceName;
this.serviceType = ops.serviceType;
this.stage = ops.stage;
this.signer = ops.signer;
this.localRepository = ops.localRepository;
this.remoteRepository = ops.remoteRepository;
this.pubKey = ops.pubKey;
this.logger.trace(`Signer logger level: ${this.signer.options.logLevel}`);
}

Expand All @@ -89,4 +102,12 @@ export abstract class SATPService {
public get Signer(): JsObjectSigner {
return this.signer;
}

public get LocalRepository(): ILocalLogRepository {
return this.localRepository;
}

public get RemoteRepository(): IRemoteLogRepository {
return this.remoteRepository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export class Stage0ServerService extends SATPService {
serviceName: ops.serviceName,
signer: ops.signer,
serviceType: Stage0ServerService.SERVICE_TYPE,
localRepository: ops.localRepository,
remoteRepository: ops.remoteRepository,
pubKey: ops.pubKey,
};
super(commonOptions);
if (ops.bridgeManager == undefined) {
Expand Down
Loading

0 comments on commit e77330d

Please sign in to comment.