Add shard config in status messgae

This commit is contained in:
boqiu 2024-11-22 14:50:22 +08:00
parent bfe434972d
commit a37836a91d
4 changed files with 17 additions and 14 deletions

View File

@ -399,9 +399,7 @@ mod tests {
use std::io::Write; use std::io::Write;
fn status_message() -> StatusMessage { fn status_message() -> StatusMessage {
StatusMessage { Default::default()
data: Default::default(),
}
} }
fn ping_message() -> Ping { fn ping_message() -> Ping {
@ -570,10 +568,7 @@ mod tests {
assert_eq!(stream_identifier.len(), 10); assert_eq!(stream_identifier.len(), 10);
// Status message is 84 bytes uncompressed. `max_compressed_len` is 32 + 84 + 84/6 = 130. // Status message is 84 bytes uncompressed. `max_compressed_len` is 32 + 84 + 84/6 = 130.
let status_message_bytes = StatusMessage { let status_message_bytes = StatusMessage::default().as_ssz_bytes();
data: Default::default(),
}
.as_ssz_bytes();
let mut uvi_codec: Uvi<usize> = Uvi::default(); let mut uvi_codec: Uvi<usize> = Uvi::default();
let mut dst = BytesMut::with_capacity(1024); let mut dst = BytesMut::with_capacity(1024);

View File

@ -69,9 +69,13 @@ impl ToString for ErrorType {
/* Requests */ /* Requests */
/// The STATUS request/response handshake message. /// The STATUS request/response handshake message.
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)] #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, Default)]
pub struct StatusMessage { pub struct StatusMessage {
pub data: NetworkIdentity, pub data: NetworkIdentity,
// shard config
pub num_shard: usize,
pub shard_id: usize,
} }
/// The PING request/response message. /// The PING request/response message.

View File

@ -23,14 +23,10 @@ fn test_status_rpc() {
let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt)).await; let (mut sender, mut receiver) = common::build_node_pair(Arc::downgrade(&rt)).await;
// Dummy STATUS RPC message // Dummy STATUS RPC message
let rpc_request = Request::Status(StatusMessage { let rpc_request = Request::Status(Default::default());
data: Default::default(),
});
// Dummy STATUS RPC message // Dummy STATUS RPC message
let rpc_response = Response::Status(StatusMessage { let rpc_response = Response::Status(Default::default());
data: Default::default(),
});
// build the sender future // build the sender future
let sender_future = async { let sender_future = async {

View File

@ -172,8 +172,11 @@ impl Libp2pEventHandler {
} }
pub fn send_status(&self, peer_id: PeerId) { pub fn send_status(&self, peer_id: PeerId) {
let shard_config = self.store.get_store().get_shard_config();
let status_message = StatusMessage { let status_message = StatusMessage {
data: self.network_globals.network_id(), data: self.network_globals.network_id(),
num_shard: shard_config.num_shard,
shard_id: shard_config.shard_id,
}; };
debug!(%peer_id, ?status_message, "Sending Status request"); debug!(%peer_id, ?status_message, "Sending Status request");
@ -254,8 +257,11 @@ impl Libp2pEventHandler {
debug!(%peer_id, ?status, "Received Status request"); debug!(%peer_id, ?status, "Received Status request");
let network_id = self.network_globals.network_id(); let network_id = self.network_globals.network_id();
let shard_config = self.store.get_store().get_shard_config();
let status_message = StatusMessage { let status_message = StatusMessage {
data: network_id.clone(), data: network_id.clone(),
num_shard: shard_config.num_shard,
shard_id: shard_config.shard_id,
}; };
debug!(%peer_id, ?status_message, "Sending Status response"); debug!(%peer_id, ?status_message, "Sending Status response");
@ -1216,6 +1222,8 @@ mod tests {
let req_id = (ConnectionId::new(4), SubstreamId(12)); let req_id = (ConnectionId::new(4), SubstreamId(12));
let request = Request::Status(StatusMessage { let request = Request::Status(StatusMessage {
data: Default::default(), data: Default::default(),
num_shard: 1,
shard_id: 0,
}); });
handler.on_rpc_request(alice, req_id, request).await; handler.on_rpc_request(alice, req_id, request).await;