Skip to content

Commit d18ffd9

Browse files
committed
feat(bridge): integrate gRPC support and enhance StreamActor functionality
This commit introduces gRPC support for the Bridge governance communication, enhancing the StreamActor's capabilities. Key changes include: - Added new protobuf definitions for governance-related messages, including StreamRequest and StreamResponse. - Updated StreamActor to generate gRPC code from the new protobuf definitions, facilitating communication with governance services. - Refactored message handling in StreamActor to support bidirectional streaming and health check endpoints. - Improved error handling and logging throughout the StreamActor lifecycle. These enhancements improve the overall architecture of the bridge system, enabling more robust and efficient governance interactions.
1 parent 03cd3de commit d18ffd9

File tree

23 files changed

+2115
-1399
lines changed

23 files changed

+2115
-1399
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
use std::env;
2-
use std::path::PathBuf;
3-
41
fn main() -> Result<(), Box<dyn std::error::Error>> {
5-
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
6-
7-
// Configure tonic-build
2+
// Generate gRPC code from protobuf definitions
83
tonic_build::configure()
9-
.build_server(false) // We're only a client
10-
.build_client(true) // Generate client code
11-
.out_dir(&out_dir) // Output directory
4+
.build_server(true)
5+
.build_client(true)
6+
.out_dir("src/generated")
127
.compile(
13-
&["proto/governance.proto"], // Proto files
14-
&["proto/"], // Include directories
8+
&["proto/governance/bridge/v1/governance.proto"],
9+
&["proto"],
1510
)?;
1611

17-
// Tell Cargo to recompile if proto files change
18-
println!("cargo:rerun-if-changed=proto/governance.proto");
19-
println!("cargo:rerun-if-changed=proto/");
20-
2112
Ok(())
2213
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
syntax = "proto3";
2+
3+
package governance.bridge.v1;
4+
5+
// Bridge governance gRPC service
6+
service GovernanceBridge {
7+
// Bidirectional streaming for governance communication
8+
rpc BidirectionalStream(stream StreamRequest) returns (stream StreamResponse);
9+
10+
// Health check endpoint
11+
rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
12+
}
13+
14+
// Stream request message
15+
message StreamRequest {
16+
string request_id = 1;
17+
RequestType request_type = 2;
18+
bytes payload = 3;
19+
uint64 timestamp = 4;
20+
Priority priority = 5;
21+
}
22+
23+
// Stream response message
24+
message StreamResponse {
25+
string response_id = 1;
26+
ResponseType response_type = 2;
27+
bytes payload = 3;
28+
uint64 timestamp = 4;
29+
bool success = 5;
30+
optional string error_message = 6;
31+
}
32+
33+
// Request types
34+
enum RequestType {
35+
REQUEST_TYPE_UNSPECIFIED = 0;
36+
REQUEST_TYPE_PEGOUT_SIGNATURE = 1;
37+
REQUEST_TYPE_FEDERATION_UPDATE = 2;
38+
REQUEST_TYPE_HEARTBEAT = 3;
39+
REQUEST_TYPE_STATUS_CHECK = 4;
40+
REQUEST_TYPE_NODE_REGISTRATION = 5;
41+
REQUEST_TYPE_PEGIN_NOTIFICATION = 6;
42+
}
43+
44+
// Response types
45+
enum ResponseType {
46+
RESPONSE_TYPE_UNSPECIFIED = 0;
47+
RESPONSE_TYPE_SIGNATURE_RESPONSE = 1;
48+
RESPONSE_TYPE_FEDERATION_UPDATE_ACK = 2;
49+
RESPONSE_TYPE_HEARTBEAT_RESPONSE = 3;
50+
RESPONSE_TYPE_STATUS_RESPONSE = 4;
51+
RESPONSE_TYPE_REGISTRATION_ACK = 5;
52+
RESPONSE_TYPE_NOTIFICATION_ACK = 6;
53+
RESPONSE_TYPE_ERROR = 7;
54+
}
55+
56+
// Priority levels
57+
enum Priority {
58+
PRIORITY_UNSPECIFIED = 0;
59+
PRIORITY_LOW = 1;
60+
PRIORITY_NORMAL = 2;
61+
PRIORITY_HIGH = 3;
62+
PRIORITY_CRITICAL = 4;
63+
}
64+
65+
// Health check messages
66+
message HealthCheckRequest {
67+
string service = 1;
68+
}
69+
70+
message HealthCheckResponse {
71+
HealthCheckStatus status = 1;
72+
string message = 2;
73+
}
74+
75+
enum HealthCheckStatus {
76+
HEALTH_CHECK_STATUS_UNSPECIFIED = 0;
77+
HEALTH_CHECK_STATUS_SERVING = 1;
78+
HEALTH_CHECK_STATUS_NOT_SERVING = 2;
79+
}
80+
81+
// PegOut signature request payload
82+
message PegOutSignatureRequest {
83+
string pegout_id = 1;
84+
string transaction_hex = 2;
85+
string destination_address = 3;
86+
uint64 amount = 4;
87+
uint64 fee = 5;
88+
}
89+
90+
// PegOut signature response payload
91+
message PegOutSignatureResponse {
92+
string pegout_id = 1;
93+
repeated string signatures = 2;
94+
string approval_status = 3;
95+
repeated string responding_nodes = 4;
96+
}
97+
98+
// Federation update payload
99+
message FederationUpdate {
100+
string update_id = 1;
101+
string update_type = 2;
102+
uint64 effective_height = 3;
103+
repeated FederationMember members = 4;
104+
uint32 threshold = 5;
105+
}
106+
107+
// Federation member info
108+
message FederationMember {
109+
string alys_address = 1;
110+
string bitcoin_pubkey = 2;
111+
uint32 weight = 3;
112+
bool active = 4;
113+
}
114+
115+
// Heartbeat payload
116+
message Heartbeat {
117+
uint64 timestamp = 1;
118+
string node_id = 2;
119+
string status = 3;
120+
}
121+
122+
// PegIn notification payload
123+
message PegInNotification {
124+
string transaction_id = 1;
125+
string deposit_address = 2;
126+
uint64 amount = 3;
127+
uint32 confirmations = 4;
128+
string recipient_address = 5;
129+
}

0 commit comments

Comments
 (0)