github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/rust/src/consensus/zmq_service.rs (about) 1 /* 2 * Copyright 2018 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 use protobuf; 19 use protobuf::Message as ProtobufMessage; 20 use rand; 21 use rand::Rng; 22 23 use consensus::engine::*; 24 use consensus::service::Service; 25 26 use messaging::stream::MessageSender; 27 use messaging::zmq_stream::ZmqMessageSender; 28 29 use messages::consensus::*; 30 use messages::validator::Message_MessageType; 31 32 use std::collections::HashMap; 33 use std::time::Duration; 34 35 /// Generates a random correlation id for use in Message 36 fn generate_correlation_id() -> String { 37 const LENGTH: usize = 16; 38 rand::thread_rng().gen_ascii_chars().take(LENGTH).collect() 39 } 40 41 pub fn register( 42 sender: &mut MessageSender, 43 timeout: Duration, 44 name: String, 45 version: String, 46 ) -> Result<(Block, Vec<PeerInfo>), Error> { 47 let mut request = ConsensusRegisterRequest::new(); 48 request.set_name(name); 49 request.set_version(version); 50 let request = request.write_to_bytes()?; 51 52 let mut msg = sender 53 .send( 54 Message_MessageType::CONSENSUS_REGISTER_REQUEST, 55 &generate_correlation_id(), 56 &request, 57 )? 58 .get_timeout(timeout)?; 59 60 let ret: Result<(Block, Vec<PeerInfo>), Error>; 61 62 // Keep trying to register until the response is something other 63 // than NOT_READY. 64 loop { 65 match msg.get_message_type() { 66 Message_MessageType::CONSENSUS_REGISTER_RESPONSE => { 67 let mut response: ConsensusRegisterResponse = 68 protobuf::parse_from_bytes(msg.get_content())?; 69 70 match response.get_status() { 71 ConsensusRegisterResponse_Status::OK => { 72 ret = Ok(( 73 response.take_chain_head().into(), 74 response 75 .take_peers() 76 .into_iter() 77 .map(|info| info.into()) 78 .collect(), 79 )); 80 81 break; 82 } 83 ConsensusRegisterResponse_Status::NOT_READY => { 84 msg = sender 85 .send( 86 Message_MessageType::CONSENSUS_REGISTER_REQUEST, 87 &generate_correlation_id(), 88 &request, 89 )? 90 .get_timeout(timeout)?; 91 92 continue; 93 } 94 status => { 95 ret = Err(Error::ReceiveError(format!( 96 "Registration failed with status {:?}", 97 status 98 ))); 99 100 break; 101 } 102 }; 103 } 104 unexpected => { 105 ret = Err(Error::ReceiveError(format!( 106 "Received unexpected message type: {:?}", 107 unexpected 108 ))); 109 110 break; 111 } 112 } 113 } 114 115 ret 116 } 117 118 pub struct ZmqService { 119 sender: ZmqMessageSender, 120 timeout: Duration, 121 name: String, 122 version: String, 123 } 124 125 impl ZmqService { 126 pub fn new(sender: ZmqMessageSender, timeout: Duration, name: String, version: String) -> Self { 127 ZmqService { 128 sender, 129 timeout, 130 name, 131 version, 132 } 133 } 134 135 /// Serialize and send a request, wait for the default timeout, and receive and parse an 136 /// expected response. 137 pub fn rpc<I: protobuf::Message, O: protobuf::Message>( 138 &mut self, 139 request: &I, 140 request_type: Message_MessageType, 141 response_type: Message_MessageType, 142 ) -> Result<O, Error> { 143 let corr_id = generate_correlation_id(); 144 let mut future = self.sender 145 .send(request_type, &corr_id, &request.write_to_bytes()?)?; 146 147 let msg = future.get_timeout(self.timeout)?; 148 let msg_type = msg.get_message_type(); 149 if msg_type == response_type { 150 let response = protobuf::parse_from_bytes(msg.get_content())?; 151 Ok(response) 152 } else { 153 Err(Error::ReceiveError(format!( 154 "Received unexpected message type: {:?}", 155 msg_type 156 ))) 157 } 158 } 159 } 160 161 /// Return Ok(()) if $r.get_status() matches $ok 162 macro_rules! check_ok { 163 ($r:expr, $ok:pat) => { 164 match $r.get_status() { 165 $ok => Ok(()), 166 status => Err(Error::ReceiveError(format!( 167 "Failed with status {:?}", 168 status 169 ))), 170 } 171 }; 172 } 173 174 impl Service for ZmqService { 175 fn send_to( 176 &mut self, 177 peer: &PeerId, 178 message_type: &str, 179 payload: Vec<u8>, 180 ) -> Result<(), Error> { 181 let mut message = ConsensusPeerMessage::new(); 182 message.set_message_type(message_type.into()); 183 message.set_content(payload); 184 message.set_name(self.name.clone()); 185 message.set_version(self.version.clone()); 186 187 let mut request = ConsensusSendToRequest::new(); 188 request.set_message(message); 189 request.set_peer_id((*peer).clone().into()); 190 191 let response: ConsensusSendToResponse = self.rpc( 192 &request, 193 Message_MessageType::CONSENSUS_SEND_TO_REQUEST, 194 Message_MessageType::CONSENSUS_SEND_TO_RESPONSE, 195 )?; 196 197 check_ok!(response, ConsensusSendToResponse_Status::OK) 198 } 199 200 fn broadcast(&mut self, message_type: &str, payload: Vec<u8>) -> Result<(), Error> { 201 let mut message = ConsensusPeerMessage::new(); 202 message.set_message_type(message_type.into()); 203 message.set_content(payload); 204 205 let mut request = ConsensusBroadcastRequest::new(); 206 request.set_message(message); 207 208 let response: ConsensusBroadcastResponse = self.rpc( 209 &request, 210 Message_MessageType::CONSENSUS_BROADCAST_REQUEST, 211 Message_MessageType::CONSENSUS_BROADCAST_RESPONSE, 212 )?; 213 214 check_ok!(response, ConsensusBroadcastResponse_Status::OK) 215 } 216 217 fn initialize_block(&mut self, previous_id: Option<BlockId>) -> Result<(), Error> { 218 let mut request = ConsensusInitializeBlockRequest::new(); 219 if let Some(previous_id) = previous_id { 220 request.set_previous_id(previous_id.into()); 221 } 222 223 let response: ConsensusInitializeBlockResponse = self.rpc( 224 &request, 225 Message_MessageType::CONSENSUS_INITIALIZE_BLOCK_REQUEST, 226 Message_MessageType::CONSENSUS_INITIALIZE_BLOCK_RESPONSE, 227 )?; 228 229 if response.get_status() == ConsensusInitializeBlockResponse_Status::INVALID_STATE { 230 return Err(Error::InvalidState( 231 "Cannot initialize block in current state".into(), 232 )); 233 } 234 235 if response.get_status() == ConsensusInitializeBlockResponse_Status::UNKNOWN_BLOCK { 236 return Err(Error::UnknownBlock("Block not found".into())); 237 } 238 239 check_ok!(response, ConsensusInitializeBlockResponse_Status::OK) 240 } 241 242 fn summarize_block(&mut self) -> Result<Vec<u8>, Error> { 243 let request = ConsensusSummarizeBlockRequest::new(); 244 245 let mut response: ConsensusSummarizeBlockResponse = self.rpc( 246 &request, 247 Message_MessageType::CONSENSUS_SUMMARIZE_BLOCK_REQUEST, 248 Message_MessageType::CONSENSUS_SUMMARIZE_BLOCK_RESPONSE, 249 )?; 250 251 match response.get_status() { 252 ConsensusSummarizeBlockResponse_Status::INVALID_STATE => Err(Error::InvalidState( 253 "Cannot summarize block in current state".into(), 254 )), 255 ConsensusSummarizeBlockResponse_Status::BLOCK_NOT_READY => Err(Error::BlockNotReady), 256 _ => check_ok!(response, ConsensusSummarizeBlockResponse_Status::OK), 257 }?; 258 259 Ok(response.take_summary()) 260 } 261 262 fn finalize_block(&mut self, data: Vec<u8>) -> Result<BlockId, Error> { 263 let mut request = ConsensusFinalizeBlockRequest::new(); 264 request.set_data(data); 265 266 let mut response: ConsensusFinalizeBlockResponse = self.rpc( 267 &request, 268 Message_MessageType::CONSENSUS_FINALIZE_BLOCK_REQUEST, 269 Message_MessageType::CONSENSUS_FINALIZE_BLOCK_RESPONSE, 270 )?; 271 272 match response.get_status() { 273 ConsensusFinalizeBlockResponse_Status::INVALID_STATE => Err(Error::InvalidState( 274 "Cannot finalize block in current state".into(), 275 )), 276 ConsensusFinalizeBlockResponse_Status::BLOCK_NOT_READY => Err(Error::BlockNotReady), 277 _ => check_ok!(response, ConsensusFinalizeBlockResponse_Status::OK), 278 }?; 279 280 Ok(response.take_block_id().into()) 281 } 282 283 fn cancel_block(&mut self) -> Result<(), Error> { 284 let request = ConsensusCancelBlockRequest::new(); 285 286 let response: ConsensusCancelBlockResponse = self.rpc( 287 &request, 288 Message_MessageType::CONSENSUS_CANCEL_BLOCK_REQUEST, 289 Message_MessageType::CONSENSUS_CANCEL_BLOCK_RESPONSE, 290 )?; 291 292 if response.get_status() == ConsensusCancelBlockResponse_Status::INVALID_STATE { 293 Err(Error::InvalidState( 294 "Cannot cancel block in current state".into(), 295 )) 296 } else { 297 check_ok!(response, ConsensusCancelBlockResponse_Status::OK) 298 } 299 } 300 301 fn check_blocks(&mut self, priority: Vec<BlockId>) -> Result<(), Error> { 302 let mut request = ConsensusCheckBlocksRequest::new(); 303 request.set_block_ids(protobuf::RepeatedField::from_vec( 304 priority.into_iter().map(Vec::from).collect(), 305 )); 306 307 let response: ConsensusCheckBlocksResponse = self.rpc( 308 &request, 309 Message_MessageType::CONSENSUS_CHECK_BLOCKS_REQUEST, 310 Message_MessageType::CONSENSUS_CHECK_BLOCKS_RESPONSE, 311 )?; 312 313 if response.get_status() == ConsensusCheckBlocksResponse_Status::UNKNOWN_BLOCK { 314 Err(Error::UnknownBlock("Block not found".into())) 315 } else { 316 check_ok!(response, ConsensusCheckBlocksResponse_Status::OK) 317 } 318 } 319 320 fn commit_block(&mut self, block_id: BlockId) -> Result<(), Error> { 321 let mut request = ConsensusCommitBlockRequest::new(); 322 request.set_block_id(block_id.into()); 323 324 let response: ConsensusCommitBlockResponse = self.rpc( 325 &request, 326 Message_MessageType::CONSENSUS_COMMIT_BLOCK_REQUEST, 327 Message_MessageType::CONSENSUS_COMMIT_BLOCK_RESPONSE, 328 )?; 329 330 if response.get_status() == ConsensusCommitBlockResponse_Status::UNKNOWN_BLOCK { 331 Err(Error::UnknownBlock("Block not found".into())) 332 } else { 333 check_ok!(response, ConsensusCommitBlockResponse_Status::OK) 334 } 335 } 336 337 fn ignore_block(&mut self, block_id: BlockId) -> Result<(), Error> { 338 let mut request = ConsensusIgnoreBlockRequest::new(); 339 request.set_block_id(block_id.into()); 340 341 let response: ConsensusIgnoreBlockResponse = self.rpc( 342 &request, 343 Message_MessageType::CONSENSUS_IGNORE_BLOCK_REQUEST, 344 Message_MessageType::CONSENSUS_IGNORE_BLOCK_RESPONSE, 345 )?; 346 347 if response.get_status() == ConsensusIgnoreBlockResponse_Status::UNKNOWN_BLOCK { 348 Err(Error::UnknownBlock("Block not found".into())) 349 } else { 350 check_ok!(response, ConsensusIgnoreBlockResponse_Status::OK) 351 } 352 } 353 354 fn fail_block(&mut self, block_id: BlockId) -> Result<(), Error> { 355 let mut request = ConsensusFailBlockRequest::new(); 356 request.set_block_id(block_id.into()); 357 358 let response: ConsensusFailBlockResponse = self.rpc( 359 &request, 360 Message_MessageType::CONSENSUS_FAIL_BLOCK_REQUEST, 361 Message_MessageType::CONSENSUS_FAIL_BLOCK_RESPONSE, 362 )?; 363 364 if response.get_status() == ConsensusFailBlockResponse_Status::UNKNOWN_BLOCK { 365 Err(Error::UnknownBlock("Block not found".into())) 366 } else { 367 check_ok!(response, ConsensusFailBlockResponse_Status::OK) 368 } 369 } 370 371 fn get_blocks(&mut self, block_ids: Vec<BlockId>) -> Result<HashMap<BlockId, Block>, Error> { 372 let mut request = ConsensusBlocksGetRequest::new(); 373 request.set_block_ids(protobuf::RepeatedField::from_vec( 374 block_ids.into_iter().map(Vec::from).collect(), 375 )); 376 377 let mut response: ConsensusBlocksGetResponse = self.rpc( 378 &request, 379 Message_MessageType::CONSENSUS_BLOCKS_GET_REQUEST, 380 Message_MessageType::CONSENSUS_BLOCKS_GET_RESPONSE, 381 )?; 382 383 if response.get_status() == ConsensusBlocksGetResponse_Status::UNKNOWN_BLOCK { 384 Err(Error::UnknownBlock("Block not found".into())) 385 } else { 386 check_ok!(response, ConsensusBlocksGetResponse_Status::OK) 387 }?; 388 389 Ok(response 390 .take_blocks() 391 .into_iter() 392 .map(|block| (BlockId::from(block.block_id.clone()), Block::from(block))) 393 .collect()) 394 } 395 396 fn get_chain_head(&mut self) -> Result<Block, Error> { 397 let request = ConsensusChainHeadGetRequest::new(); 398 399 let mut response: ConsensusChainHeadGetResponse = self.rpc( 400 &request, 401 Message_MessageType::CONSENSUS_CHAIN_HEAD_GET_REQUEST, 402 Message_MessageType::CONSENSUS_CHAIN_HEAD_GET_RESPONSE, 403 )?; 404 405 if response.get_status() == ConsensusChainHeadGetResponse_Status::NO_CHAIN_HEAD { 406 Err(Error::NoChainHead) 407 } else { 408 check_ok!(response, ConsensusChainHeadGetResponse_Status::OK) 409 }?; 410 411 Ok(Block::from(response.take_block())) 412 } 413 414 fn get_settings( 415 &mut self, 416 block_id: BlockId, 417 keys: Vec<String>, 418 ) -> Result<HashMap<String, String>, Error> { 419 let mut request = ConsensusSettingsGetRequest::new(); 420 request.set_block_id(block_id.into()); 421 request.set_keys(protobuf::RepeatedField::from_vec(keys)); 422 423 let mut response: ConsensusSettingsGetResponse = self.rpc( 424 &request, 425 Message_MessageType::CONSENSUS_SETTINGS_GET_REQUEST, 426 Message_MessageType::CONSENSUS_SETTINGS_GET_RESPONSE, 427 )?; 428 429 if response.get_status() == ConsensusSettingsGetResponse_Status::UNKNOWN_BLOCK { 430 Err(Error::UnknownBlock("Block not found".into())) 431 } else { 432 check_ok!(response, ConsensusSettingsGetResponse_Status::OK) 433 }?; 434 435 Ok(response 436 .take_entries() 437 .into_iter() 438 .map(|mut entry| (entry.take_key(), entry.take_value())) 439 .collect()) 440 } 441 442 fn get_state( 443 &mut self, 444 block_id: BlockId, 445 addresses: Vec<String>, 446 ) -> Result<HashMap<String, Vec<u8>>, Error> { 447 let mut request = ConsensusStateGetRequest::new(); 448 request.set_block_id(block_id.into()); 449 request.set_addresses(protobuf::RepeatedField::from_vec(addresses)); 450 451 let mut response: ConsensusStateGetResponse = self.rpc( 452 &request, 453 Message_MessageType::CONSENSUS_STATE_GET_REQUEST, 454 Message_MessageType::CONSENSUS_STATE_GET_RESPONSE, 455 )?; 456 457 if response.get_status() == ConsensusStateGetResponse_Status::UNKNOWN_BLOCK { 458 Err(Error::UnknownBlock("Block not found".into())) 459 } else { 460 check_ok!(response, ConsensusStateGetResponse_Status::OK) 461 }?; 462 463 Ok(response 464 .take_entries() 465 .into_iter() 466 .map(|mut entry| (entry.take_address(), entry.take_data())) 467 .collect()) 468 } 469 } 470 471 #[cfg(test)] 472 mod tests { 473 use super::*; 474 use messages::validator::Message; 475 use messaging::stream::MessageConnection; 476 use messaging::zmq_stream::ZmqMessageConnection; 477 use std::default::Default; 478 use std::thread; 479 use zmq; 480 481 fn recv_rep<I: protobuf::Message, O: protobuf::Message>( 482 socket: &zmq::Socket, 483 request_type: Message_MessageType, 484 response: I, 485 response_type: Message_MessageType, 486 ) -> (Vec<u8>, O) { 487 let mut parts = socket.recv_multipart(0).unwrap(); 488 assert!(parts.len() == 2); 489 490 let mut msg: Message = protobuf::parse_from_bytes(&parts.pop().unwrap()).unwrap(); 491 let connection_id = parts.pop().unwrap(); 492 assert!(msg.get_message_type() == request_type); 493 let request: O = protobuf::parse_from_bytes(&msg.get_content()).unwrap(); 494 495 let correlation_id = msg.take_correlation_id(); 496 let mut msg = Message::new(); 497 msg.set_message_type(response_type); 498 msg.set_correlation_id(correlation_id); 499 msg.set_content(response.write_to_bytes().unwrap()); 500 socket 501 .send_multipart(&[&connection_id, &msg.write_to_bytes().unwrap()], 0) 502 .unwrap(); 503 504 (connection_id, request) 505 } 506 507 macro_rules! service_test { 508 ( 509 $socket:expr, 510 $rep:expr, 511 $status:expr, 512 $rep_msg_type:expr, 513 $req_type:ty, 514 $req_msg_type:expr 515 ) => { 516 let mut response = $rep; 517 response.set_status($status); 518 let (_, _): (_, $req_type) = 519 recv_rep($socket, $req_msg_type, response, $rep_msg_type); 520 }; 521 } 522 523 #[test] 524 fn test_zmq_service() { 525 let ctx = zmq::Context::new(); 526 let socket = ctx.socket(zmq::ROUTER).expect("Failed to create context"); 527 socket 528 .bind("tcp://127.0.0.1:*") 529 .expect("Failed to bind socket"); 530 let addr = socket.get_last_endpoint().unwrap().unwrap(); 531 532 let svc_thread = thread::spawn(move || { 533 let connection = ZmqMessageConnection::new(&addr); 534 let (sender, _) = connection.create(); 535 let mut svc = 536 ZmqService::new(sender, Duration::from_secs(10), "mock".into(), "0".into()); 537 538 svc.send_to(&Default::default(), Default::default(), Default::default()) 539 .unwrap(); 540 svc.broadcast(Default::default(), Default::default()) 541 .unwrap(); 542 543 svc.initialize_block(Some(Default::default())).unwrap(); 544 svc.summarize_block().unwrap(); 545 svc.finalize_block(Default::default()).unwrap(); 546 svc.cancel_block().unwrap(); 547 548 svc.check_blocks(Default::default()).unwrap(); 549 svc.commit_block(Default::default()).unwrap(); 550 svc.ignore_block(Default::default()).unwrap(); 551 svc.fail_block(Default::default()).unwrap(); 552 553 svc.get_blocks(Default::default()).unwrap(); 554 svc.get_settings(Default::default(), Default::default()) 555 .unwrap(); 556 svc.get_state(Default::default(), Default::default()) 557 .unwrap(); 558 svc.get_chain_head().unwrap(); 559 }); 560 561 service_test!( 562 &socket, 563 ConsensusSendToResponse::new(), 564 ConsensusSendToResponse_Status::OK, 565 Message_MessageType::CONSENSUS_SEND_TO_RESPONSE, 566 ConsensusSendToRequest, 567 Message_MessageType::CONSENSUS_SEND_TO_REQUEST 568 ); 569 570 service_test!( 571 &socket, 572 ConsensusBroadcastResponse::new(), 573 ConsensusBroadcastResponse_Status::OK, 574 Message_MessageType::CONSENSUS_BROADCAST_RESPONSE, 575 ConsensusBroadcastRequest, 576 Message_MessageType::CONSENSUS_BROADCAST_REQUEST 577 ); 578 579 service_test!( 580 &socket, 581 ConsensusInitializeBlockResponse::new(), 582 ConsensusInitializeBlockResponse_Status::OK, 583 Message_MessageType::CONSENSUS_INITIALIZE_BLOCK_RESPONSE, 584 ConsensusInitializeBlockRequest, 585 Message_MessageType::CONSENSUS_INITIALIZE_BLOCK_REQUEST 586 ); 587 588 service_test!( 589 &socket, 590 ConsensusSummarizeBlockResponse::new(), 591 ConsensusSummarizeBlockResponse_Status::OK, 592 Message_MessageType::CONSENSUS_SUMMARIZE_BLOCK_RESPONSE, 593 ConsensusSummarizeBlockRequest, 594 Message_MessageType::CONSENSUS_SUMMARIZE_BLOCK_REQUEST 595 ); 596 597 service_test!( 598 &socket, 599 ConsensusFinalizeBlockResponse::new(), 600 ConsensusFinalizeBlockResponse_Status::OK, 601 Message_MessageType::CONSENSUS_FINALIZE_BLOCK_RESPONSE, 602 ConsensusFinalizeBlockRequest, 603 Message_MessageType::CONSENSUS_FINALIZE_BLOCK_REQUEST 604 ); 605 606 service_test!( 607 &socket, 608 ConsensusCancelBlockResponse::new(), 609 ConsensusCancelBlockResponse_Status::OK, 610 Message_MessageType::CONSENSUS_CANCEL_BLOCK_RESPONSE, 611 ConsensusCancelBlockRequest, 612 Message_MessageType::CONSENSUS_CANCEL_BLOCK_REQUEST 613 ); 614 615 service_test!( 616 &socket, 617 ConsensusCheckBlocksResponse::new(), 618 ConsensusCheckBlocksResponse_Status::OK, 619 Message_MessageType::CONSENSUS_CHECK_BLOCKS_RESPONSE, 620 ConsensusCheckBlocksRequest, 621 Message_MessageType::CONSENSUS_CHECK_BLOCKS_REQUEST 622 ); 623 624 service_test!( 625 &socket, 626 ConsensusCommitBlockResponse::new(), 627 ConsensusCommitBlockResponse_Status::OK, 628 Message_MessageType::CONSENSUS_COMMIT_BLOCK_RESPONSE, 629 ConsensusCommitBlockRequest, 630 Message_MessageType::CONSENSUS_COMMIT_BLOCK_REQUEST 631 ); 632 633 service_test!( 634 &socket, 635 ConsensusIgnoreBlockResponse::new(), 636 ConsensusIgnoreBlockResponse_Status::OK, 637 Message_MessageType::CONSENSUS_IGNORE_BLOCK_RESPONSE, 638 ConsensusIgnoreBlockRequest, 639 Message_MessageType::CONSENSUS_IGNORE_BLOCK_REQUEST 640 ); 641 642 service_test!( 643 &socket, 644 ConsensusFailBlockResponse::new(), 645 ConsensusFailBlockResponse_Status::OK, 646 Message_MessageType::CONSENSUS_FAIL_BLOCK_RESPONSE, 647 ConsensusFailBlockRequest, 648 Message_MessageType::CONSENSUS_FAIL_BLOCK_REQUEST 649 ); 650 651 service_test!( 652 &socket, 653 ConsensusBlocksGetResponse::new(), 654 ConsensusBlocksGetResponse_Status::OK, 655 Message_MessageType::CONSENSUS_BLOCKS_GET_RESPONSE, 656 ConsensusBlocksGetRequest, 657 Message_MessageType::CONSENSUS_BLOCKS_GET_REQUEST 658 ); 659 660 service_test!( 661 &socket, 662 ConsensusSettingsGetResponse::new(), 663 ConsensusSettingsGetResponse_Status::OK, 664 Message_MessageType::CONSENSUS_SETTINGS_GET_RESPONSE, 665 ConsensusSettingsGetRequest, 666 Message_MessageType::CONSENSUS_SETTINGS_GET_REQUEST 667 ); 668 669 service_test!( 670 &socket, 671 ConsensusStateGetResponse::new(), 672 ConsensusStateGetResponse_Status::OK, 673 Message_MessageType::CONSENSUS_STATE_GET_RESPONSE, 674 ConsensusStateGetRequest, 675 Message_MessageType::CONSENSUS_STATE_GET_REQUEST 676 ); 677 678 service_test!( 679 &socket, 680 ConsensusChainHeadGetResponse::new(), 681 ConsensusChainHeadGetResponse_Status::OK, 682 Message_MessageType::CONSENSUS_CHAIN_HEAD_GET_RESPONSE, 683 ConsensusChainHeadGetRequest, 684 Message_MessageType::CONSENSUS_CHAIN_HEAD_GET_REQUEST 685 ); 686 687 svc_thread.join().unwrap(); 688 } 689 }