-
Notifications
You must be signed in to change notification settings - Fork 287
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 <rafael.belchior@tecnico.ulisboa.pt> Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> chore(satp-hermes): improve DB management Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt> chore(satp-hermes): crash recovery architecture Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt> fix(recovery): enhance crash recovery and rollback implementation Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> refactor(recovery): consolidate logic and improve SATP message handling Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat(recovery): add rollback implementations Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: correct return types and inits Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> Co-authored-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt> fix: add unit tests and resolve rollbackstate Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat: add function processing logs from g2 Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat: add cron schedule for periodic crash checks Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: resolve rollback condition and add tests Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat: add orchestrator communication layer using connect-RPC Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat: add rollback protocol rpc Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: handle server log synchronization Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: resolve gol errors, add unit tests Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: handle server-side rollback Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: resolve networkId in rollback strategies Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com>
- Loading branch information
1 parent
7f99648
commit 222d088
Showing
37 changed files
with
5,996 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
139 changes: 139 additions & 0 deletions
139
...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,139 @@ | ||
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: [], | ||
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.