Skip to content

Commit dc45c2e

Browse files
committed
feat(actors): implement V2 actor system with comprehensive RPC server and supervision
This commit introduces the V2 actor system, consolidating various actor functionalities and implementing a new RPC server architecture. Key changes include: - Added `rpc_v2.rs` for actor-based RPC server handling, enabling message-driven interactions with ChainActor, EngineActor, and StorageActor. - Implemented `RootSupervisor` for lifecycle management and fault tolerance across all actors. - Enhanced message passing patterns between actors, including new RPC-specific messages for block retrieval and status checks. - Updated `app.rs` to initialize the V2 actor system and start the RPC server. - Introduced extensive integration tests to validate cross-actor communication and end-to-end workflows. These enhancements streamline the architecture, improve maintainability, and prepare the system for production deployment.
1 parent bc2d681 commit dc45c2e

File tree

16 files changed

+3698
-389
lines changed

16 files changed

+3698
-389
lines changed

Cargo.lock

Lines changed: 21 additions & 238 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/actors/chain/actor.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,39 @@ impl Handler<HealthCheck> for ChainActor {
777777
details,
778778
}
779779
}
780-
}
780+
}
781+
782+
// === RPC Message Handlers ===
783+
784+
/// Handler for GetBlockByHeight RPC message
785+
impl Handler<GetBlockByHeight> for ChainActor {
786+
type Result = ResponseActFuture<Self, Result<Option<SignedConsensusBlock>, ChainError>>;
787+
788+
fn handle(&mut self, msg: GetBlockByHeight, _: &mut Context<Self>) -> Self::Result {
789+
Box::pin(async move {
790+
self.get_block_by_height(msg.height).await
791+
}.into_actor(self))
792+
}
793+
}
794+
795+
/// Handler for GetBlockByHash RPC message
796+
impl Handler<GetBlockByHash> for ChainActor {
797+
type Result = ResponseActFuture<Self, Result<Option<SignedConsensusBlock>, ChainError>>;
798+
799+
fn handle(&mut self, msg: GetBlockByHash, _: &mut Context<Self>) -> Self::Result {
800+
Box::pin(async move {
801+
self.get_block_by_hash(msg.hash).await
802+
}.into_actor(self))
803+
}
804+
}
805+
806+
/// Handler for GetBlockCount RPC message
807+
impl Handler<GetBlockCount> for ChainActor {
808+
type Result = ResponseActFuture<Self, Result<u64, ChainError>>;
809+
810+
fn handle(&mut self, msg: GetBlockCount, _: &mut Context<Self>) -> Self::Result {
811+
Box::pin(async move {
812+
Ok(self.chain_state.height)
813+
}.into_actor(self))
814+
}
815+
}

app/src/actors/chain/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::time::Duration;
88
use actor_system::SupervisionConfig;
99
use super::state::FederationConfig;
10+
use lighthouse_wrapper::bls::SecretKey;
1011

1112
/// Configuration for ChainActor behavior and performance
1213
#[derive(Debug, Clone)]

app/src/actors/chain/messages.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,4 +1153,27 @@ impl Default for ChainStatus {
11531153
},
11541154
}
11551155
}
1156-
}
1156+
}
1157+
1158+
// === RPC-specific messages ===
1159+
1160+
/// Message to get a block by its height (for RPC)
1161+
#[derive(Message, Debug, Clone)]
1162+
#[rtype(result = "Result<Option<SignedConsensusBlock>, ChainError>")]
1163+
pub struct GetBlockByHeight {
1164+
/// Block height to retrieve
1165+
pub height: u64,
1166+
}
1167+
1168+
/// Message to get a block by its hash (for RPC)
1169+
#[derive(Message, Debug, Clone)]
1170+
#[rtype(result = "Result<Option<SignedConsensusBlock>, ChainError>")]
1171+
pub struct GetBlockByHash {
1172+
/// Block hash to retrieve
1173+
pub hash: Hash256,
1174+
}
1175+
1176+
/// Message to get the current block count (for RPC)
1177+
#[derive(Message, Debug, Clone)]
1178+
#[rtype(result = "Result<u64, ChainError>")]
1179+
pub struct GetBlockCount;

app/src/actors/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ pub mod bridge; // Bridge actor system
2323
pub mod network; // Network actor system (SyncActor, NetworkActor, PeerActor)
2424
pub mod sync; // Sync actor system
2525
pub mod storage; // Organized storage actor module
26+
pub mod supervisor; // Root supervisor for all actors
27+
pub mod shared; // Shared structures like ActorAddresses
28+
29+
#[cfg(test)]
30+
pub mod tests; // V2 Actor system integration tests
2631

2732
pub use chain::*; // Import from organized module
2833
pub use engine::*; // Import from organized engine module
2934
pub use network::*; // New network actor system
3035
pub use storage::*; // Import from organized storage module
31-
pub use bridge::actors::stream::*; // Export new consolidated StreamActor
36+
pub use bridge::actors::stream::*; // Export new consolidated StreamActor
37+
pub use supervisor::*; // Export supervisor
38+
pub use shared::*; // Export shared structures

0 commit comments

Comments
 (0)