Skip to content

Commit

Permalink
feat: add crash recovery and knex config for production
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh01000100 <[email protected]>
  • Loading branch information
Yogesh01000100 committed Aug 23, 2024
1 parent c21957b commit e027214
Show file tree
Hide file tree
Showing 25 changed files with 963 additions and 18 deletions.
17 changes: 17 additions & 0 deletions packages/cactus-plugin-satp-hermes/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:
db:
image: postgres:13
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_HOST: ${DB_HOST}
PGPORT: ${DB_PORT}
ports:
- "${DB_PORT}:5432"
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata:
8 changes: 7 additions & 1 deletion packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
"watch": "tsc --build --watch",
"forge": "forge build ./src/solidity/*.sol --out ./src/solidity/generated",
"forge:test": "forge build ./src/test/solidity/contracts/*.sol --out ./src/test/solidity/generated",
"forge:all": "run-s 'forge' 'forge:test'"
"db:start": "docker-compose up -d",
"db:stop": "docker-compose down",
"db:reset": "docker-compose down -v",
"migrate": "knex migrate:latest --env production --knexfile src/knex/knexfile.js",
"seed": "knex seed:run --env development --knexfile src/knex/knexfile.js"
},
"jest": {
"moduleNameMapper": {
Expand Down Expand Up @@ -117,6 +121,7 @@
"kubo-rpc-client": "3.0.1",
"npm-run-all": "4.1.5",
"openzeppelin-solidity": "3.4.2",
"pg": "^8.8.0",
"secp256k1": "4.0.3",
"socket.io": "4.6.2",
"sqlite3": "5.1.5",
Expand All @@ -137,6 +142,7 @@
"@types/express": "4.17.21",
"@types/fs-extra": "11.0.4",
"@types/node": "18.18.2",
"@types/pg": "8.6.5",
"@types/swagger-ui-express": "4.1.6",
"@types/tape": "4.13.4",
"@types/uuid": "10.0.0",
Expand Down
17 changes: 16 additions & 1 deletion packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import dotenv from "dotenv";

dotenv.config({ path: path.resolve(__dirname, "../../.env") });

// default configuration for knex
module.exports = {
development: {
client: "sqlite3",
Expand All @@ -13,4 +15,17 @@ module.exports = {
},
useNullAsDefault: true,
},
production: {
client: "pg",
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
},
},
};
17 changes: 16 additions & 1 deletion packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import dotenv from "dotenv";

dotenv.config({ path: path.resolve(__dirname, "../../.env") });

// default configuration for knex
module.exports = {
development: {
client: "sqlite3",
Expand All @@ -13,4 +15,17 @@ module.exports = {
},
useNullAsDefault: true,
},
production: {
client: "pg",
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,64 @@ service CrashRecovery {
// util RPCs

// step RPCs
rpc RecoverV2Message (RecoverMessage) returns (RecoverUpdateMessage);
rpc RecoverV2UpdateMessage (RecoverUpdateMessage) returns (RecoverSuccessMessage);
rpc RecoverV2SuccessMessage (RecoverSuccessMessage) returns (google.protobuf.Empty) {};
rpc RollbackV2Message (RollbackMessage) returns (RollbackAckMessage);
rpc RollbackV2AckMessage (RollbackAckMessage) returns (google.protobuf.Empty) {};
}

message RecoverMessage {
string sessionId = 1;
string messageType = 2;
string satpPhase = 3;
int32 sequenceNumber = 4;
bool isBackup = 5;
string newIdentityPublicKey = 6;
int64 lastEntryTimestamp = 7;
string senderSignature = 8;
}

message RecoverUpdateMessage {
string sessionId = 1;
string messageType = 2;
string hashRecoverMessage = 3;
repeated LogEntry recoveredLogs = 4;
string senderSignature = 5;
}

message RecoverSuccessMessage {
string sessionId = 1;
string messageType = 2;
string hashRecoverUpdateMessage = 3;
bool success = 4;
repeated string entriesChanged = 5;
string senderSignature = 6;
}

message RollbackMessage {
string sessionId = 1;
string messageType = 2;
bool success = 3;
repeated string actionsPerformed = 4;
repeated string proofs = 5;
string senderSignature = 6;
}

message RollbackAckMessage {
string sessionId = 1;
string messageType = 2;
bool success = 3;
repeated string actionsPerformed = 4;
repeated string proofs = 5;
string senderSignature = 6;
}

message LogEntry {
string key=1;
string sessionId=2;
string data=3;
string type=4;
string operation=5;
string timestamp=6;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
RecoverMessage,
RecoverUpdateMessage,
RecoverSuccessMessage,
RollbackMessage,
} from "../../generated/proto/cacti/satp/v02/crash_recovery_pb";
import { SessionData } from "../../generated/proto/cacti/satp/v02/common/session_pb";

export class CrashRecoveryClientService {
createRecoverMessage(sessionData: SessionData): RecoverMessage {}

async sendRecoverMessage(
message: RecoverMessage,
): Promise<RecoverUpdateMessage> {}

async sendRecoverUpdateMessage(
message: RecoverUpdateMessage,
): Promise<RecoverSuccessMessage> {}

createRollbackMessage(sessionData: SessionData): RollbackMessage {}
}
Loading

0 comments on commit e027214

Please sign in to comment.