1use std::{
7 collections::{BTreeMap, BTreeSet, HashMap, HashSet},
8 fmt::{self, Display, Formatter},
9 sync::Arc,
10};
11
12use datasize::DataSize;
13use hex_fmt::HexFmt;
14use serde::Serialize;
15use smallvec::SmallVec;
16use static_assertions::const_assert;
17
18use casper_binary_port::{
19 ConsensusStatus, ConsensusValidatorChanges, LastProgress, NetworkName, RecordId, Uptime,
20};
21use casper_storage::{
22 block_store::types::ApprovalsHashes,
23 data_access_layer::{
24 prefixed_values::{PrefixedValuesRequest, PrefixedValuesResult},
25 tagged_values::{TaggedValuesRequest, TaggedValuesResult},
26 AddressableEntityResult, BalanceRequest, BalanceResult, EntryPointExistsResult,
27 EraValidatorsRequest, EraValidatorsResult, ExecutionResultsChecksumResult, PutTrieRequest,
28 PutTrieResult, QueryRequest, QueryResult, SeigniorageRecipientsRequest,
29 SeigniorageRecipientsResult, TrieRequest, TrieResult,
30 },
31 DbRawBytesSpec,
32};
33use casper_types::{
34 execution::ExecutionResult, Approval, AvailableBlockRange, Block, BlockHash, BlockHeader,
35 BlockSignatures, BlockSynchronizerStatus, BlockV2, ChainspecRawBytes, DeployHash, Digest,
36 DisplayIter, EntityAddr, EraId, ExecutionInfo, FinalitySignature, FinalitySignatureId,
37 HashAddr, NextUpgrade, ProtocolUpgradeConfig, PublicKey, TimeDiff, Timestamp, Transaction,
38 TransactionHash, TransactionId, Transfer,
39};
40
41use super::{AutoClosingResponder, GossipTarget, Responder};
42use crate::{
43 components::{
44 block_synchronizer::{
45 GlobalStateSynchronizerError, GlobalStateSynchronizerResponse, TrieAccumulatorError,
46 TrieAccumulatorResponse,
47 },
48 consensus::{ClContext, ProposedBlock},
49 contract_runtime::SpeculativeExecutionResult,
50 diagnostics_port::StopAtSpec,
51 fetcher::{FetchItem, FetchResult},
52 gossiper::GossipItem,
53 network::NetworkInsights,
54 transaction_acceptor,
55 },
56 contract_runtime::ExecutionPreState,
57 reactor::main_reactor::ReactorState,
58 types::{
59 appendable_block::AppendableBlock, BlockExecutionResultsOrChunk,
60 BlockExecutionResultsOrChunkId, BlockWithMetadata, ExecutableBlock, InvalidProposalError,
61 LegacyDeploy, MetaBlockState, NodeId, StatusFeed, TransactionHeader,
62 },
63 utils::Source,
64};
65
66const _STORAGE_REQUEST_SIZE: usize = size_of::<StorageRequest>();
67const_assert!(_STORAGE_REQUEST_SIZE < 129);
68
69#[derive(Debug)]
71pub(crate) enum MetricsRequest {
72 RenderNodeMetricsText {
74 responder: Responder<Option<String>>,
76 },
77}
78
79impl Display for MetricsRequest {
80 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
81 match self {
82 MetricsRequest::RenderNodeMetricsText { .. } => write!(formatter, "get metrics text"),
83 }
84 }
85}
86
87const _NETWORK_EVENT_SIZE: usize = size_of::<NetworkRequest<String>>();
88const_assert!(_NETWORK_EVENT_SIZE < 105);
89
90#[derive(Debug, Serialize)]
92#[must_use]
93pub(crate) enum NetworkRequest<P> {
94 SendMessage {
96 dest: Box<NodeId>,
98 payload: Box<P>,
100 respond_after_queueing: bool,
103 #[serde(skip_serializing)]
105 auto_closing_responder: AutoClosingResponder<()>,
106 },
107 ValidatorBroadcast {
109 payload: Box<P>,
111 era_id: EraId,
113 #[serde(skip_serializing)]
115 auto_closing_responder: AutoClosingResponder<()>,
116 },
117 Gossip {
119 payload: Box<P>,
121 gossip_target: GossipTarget,
123 count: usize,
125 #[serde(skip_serializing)]
127 exclude: HashSet<NodeId>,
128 #[serde(skip_serializing)]
130 auto_closing_responder: AutoClosingResponder<HashSet<NodeId>>,
131 },
132}
133
134impl<P> NetworkRequest<P> {
135 pub(crate) fn map_payload<F, P2>(self, wrap_payload: F) -> NetworkRequest<P2>
139 where
140 F: FnOnce(P) -> P2,
141 {
142 match self {
143 NetworkRequest::SendMessage {
144 dest,
145 payload,
146 respond_after_queueing,
147 auto_closing_responder,
148 } => NetworkRequest::SendMessage {
149 dest,
150 payload: Box::new(wrap_payload(*payload)),
151 respond_after_queueing,
152 auto_closing_responder,
153 },
154 NetworkRequest::ValidatorBroadcast {
155 payload,
156 era_id,
157 auto_closing_responder,
158 } => NetworkRequest::ValidatorBroadcast {
159 payload: Box::new(wrap_payload(*payload)),
160 era_id,
161 auto_closing_responder,
162 },
163 NetworkRequest::Gossip {
164 payload,
165 gossip_target,
166 count,
167 exclude,
168 auto_closing_responder,
169 } => NetworkRequest::Gossip {
170 payload: Box::new(wrap_payload(*payload)),
171 gossip_target,
172 count,
173 exclude,
174 auto_closing_responder,
175 },
176 }
177 }
178}
179
180impl<P> Display for NetworkRequest<P>
181where
182 P: Display,
183{
184 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
185 match self {
186 NetworkRequest::SendMessage { dest, payload, .. } => {
187 write!(formatter, "send to {}: {}", dest, payload)
188 }
189 NetworkRequest::ValidatorBroadcast { payload, .. } => {
190 write!(formatter, "broadcast: {}", payload)
191 }
192 NetworkRequest::Gossip { payload, .. } => write!(formatter, "gossip: {}", payload),
193 }
194 }
195}
196
197#[derive(Debug, Serialize)]
199pub(crate) enum NetworkInfoRequest {
200 Peers {
202 responder: Responder<BTreeMap<NodeId, String>>,
205 },
206 FullyConnectedPeers {
208 count: usize,
209 responder: Responder<Vec<NodeId>>,
211 },
212 Insight {
214 responder: Responder<NetworkInsights>,
215 },
216}
217
218impl Display for NetworkInfoRequest {
219 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
220 match self {
221 NetworkInfoRequest::Peers { responder: _ } => {
222 formatter.write_str("get peers-to-socket-address map")
223 }
224 NetworkInfoRequest::FullyConnectedPeers {
225 count,
226 responder: _,
227 } => {
228 write!(formatter, "get up to {} fully connected peers", count)
229 }
230 NetworkInfoRequest::Insight { responder: _ } => {
231 formatter.write_str("get networking insights")
232 }
233 }
234 }
235}
236
237#[derive(Debug, Serialize)]
245#[must_use]
246pub(crate) struct BeginGossipRequest<T>
247where
248 T: GossipItem,
249{
250 pub(crate) item_id: T::Id,
251 pub(crate) source: Source,
252 pub(crate) target: GossipTarget,
253 pub(crate) responder: Responder<()>,
254}
255
256impl<T> Display for BeginGossipRequest<T>
257where
258 T: GossipItem,
259{
260 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
261 write!(f, "begin gossip of {} from {}", self.item_id, self.source)
262 }
263}
264
265#[derive(Debug, Serialize)]
266pub(crate) enum StorageRequest {
268 PutBlock {
270 block: Arc<Block>,
272 responder: Responder<bool>,
275 },
276 PutApprovalsHashes {
278 approvals_hashes: Box<ApprovalsHashes>,
280 responder: Responder<bool>,
281 },
282 PutExecutedBlock {
284 block: Arc<BlockV2>,
286 approvals_hashes: Box<ApprovalsHashes>,
288 execution_results: HashMap<TransactionHash, ExecutionResult>,
289 responder: Responder<bool>,
290 },
291 GetBlock {
293 block_hash: BlockHash,
295 responder: Responder<Option<Block>>,
298 },
299 IsBlockStored {
300 block_hash: BlockHash,
301 responder: Responder<bool>,
302 },
303 GetApprovalsHashes {
305 block_hash: BlockHash,
307 responder: Responder<Option<ApprovalsHashes>>,
310 },
311 GetHighestCompleteBlock {
313 responder: Responder<Option<Block>>,
315 },
316 GetHighestCompleteBlockHeader {
318 responder: Responder<Option<BlockHeader>>,
320 },
321 GetTransactionsEraIds {
323 transaction_hashes: HashSet<TransactionHash>,
324 responder: Responder<HashSet<EraId>>,
325 },
326 GetBlockHeader {
328 block_hash: BlockHash,
330 only_from_available_block_range: bool,
333 responder: Responder<Option<BlockHeader>>,
336 },
337 GetRawData {
339 record_id: RecordId,
341 key: Vec<u8>,
343 responder: Responder<Option<DbRawBytesSpec>>,
346 },
347 GetBlockHeaderByHeight {
348 block_height: u64,
350 only_from_available_block_range: bool,
353 responder: Responder<Option<BlockHeader>>,
356 },
357 GetLatestSwitchBlockHeader {
358 responder: Responder<Option<BlockHeader>>,
359 },
360 GetSwitchBlockHeaderByEra {
361 era_id: EraId,
363 responder: Responder<Option<BlockHeader>>,
365 },
366 GetBlockTransfers {
368 block_hash: BlockHash,
370 responder: Responder<Option<Vec<Transfer>>>,
373 },
374 PutTransaction {
375 transaction: Arc<Transaction>,
376 responder: Responder<bool>,
379 },
380 GetTransactions {
382 transaction_hashes: Vec<TransactionHash>,
383 #[allow(clippy::type_complexity)]
384 responder: Responder<SmallVec<[Option<(Transaction, Option<BTreeSet<Approval>>)>; 1]>>,
385 },
386 GetLegacyDeploy {
388 deploy_hash: DeployHash,
389 responder: Responder<Option<LegacyDeploy>>,
390 },
391 GetTransaction {
392 transaction_id: TransactionId,
393 responder: Responder<Option<Transaction>>,
394 },
395 IsTransactionStored {
396 transaction_id: TransactionId,
397 responder: Responder<bool>,
398 },
399 GetTransactionAndExecutionInfo {
400 transaction_hash: TransactionHash,
401 with_finalized_approvals: bool,
402 responder: Responder<Option<(Transaction, Option<ExecutionInfo>)>>,
403 },
404 PutExecutionResults {
412 block_hash: Box<BlockHash>,
414 block_height: u64,
415 era_id: EraId,
416 execution_results: HashMap<TransactionHash, ExecutionResult>,
418 responder: Responder<()>,
420 },
421 GetExecutionResults {
422 block_hash: BlockHash,
423 responder: Responder<Option<Vec<(TransactionHash, TransactionHeader, ExecutionResult)>>>,
424 },
425 GetBlockExecutionResultsOrChunk {
426 id: BlockExecutionResultsOrChunkId,
428 responder: Responder<Option<BlockExecutionResultsOrChunk>>,
431 },
432 GetFinalitySignature {
434 id: Box<FinalitySignatureId>,
435 responder: Responder<Option<FinalitySignature>>,
436 },
437 IsFinalitySignatureStored {
438 id: Box<FinalitySignatureId>,
439 responder: Responder<bool>,
440 },
441 GetBlockAndMetadataByHeight {
443 block_height: BlockHeight,
445 only_from_available_block_range: bool,
448 responder: Responder<Option<BlockWithMetadata>>,
450 },
451 GetBlockSignature {
453 block_hash: BlockHash,
455 public_key: Box<PublicKey>,
457 responder: Responder<Option<FinalitySignature>>,
459 },
460 PutBlockSignatures {
462 signatures: BlockSignatures,
464 responder: Responder<bool>,
467 },
468 PutFinalitySignature {
469 signature: Box<FinalitySignature>,
470 responder: Responder<bool>,
471 },
472 PutBlockHeader {
474 block_header: Box<BlockHeader>,
476 responder: Responder<bool>,
479 },
480 GetAvailableBlockRange {
483 responder: Responder<AvailableBlockRange>,
485 },
486 StoreFinalizedApprovals {
488 transaction_hash: TransactionHash,
490 finalized_approvals: BTreeSet<Approval>,
492 responder: Responder<bool>,
495 },
496 GetKeyBlockHeightForActivationPoint { responder: Responder<Option<u64>> },
498 GetBlockUtilizationScore {
500 era_id: EraId,
502 block_height: u64,
504 switch_block_utilization: u64,
506 responder: Responder<Option<(u64, u64)>>,
508 },
509}
510
511impl Display for StorageRequest {
512 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
513 match self {
514 StorageRequest::PutBlock { block, .. } => {
515 write!(formatter, "put {}", block)
516 }
517 StorageRequest::PutApprovalsHashes {
518 approvals_hashes, ..
519 } => {
520 write!(formatter, "put {}", approvals_hashes)
521 }
522 StorageRequest::GetBlock { block_hash, .. } => {
523 write!(formatter, "get block {}", block_hash)
524 }
525 StorageRequest::IsBlockStored { block_hash, .. } => {
526 write!(formatter, "is block {} stored", block_hash)
527 }
528 StorageRequest::GetApprovalsHashes { block_hash, .. } => {
529 write!(formatter, "get approvals hashes {}", block_hash)
530 }
531 StorageRequest::GetHighestCompleteBlock { .. } => {
532 write!(formatter, "get highest complete block")
533 }
534 StorageRequest::GetHighestCompleteBlockHeader { .. } => {
535 write!(formatter, "get highest complete block header")
536 }
537 StorageRequest::GetTransactionsEraIds {
538 transaction_hashes, ..
539 } => {
540 write!(
541 formatter,
542 "get era ids for {} transactions",
543 transaction_hashes.len()
544 )
545 }
546 StorageRequest::GetBlockHeader { block_hash, .. } => {
547 write!(formatter, "get {}", block_hash)
548 }
549 StorageRequest::GetBlockHeaderByHeight { block_height, .. } => {
550 write!(formatter, "get header for height {}", block_height)
551 }
552 StorageRequest::GetLatestSwitchBlockHeader { .. } => {
553 write!(formatter, "get latest switch block header")
554 }
555 StorageRequest::GetSwitchBlockHeaderByEra { era_id, .. } => {
556 write!(formatter, "get header for era {}", era_id)
557 }
558 StorageRequest::GetBlockTransfers { block_hash, .. } => {
559 write!(formatter, "get transfers for {}", block_hash)
560 }
561 StorageRequest::PutTransaction { transaction, .. } => {
562 write!(formatter, "put {}", transaction)
563 }
564 StorageRequest::GetTransactions {
565 transaction_hashes, ..
566 } => {
567 write!(
568 formatter,
569 "get {}",
570 DisplayIter::new(transaction_hashes.iter())
571 )
572 }
573 StorageRequest::GetLegacyDeploy { deploy_hash, .. } => {
574 write!(formatter, "get legacy deploy {}", deploy_hash)
575 }
576 StorageRequest::GetTransaction { transaction_id, .. } => {
577 write!(formatter, "get transaction {}", transaction_id)
578 }
579 StorageRequest::GetTransactionAndExecutionInfo {
580 transaction_hash, ..
581 } => {
582 write!(
583 formatter,
584 "get transaction and exec info {}",
585 transaction_hash
586 )
587 }
588 StorageRequest::IsTransactionStored { transaction_id, .. } => {
589 write!(formatter, "is transaction {} stored", transaction_id)
590 }
591 StorageRequest::PutExecutionResults { block_hash, .. } => {
592 write!(formatter, "put execution results for {}", block_hash)
593 }
594 StorageRequest::GetExecutionResults { block_hash, .. } => {
595 write!(formatter, "get execution results for {}", block_hash)
596 }
597 StorageRequest::GetBlockExecutionResultsOrChunk { id, .. } => {
598 write!(formatter, "get block execution results or chunk for {}", id)
599 }
600 StorageRequest::GetFinalitySignature { id, .. } => {
601 write!(formatter, "get finality signature {}", id)
602 }
603 StorageRequest::IsFinalitySignatureStored { id, .. } => {
604 write!(formatter, "is finality signature {} stored", id)
605 }
606 StorageRequest::GetBlockAndMetadataByHeight { block_height, .. } => {
607 write!(
608 formatter,
609 "get block and metadata for block at height: {}",
610 block_height
611 )
612 }
613 StorageRequest::GetBlockSignature {
614 block_hash,
615 public_key,
616 ..
617 } => {
618 write!(
619 formatter,
620 "get finality signature for block hash {} from {}",
621 block_hash, public_key
622 )
623 }
624 StorageRequest::PutBlockSignatures { .. } => {
625 write!(formatter, "put finality signatures")
626 }
627 StorageRequest::PutFinalitySignature { .. } => {
628 write!(formatter, "put finality signature")
629 }
630 StorageRequest::PutBlockHeader { block_header, .. } => {
631 write!(formatter, "put block header: {}", block_header)
632 }
633 StorageRequest::GetAvailableBlockRange { .. } => {
634 write!(formatter, "get available block range",)
635 }
636 StorageRequest::StoreFinalizedApprovals {
637 transaction_hash, ..
638 } => {
639 write!(
640 formatter,
641 "finalized approvals for transaction {}",
642 transaction_hash
643 )
644 }
645 StorageRequest::PutExecutedBlock { block, .. } => {
646 write!(formatter, "put executed block {}", block.hash(),)
647 }
648 StorageRequest::GetKeyBlockHeightForActivationPoint { .. } => {
649 write!(
650 formatter,
651 "get key block height for current activation point"
652 )
653 }
654 StorageRequest::GetRawData {
655 key,
656 responder: _responder,
657 record_id,
658 } => {
659 write!(formatter, "get raw data {}::{:?}", record_id, key)
660 }
661 StorageRequest::GetBlockUtilizationScore { era_id, .. } => {
662 write!(formatter, "get utilization score for era {}", era_id)
663 }
664 }
665 }
666}
667
668#[derive(Debug, Serialize)]
669pub(crate) struct MakeBlockExecutableRequest {
670 pub block_hash: BlockHash,
672 pub responder: Responder<Option<ExecutableBlock>>,
674}
675
676impl Display for MakeBlockExecutableRequest {
677 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
678 write!(f, "block made executable: {}", self.block_hash)
679 }
680}
681
682#[derive(Debug, Serialize)]
690pub(crate) struct MarkBlockCompletedRequest {
691 pub block_height: u64,
692 pub responder: Responder<bool>,
694}
695
696impl Display for MarkBlockCompletedRequest {
697 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
698 write!(f, "block completed: height {}", self.block_height)
699 }
700}
701
702#[derive(DataSize, Debug, Serialize)]
703pub(crate) enum TransactionBufferRequest {
704 GetAppendableBlock {
705 timestamp: Timestamp,
706 era_id: EraId,
707 request_expiry: Timestamp,
708 responder: Responder<AppendableBlock>,
709 },
710}
711
712impl Display for TransactionBufferRequest {
713 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
714 match self {
715 TransactionBufferRequest::GetAppendableBlock {
716 timestamp,
717 era_id,
718 request_expiry,
719 ..
720 } => {
721 write!(
722 formatter,
723 "request for appendable block at instant {} for era {} (expires at {})",
724 timestamp, era_id, request_expiry
725 )
726 }
727 }
728 }
729}
730
731#[derive(Debug)]
736#[must_use]
737pub(crate) enum RestRequest {
738 Status {
740 responder: Responder<StatusFeed>,
742 },
743 Metrics {
745 responder: Responder<Option<String>>,
747 },
748}
749
750impl Display for RestRequest {
751 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
752 match self {
753 RestRequest::Status { .. } => write!(formatter, "get status"),
754 RestRequest::Metrics { .. } => write!(formatter, "get metrics"),
755 }
756 }
757}
758
759#[derive(Debug, Serialize)]
761#[must_use]
762pub(crate) enum ContractRuntimeRequest {
763 EnqueueBlockForExecution {
765 executable_block: ExecutableBlock,
767 key_block_height_for_activation_point: u64,
769 meta_block_state: MetaBlockState,
770 },
771 Query {
773 #[serde(skip_serializing)]
775 request: QueryRequest,
776 responder: Responder<QueryResult>,
778 },
779 QueryByPrefix {
781 #[serde(skip_serializing)]
783 request: PrefixedValuesRequest,
784 responder: Responder<PrefixedValuesResult>,
786 },
787 GetBalance {
789 #[serde(skip_serializing)]
791 request: BalanceRequest,
792 responder: Responder<BalanceResult>,
794 },
795 GetEraValidators {
797 #[serde(skip_serializing)]
799 request: EraValidatorsRequest,
800 responder: Responder<EraValidatorsResult>,
802 },
803 GetSeigniorageRecipients {
805 #[serde(skip_serializing)]
807 request: SeigniorageRecipientsRequest,
808 responder: Responder<SeigniorageRecipientsResult>,
810 },
811 GetTaggedValues {
813 #[serde(skip_serializing)]
815 request: TaggedValuesRequest,
816 responder: Responder<TaggedValuesResult>,
818 },
819 GetExecutionResultsChecksum {
822 state_root_hash: Digest,
823 responder: Responder<ExecutionResultsChecksumResult>,
824 },
825 GetAddressableEntity {
830 state_root_hash: Digest,
831 entity_addr: EntityAddr,
832 responder: Responder<AddressableEntityResult>,
833 },
834 GetEntryPointExists {
837 state_root_hash: Digest,
838 contract_hash: HashAddr,
839 entry_point_name: String,
840 responder: Responder<EntryPointExistsResult>,
841 },
842 GetTrie {
844 #[serde(skip_serializing)]
846 request: TrieRequest,
847 responder: Responder<TrieResult>,
849 },
850 PutTrie {
852 #[serde(skip_serializing)]
854 request: PutTrieRequest,
855 responder: Responder<PutTrieResult>,
857 },
858 SpeculativelyExecute {
860 block_header: Box<BlockHeader>,
862 transaction: Box<Transaction>,
864 responder: Responder<SpeculativeExecutionResult>,
866 },
867 UpdateRuntimePrice(EraId, u8),
868 GetEraGasPrice {
869 era_id: EraId,
870 responder: Responder<Option<u8>>,
871 },
872 DoProtocolUpgrade {
873 protocol_upgrade_config: ProtocolUpgradeConfig,
874 next_block_height: u64,
875 parent_hash: BlockHash,
876 parent_seed: Digest,
877 },
878 UpdatePreState {
879 new_pre_state: ExecutionPreState,
880 },
881}
882
883impl Display for ContractRuntimeRequest {
884 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
885 match self {
886 ContractRuntimeRequest::EnqueueBlockForExecution {
887 executable_block, ..
888 } => {
889 write!(formatter, "executable_block: {}", executable_block)
890 }
891 ContractRuntimeRequest::Query {
892 request: query_request,
893 ..
894 } => {
895 write!(formatter, "query request: {:?}", query_request)
896 }
897 ContractRuntimeRequest::QueryByPrefix { request, .. } => {
898 write!(formatter, "query by prefix request: {:?}", request)
899 }
900 ContractRuntimeRequest::GetBalance {
901 request: balance_request,
902 ..
903 } => write!(formatter, "balance request: {:?}", balance_request),
904 ContractRuntimeRequest::GetEraValidators { request, .. } => {
905 write!(formatter, "get era validators: {:?}", request)
906 }
907 ContractRuntimeRequest::GetSeigniorageRecipients { request, .. } => {
908 write!(formatter, "get seigniorage recipients for {:?}", request)
909 }
910 ContractRuntimeRequest::GetTaggedValues {
911 request: get_all_values_request,
912 ..
913 } => {
914 write!(
915 formatter,
916 "get all values request: {:?}",
917 get_all_values_request
918 )
919 }
920 ContractRuntimeRequest::GetExecutionResultsChecksum {
921 state_root_hash, ..
922 } => write!(
923 formatter,
924 "get execution results checksum under {}",
925 state_root_hash
926 ),
927 ContractRuntimeRequest::GetAddressableEntity {
928 state_root_hash,
929 entity_addr,
930 ..
931 } => {
932 write!(
933 formatter,
934 "get addressable_entity {} under {}",
935 entity_addr, state_root_hash
936 )
937 }
938 ContractRuntimeRequest::GetTrie { request, .. } => {
939 write!(formatter, "get trie: {:?}", request)
940 }
941 ContractRuntimeRequest::PutTrie { request, .. } => {
942 write!(formatter, "trie: {:?}", request)
943 }
944 ContractRuntimeRequest::SpeculativelyExecute {
945 transaction,
946 block_header,
947 ..
948 } => {
949 write!(
950 formatter,
951 "Execute {} on {}",
952 transaction.hash(),
953 block_header.state_root_hash()
954 )
955 }
956 ContractRuntimeRequest::UpdateRuntimePrice(_, era_gas_price) => {
957 write!(formatter, "updating price to {}", era_gas_price)
958 }
959 ContractRuntimeRequest::GetEraGasPrice { era_id, .. } => {
960 write!(formatter, "Get gas price for era {}", era_id)
961 }
962 ContractRuntimeRequest::GetEntryPointExists {
963 state_root_hash,
964 contract_hash,
965 entry_point_name,
966 ..
967 } => {
968 let formatted_contract_hash = HexFmt(contract_hash);
969 write!(
970 formatter,
971 "get entry point {}-{} under {}",
972 formatted_contract_hash, entry_point_name, state_root_hash
973 )
974 }
975 ContractRuntimeRequest::DoProtocolUpgrade {
976 protocol_upgrade_config,
977 ..
978 } => {
979 write!(
980 formatter,
981 "execute protocol upgrade against config: {:?}",
982 protocol_upgrade_config
983 )
984 }
985 ContractRuntimeRequest::UpdatePreState { new_pre_state } => {
986 write!(
987 formatter,
988 "Updating contract runtimes execution prestate: {:?}",
989 new_pre_state
990 )
991 }
992 }
993 }
994}
995
996#[derive(Debug, Serialize)]
998#[must_use]
999pub(crate) struct FetcherRequest<T: FetchItem> {
1000 pub(crate) id: T::Id,
1002 pub(crate) peer: NodeId,
1004 pub(crate) validation_metadata: Box<T::ValidationMetadata>,
1006 pub(crate) responder: Responder<FetchResult<T>>,
1008}
1009
1010impl<T: FetchItem> Display for FetcherRequest<T> {
1011 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
1012 write!(formatter, "request item by id {}", self.id)
1013 }
1014}
1015
1016#[derive(Debug, Serialize, DataSize)]
1018#[must_use]
1019pub(crate) struct TrieAccumulatorRequest {
1020 pub(crate) hash: Digest,
1022 pub(crate) peers: Vec<NodeId>,
1024 pub(crate) responder: Responder<Result<TrieAccumulatorResponse, TrieAccumulatorError>>,
1026}
1027
1028impl Display for TrieAccumulatorRequest {
1029 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
1030 write!(formatter, "request trie by hash {}", self.hash)
1031 }
1032}
1033
1034#[derive(Debug, Serialize)]
1035pub(crate) struct SyncGlobalStateRequest {
1036 pub(crate) block_hash: BlockHash,
1037 pub(crate) state_root_hash: Digest,
1038 #[serde(skip)]
1039 pub(crate) responder:
1040 Responder<Result<GlobalStateSynchronizerResponse, GlobalStateSynchronizerError>>,
1041}
1042
1043impl Display for SyncGlobalStateRequest {
1044 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
1045 write!(
1046 formatter,
1047 "request to sync global state at {}",
1048 self.block_hash
1049 )
1050 }
1051}
1052
1053#[derive(Debug, DataSize)]
1055#[must_use]
1056pub(crate) struct BlockValidationRequest {
1057 pub(crate) proposed_block_height: u64,
1059 pub(crate) block: ProposedBlock<ClContext>,
1061 pub(crate) sender: NodeId,
1063 pub(crate) responder: Responder<Result<(), Box<InvalidProposalError>>>,
1067}
1068
1069impl Display for BlockValidationRequest {
1070 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1071 let BlockValidationRequest { block, sender, .. } = self;
1072 write!(f, "validate block {} from {}", block, sender)
1073 }
1074}
1075
1076type BlockHeight = u64;
1077
1078#[derive(DataSize, Debug)]
1079#[must_use]
1080pub(crate) enum ConsensusRequest {
1082 Status(Responder<Option<ConsensusStatus>>),
1084 ValidatorChanges(Responder<ConsensusValidatorChanges>),
1086}
1087
1088#[derive(Debug, Serialize)]
1090pub(crate) enum ChainspecRawBytesRequest {
1091 GetChainspecRawBytes(Responder<Arc<ChainspecRawBytes>>),
1094}
1095
1096impl Display for ChainspecRawBytesRequest {
1097 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1098 match self {
1099 ChainspecRawBytesRequest::GetChainspecRawBytes(_) => {
1100 write!(f, "get chainspec raw bytes")
1101 }
1102 }
1103 }
1104}
1105
1106#[derive(Debug, Serialize)]
1108pub(crate) struct UpgradeWatcherRequest(pub(crate) Responder<Option<NextUpgrade>>);
1109
1110impl Display for UpgradeWatcherRequest {
1111 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1112 write!(f, "get next upgrade")
1113 }
1114}
1115
1116#[derive(Debug, Serialize)]
1117pub(crate) enum ReactorInfoRequest {
1118 ReactorState { responder: Responder<ReactorState> },
1119 LastProgress { responder: Responder<LastProgress> },
1120 Uptime { responder: Responder<Uptime> },
1121 NetworkName { responder: Responder<NetworkName> },
1122 BalanceHoldsInterval { responder: Responder<TimeDiff> },
1123}
1124
1125impl Display for ReactorInfoRequest {
1126 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1127 write!(
1128 f,
1129 "get reactor status: {}",
1130 match self {
1131 ReactorInfoRequest::ReactorState { .. } => "ReactorState",
1132 ReactorInfoRequest::LastProgress { .. } => "LastProgress",
1133 ReactorInfoRequest::Uptime { .. } => "Uptime",
1134 ReactorInfoRequest::NetworkName { .. } => "NetworkName",
1135 ReactorInfoRequest::BalanceHoldsInterval { .. } => "BalanceHoldsInterval",
1136 }
1137 )
1138 }
1139}
1140
1141#[derive(Debug, Serialize)]
1142#[allow(clippy::enum_variant_names)]
1143pub(crate) enum BlockAccumulatorRequest {
1144 GetPeersForBlock {
1145 block_hash: BlockHash,
1146 responder: Responder<Option<Vec<NodeId>>>,
1147 },
1148}
1149
1150impl Display for BlockAccumulatorRequest {
1151 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1152 match self {
1153 BlockAccumulatorRequest::GetPeersForBlock { block_hash, .. } => {
1154 write!(f, "get peers for {}", block_hash)
1155 }
1156 }
1157 }
1158}
1159
1160#[derive(Debug, Serialize)]
1161pub(crate) enum BlockSynchronizerRequest {
1162 NeedNext,
1163 DishonestPeers,
1164 SyncGlobalStates(Vec<(BlockHash, Digest)>),
1165 Status {
1166 responder: Responder<BlockSynchronizerStatus>,
1167 },
1168}
1169
1170impl Display for BlockSynchronizerRequest {
1171 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1172 match self {
1173 BlockSynchronizerRequest::NeedNext => {
1174 write!(f, "block synchronizer request: need next")
1175 }
1176 BlockSynchronizerRequest::DishonestPeers => {
1177 write!(f, "block synchronizer request: dishonest peers")
1178 }
1179 BlockSynchronizerRequest::Status { .. } => {
1180 write!(f, "block synchronizer request: status")
1181 }
1182 BlockSynchronizerRequest::SyncGlobalStates(_) => {
1183 write!(f, "request to sync global states")
1184 }
1185 }
1186 }
1187}
1188
1189#[derive(DataSize, Debug, Serialize)]
1191pub(crate) struct SetNodeStopRequest {
1192 pub(crate) stop_at: Option<StopAtSpec>,
1196 pub(crate) responder: Responder<Option<StopAtSpec>>,
1198}
1199
1200impl Display for SetNodeStopRequest {
1201 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1202 match self.stop_at {
1203 None => f.write_str("clear node stop"),
1204 Some(stop_at) => write!(f, "set node stop to: {}", stop_at),
1205 }
1206 }
1207}
1208
1209#[derive(DataSize, Debug, Serialize)]
1211pub(crate) struct AcceptTransactionRequest {
1212 pub(crate) transaction: Transaction,
1213 pub(crate) is_speculative: bool,
1214 pub(crate) responder: Responder<Result<(), transaction_acceptor::Error>>,
1215}
1216
1217impl Display for AcceptTransactionRequest {
1218 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1219 write!(
1220 f,
1221 "accept transaction {} is_speculative: {}",
1222 self.transaction.hash(),
1223 self.is_speculative
1224 )
1225 }
1226}