-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(satp-hermes): add crash recovery & rollback protocol
1. Implemented recovery & rollback using RPC-based message handlers. 2. Added rollback strategies for all SATP stages. 3. Integrated database log management for recovery and rollback. 4. Added cron jobs for scheduled crash detection and recovery initiation. Co-authored-by: Rafael Belchior <[email protected]> Co-authored-by: Carlos Amaro <[email protected]> Signed-off-by: Yogesh01000100 <[email protected]> chore(satp-hermes): improve DB management Signed-off-by: Rafael Belchior <[email protected]> chore(satp-hermes): crash recovery architecture Signed-off-by: Rafael Belchior <[email protected]> fix(recovery): enhance crash recovery and rollback implementation Signed-off-by: Yogesh01000100 <[email protected]> refactor(recovery): consolidate logic and improve SATP message handling Signed-off-by: Yogesh01000100 <[email protected]> feat(recovery): add rollback implementations Signed-off-by: Yogesh01000100 <[email protected]> fix: correct return types and inits Signed-off-by: Yogesh01000100 <[email protected]> fix: add unit tests and resolve rollbackstate Signed-off-by: Yogesh01000100 <[email protected]> feat: add function processing logs from g2 Signed-off-by: Yogesh01000100 <[email protected]> feat: add cron schedule for periodic crash checks Signed-off-by: Yogesh01000100 <[email protected]> fix: resolve rollback condition and add tests Signed-off-by: Yogesh01000100 <[email protected]> feat: add orchestrator communication layer using connect-RPC Signed-off-by: Yogesh01000100 <[email protected]> feat: add rollback protocol rpc Signed-off-by: Yogesh01000100 <[email protected]> fix: handle server log synchronization Signed-off-by: Yogesh01000100 <[email protected]> fix: resolve gol errors, add unit tests Signed-off-by: Yogesh01000100 <[email protected]> fix: handle server-side rollback Signed-off-by: Yogesh01000100 <[email protected]> fix: resolve networkId in rollback strategies Signed-off-by: Yogesh01000100 <[email protected]>
- Loading branch information
1 parent
15eee79
commit 503658c
Showing
38 changed files
with
6,566 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...ges/cactus-plugin-satp-hermes/src/main/typescript/core/crash-management/client-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { | ||
RecoverMessage, | ||
RecoverMessageSchema, | ||
RecoverSuccessMessage, | ||
RecoverSuccessMessageSchema, | ||
RollbackMessage, | ||
RollbackMessageSchema, | ||
RollbackState, | ||
} from "../../../typescript/generated/proto/cacti/satp/v02/crash_recovery_pb"; | ||
import { JsObjectSigner, Logger } from "@hyperledger/cactus-common"; | ||
import { SATPSession } from "../satp-session"; | ||
import { create } from "@bufbuild/protobuf"; | ||
import { SATPLogger } from "../../logging"; | ||
import { stringify as safeStableStringify } from "safe-stable-stringify"; | ||
import { bufArray2HexStr, sign } from "../../gateway-utils"; | ||
|
||
export class CrashRecoveryClientService { | ||
constructor( | ||
private readonly dbLogger: SATPLogger, | ||
private readonly log: Logger, | ||
private readonly signer: JsObjectSigner, | ||
) { | ||
this.log = log; | ||
this.log.trace(`Initialized ${CrashRecoveryClientService.name}`); | ||
} | ||
|
||
public async createRecoverMessage( | ||
session: SATPSession, | ||
): Promise<RecoverMessage> { | ||
const fnTag = `${CrashRecoveryClientService.name}#createRecoverMessage`; | ||
this.log.debug( | ||
`${fnTag} - Creating RecoverMessage for sessionId: ${session.getSessionId()}`, | ||
); | ||
|
||
const sessionData = session.getClientSessionData(); | ||
|
||
const recoverMessage = create(RecoverMessageSchema, { | ||
sessionId: session.getSessionId(), | ||
messageType: "urn:ietf:SATP-2pc:msgtype:recover-msg", | ||
satpPhase: "", | ||
sequenceNumber: Number(sessionData.lastSequenceNumber), | ||
isBackup: false, | ||
newIdentityPublicKey: "", | ||
lastEntryTimestamp: BigInt(sessionData.lastMessageReceivedTimestamp), | ||
senderSignature: "", | ||
}); | ||
|
||
const signature = bufArray2HexStr( | ||
sign(this.signer, safeStableStringify(recoverMessage)), | ||
); | ||
|
||
recoverMessage.senderSignature = signature; | ||
|
||
await this.dbLogger.persistLogEntry({ | ||
sessionID: recoverMessage.sessionId, | ||
type: "urn:ietf:SATP-2pc:msgtype:recover-msg", | ||
operation: "done", | ||
data: safeStableStringify(sessionData), | ||
sequenceNumber: Number(sessionData.lastSequenceNumber), | ||
}); | ||
this.log.debug(`${fnTag} - RecoverMessage created:`, recoverMessage); | ||
|
||
return recoverMessage; | ||
} | ||
|
||
public async createRecoverSuccessMessage( | ||
session: SATPSession, | ||
): Promise<RecoverSuccessMessage> { | ||
const fnTag = `${CrashRecoveryClientService.name}#createRecoverSuccessMessage`; | ||
this.log.debug( | ||
`${fnTag} - Creating RecoverSuccessMessage for sessionId: ${session.getSessionId()}`, | ||
); | ||
const sessionData = session.getClientSessionData(); | ||
const recoverSuccessMessage = create(RecoverSuccessMessageSchema, { | ||
sessionId: session.getSessionId(), | ||
messageType: "urn:ietf:SATP-2pc:msgtype:recover-success-msg", | ||
hashRecoverUpdateMessage: "", | ||
success: true, | ||
entriesChanged: [], | ||
senderSignature: "", | ||
}); | ||
|
||
const signature = bufArray2HexStr( | ||
sign(this.signer, safeStableStringify(recoverSuccessMessage)), | ||
); | ||
|
||
recoverSuccessMessage.senderSignature = signature; | ||
|
||
await this.dbLogger.persistLogEntry({ | ||
sessionID: recoverSuccessMessage.sessionId, | ||
type: "urn:ietf:SATP-2pc:msgtype:recover-success-msg", | ||
operation: "done", | ||
data: safeStableStringify(sessionData), | ||
sequenceNumber: Number(sessionData.lastSequenceNumber), | ||
}); | ||
this.log.debug( | ||
`${fnTag} - RecoverSuccessMessage created:`, | ||
recoverSuccessMessage, | ||
); | ||
|
||
return recoverSuccessMessage; | ||
} | ||
|
||
public async createRollbackMessage( | ||
session: SATPSession, | ||
rollbackState: RollbackState, | ||
): Promise<RollbackMessage> { | ||
const fnTag = `${CrashRecoveryClientService.name}#createRollbackMessage`; | ||
this.log.debug( | ||
`${fnTag} - Creating RollbackMessage for sessionId: ${session.getSessionId()}`, | ||
); | ||
const sessionData = session.getClientSessionData(); | ||
const rollbackMessage = create(RollbackMessageSchema, { | ||
sessionId: session.getSessionId(), | ||
messageType: "urn:ietf:SATP-2pc:msgtype:rollback-msg", | ||
success: rollbackState.status === "COMPLETED", | ||
actionsPerformed: rollbackState.rollbackLogEntries.map( | ||
(entry) => entry.action, | ||
), | ||
proofs: [], | ||
senderSignature: "", | ||
}); | ||
|
||
const signature = bufArray2HexStr( | ||
sign(this.signer, safeStableStringify(rollbackMessage)), | ||
); | ||
|
||
rollbackMessage.senderSignature = signature; | ||
|
||
await this.dbLogger.persistLogEntry({ | ||
sessionID: rollbackMessage.sessionId, | ||
type: "urn:ietf:SATP-2pc:msgtype:rollback-msg", | ||
operation: "done", | ||
data: safeStableStringify(sessionData), | ||
sequenceNumber: Number(sessionData.lastSequenceNumber), | ||
}); | ||
this.log.debug(`${fnTag} - RollbackMessage created:`, rollbackMessage); | ||
|
||
return rollbackMessage; | ||
} | ||
} |
Oops, something went wrong.