22
22
//! peers. Verified in this context means, the erasure chunks contained merkle proof
23
23
//! is checked.
24
24
25
+ #[ deny( unused_extern_crates, unused_results, unused_qualifications) ]
26
+
25
27
use codec:: { Decode , Encode } ;
26
- use futures:: { channel:: oneshot, FutureExt } ;
28
+ use futures:: { channel:: oneshot, FutureExt , TryFutureExt } ;
27
29
28
30
use sp_core:: crypto:: Public ;
29
31
use sp_keystore:: { CryptoStore , SyncCryptoStorePtr } ;
@@ -53,27 +55,71 @@ use polkadot_node_network_protocol::{
53
55
NetworkBridgeEvent ,
54
56
} ;
55
57
use std:: collections:: { HashMap , HashSet } ;
56
- use std:: io;
57
58
use std:: iter;
58
59
use thiserror:: Error ;
59
60
const TARGET : & ' static str = "avad" ;
60
61
61
62
#[ derive( Debug , Error ) ]
62
63
enum Error {
63
- #[ error( transparent) ]
64
- Erasure ( polkadot_erasure_coding:: Error ) ,
65
-
66
- #[ error( transparent) ]
67
- Io ( io:: Error ) ,
64
+ #[ error( "Sending PendingAvailability query failed" ) ]
65
+ QueryPendingAvailabilitySendQuery ( #[ source] SubsystemError ) ,
66
+ #[ error( "Response channel to obtain PendingAvailability failed" ) ]
67
+ QueryPendingAvailabilityResponseChannel ( #[ source] oneshot:: Canceled ) ,
68
+ #[ error( "RuntimeAPI to obtain PendingAvailability failed" ) ]
69
+ QueryPendingAvailability ( #[ source] RuntimeApiError ) ,
70
+
71
+ #[ error( "Sending StoreChunk query failed" ) ]
72
+ StoreChunkSendQuery ( #[ source] SubsystemError ) ,
73
+ #[ error( "Response channel to obtain StoreChunk failed" ) ]
74
+ StoreChunkResponseChannel ( #[ source] oneshot:: Canceled ) ,
75
+
76
+ #[ error( "Sending QueryChunk query failed" ) ]
77
+ QueryChunkSendQuery ( #[ source] SubsystemError ) ,
78
+ #[ error( "Response channel to obtain QueryChunk failed" ) ]
79
+ QueryChunkResponseChannel ( #[ source] oneshot:: Canceled ) ,
80
+
81
+ #[ error( "Sending QueryAncestors query failed" ) ]
82
+ QueryAncestorsSendQuery ( #[ source] SubsystemError ) ,
83
+ #[ error( "Response channel to obtain QueryAncestors failed" ) ]
84
+ QueryAncestorsResponseChannel ( #[ source] oneshot:: Canceled ) ,
85
+ #[ error( "RuntimeAPI to obtain QueryAncestors failed" ) ]
86
+ QueryAncestors ( #[ source] ChainApiError ) ,
87
+
88
+
89
+ #[ error( "Sending QuerySession query failed" ) ]
90
+ QuerySessionSendQuery ( #[ source] SubsystemError ) ,
91
+ #[ error( "Response channel to obtain QuerySession failed" ) ]
92
+ QuerySessionResponseChannel ( #[ source] oneshot:: Canceled ) ,
93
+ #[ error( "RuntimeAPI to obtain QuerySession failed" ) ]
94
+ QuerySession ( #[ source] RuntimeApiError ) ,
95
+
96
+ #[ error( "Sending QueryValidators query failed" ) ]
97
+ QueryValidatorsSendQuery ( #[ source] SubsystemError ) ,
98
+ #[ error( "Response channel to obtain QueryValidators failed" ) ]
99
+ QueryValidatorsResponseChannel ( #[ source] oneshot:: Canceled ) ,
100
+ #[ error( "RuntimeAPI to obtain QueryValidators failed" ) ]
101
+ QueryValidators ( #[ source] RuntimeApiError ) ,
102
+
103
+ #[ error( "Sending AvailabilityCores query failed" ) ]
104
+ AvailabilityCoresSendQuery ( #[ source] SubsystemError ) ,
105
+ #[ error( "Response channel to obtain AvailabilityCores failed" ) ]
106
+ AvailabilityCoresResponseChannel ( #[ source] oneshot:: Canceled ) ,
107
+ #[ error( "RuntimeAPI to obtain AvailabilityCores failed" ) ]
108
+ AvailabilityCores ( #[ source] RuntimeApiError ) ,
109
+
110
+ #[ error( "Sending AvailabilityCores query failed" ) ]
111
+ QueryAvailabilitySendQuery ( #[ source] SubsystemError ) ,
112
+ #[ error( "Response channel to obtain AvailabilityCores failed" ) ]
113
+ QueryAvailabilityResponseChannel ( #[ source] oneshot:: Canceled ) ,
114
+
115
+ #[ error( "Sending out a peer report message" ) ]
116
+ ReportPeerMessageSend ( #[ source] SubsystemError ) ,
68
117
69
- #[ error( transparent) ]
70
- Oneshot ( oneshot:: Canceled ) ,
71
-
72
- #[ error( transparent) ]
73
- RuntimeApi ( RuntimeApiError ) ,
118
+ #[ error( "Sending a gossip message" ) ]
119
+ TrackedGossipMessage ( #[ source] SubsystemError ) ,
74
120
75
- #[ error( transparent ) ]
76
- ChainApi ( ChainApiError ) ,
121
+ #[ error( "Receive channel closed" ) ]
122
+ IncomingMessageChannel ( # [ source ] SubsystemError ) ,
77
123
}
78
124
79
125
type Result < T > = std:: result:: Result < T , Error > ;
@@ -508,7 +554,7 @@ where
508
554
) ,
509
555
) )
510
556
. await
511
- . map_err :: < Error , _ > ( Into :: into ) ?;
557
+ . map_err ( |e| Error :: TrackedGossipMessage ( e ) ) ?;
512
558
513
559
metrics. on_chunk_distributed ( ) ;
514
560
}
@@ -730,7 +776,10 @@ impl AvailabilityDistributionSubsystem {
730
776
// work: process incoming messages from the overseer.
731
777
let mut state = ProtocolState :: default ( ) ;
732
778
loop {
733
- let message = ctx. recv ( ) . await . map_err :: < Error , _ > ( Into :: into) ?;
779
+ let message = ctx
780
+ . recv ( )
781
+ . await
782
+ . map_err ( |e| Error :: IncomingMessageChannel ( e) ) ?;
734
783
match message {
735
784
FromOverseer :: Communication {
736
785
msg : AvailabilityDistributionMessage :: NetworkBridgeUpdateV1 ( event) ,
@@ -770,9 +819,9 @@ where
770
819
fn start ( self , ctx : Context ) -> SpawnedSubsystem {
771
820
772
821
let future = self . run ( ctx)
773
- . map_err ( |e| {
822
+ . map_err ( |e|
774
823
SubsystemError :: with_origin ( "availability-distribution" , e)
775
- } )
824
+ )
776
825
. map ( |_| ( ) ) . boxed ( ) ;
777
826
778
827
SpawnedSubsystem {
@@ -881,14 +930,16 @@ where
881
930
{
882
931
let ( tx, rx) = oneshot:: channel ( ) ;
883
932
ctx. send_message ( AllMessages :: RuntimeApi ( RuntimeApiMessage :: Request (
884
- relay_parent,
885
- RuntimeApiRequest :: AvailabilityCores ( tx) ,
886
- ) ) )
887
- . await
888
- . map_err :: < Error , _ > ( Into :: into ) ?;
933
+ relay_parent,
934
+ RuntimeApiRequest :: AvailabilityCores ( tx) ,
935
+ ) ) )
936
+ . await
937
+ . map_err ( |e| Error :: AvailabilityCoresSendQuery ( e ) ) ?;
889
938
890
939
let all_para_ids: Vec < _ > = rx
891
- . await ??;
940
+ . await
941
+ . map_err ( |e| Error :: AvailabilityCoresResponseChannel ( e) ) ?
942
+ . map_err ( |e| Error :: AvailabilityCores ( e) ) ?;
892
943
893
944
let occupied_para_ids = all_para_ids
894
945
. into_iter ( )
@@ -915,10 +966,10 @@ where
915
966
peer
916
967
) ;
917
968
ctx. send_message ( AllMessages :: NetworkBridge (
918
- NetworkBridgeMessage :: ReportPeer ( peer, rep) ,
919
- ) )
920
- . await
921
- . map_err :: < Error , _ > ( Into :: into )
969
+ NetworkBridgeMessage :: ReportPeer ( peer, rep) ,
970
+ ) )
971
+ . await
972
+ . map_err ( |e| Error :: ReportPeerMessageSend ( e ) )
922
973
}
923
974
924
975
/// Query the proof of validity for a particular candidate hash.
@@ -931,10 +982,14 @@ where
931
982
{
932
983
let ( tx, rx) = oneshot:: channel ( ) ;
933
984
ctx. send_message ( AllMessages :: AvailabilityStore (
934
- AvailabilityStoreMessage :: QueryDataAvailability ( candidate_hash, tx) ,
935
- ) )
936
- . await ?;
937
- rx. await . map_err :: < Error , _ > ( Into :: into)
985
+ AvailabilityStoreMessage :: QueryDataAvailability ( candidate_hash, tx) ,
986
+ ) )
987
+ . await
988
+ . map_err ( |e| Error :: QueryAvailabilitySendQuery ( e) )
989
+ ?;
990
+ rx
991
+ . await
992
+ . map_err ( |e| Error :: QueryAvailabilityResponseChannel ( e) )
938
993
}
939
994
940
995
@@ -950,8 +1005,10 @@ where
950
1005
ctx. send_message ( AllMessages :: AvailabilityStore (
951
1006
AvailabilityStoreMessage :: QueryChunk ( candidate_hash, validator_index, tx) ,
952
1007
) )
953
- . await ?;
954
- rx. await . map_err :: < Error , _ > ( Into :: into)
1008
+ . await
1009
+ . map_err ( |e| Error :: QueryChunkSendQuery ( e) ) ?;
1010
+ rx. await
1011
+ . map_err ( |e| Error :: QueryChunkResponseChannel ( e) )
955
1012
}
956
1013
957
1014
@@ -966,9 +1023,13 @@ where
966
1023
{
967
1024
let ( tx, rx) = oneshot:: channel ( ) ;
968
1025
ctx. send_message ( AllMessages :: AvailabilityStore (
969
- AvailabilityStoreMessage :: StoreChunk ( candidate_hash, validator_index, erasure_chunk, tx) ,
970
- ) ) . await ?;
971
- rx. await . map_err :: < Error , _ > ( Into :: into)
1026
+ AvailabilityStoreMessage :: StoreChunk ( candidate_hash, validator_index, erasure_chunk, tx) ,
1027
+ ) )
1028
+ . await
1029
+ . map_err ( |e| Error :: StoreChunkSendQuery ( e) ) ?;
1030
+ rx
1031
+ . await
1032
+ . map_err ( |e| Error :: StoreChunkResponseChannel ( e) )
972
1033
}
973
1034
974
1035
/// Request the head data for a particular para.
@@ -985,9 +1046,12 @@ where
985
1046
relay_parent,
986
1047
RuntimeApiRequest :: CandidatePendingAvailability ( para, tx) ,
987
1048
) ) )
988
- . await ?;
989
- rx. await ?
990
- . map_err :: < Error , _ > ( Into :: into)
1049
+ . await
1050
+ . map_err ( |e| Error :: QueryPendingAvailabilitySendQuery ( e) ) ?;
1051
+
1052
+ rx. await
1053
+ . map_err ( |e| Error :: QueryPendingAvailabilityResponseChannel ( e) ) ?
1054
+ . map_err ( |e| Error :: QueryPendingAvailability ( e) )
991
1055
}
992
1056
993
1057
/// Query the validator set.
@@ -1005,9 +1069,11 @@ where
1005
1069
) ) ;
1006
1070
1007
1071
ctx. send_message ( query_validators)
1008
- . await ?;
1009
- rx. await ?
1010
- . map_err :: < Error , _ > ( Into :: into)
1072
+ . await
1073
+ . map_err ( |e| Error :: QueryValidatorsSendQuery ( e) ) ?;
1074
+ rx. await
1075
+ . map_err ( |e| Error :: QueryValidatorsResponseChannel ( e) ) ?
1076
+ . map_err ( |e| Error :: QueryValidators ( e) )
1011
1077
}
1012
1078
1013
1079
/// Query the hash of the `K` ancestors
@@ -1027,9 +1093,11 @@ where
1027
1093
} ) ;
1028
1094
1029
1095
ctx. send_message ( query_ancestors)
1030
- . await ?;
1031
- rx. await ?
1032
- . map_err :: < Error , _ > ( Into :: into)
1096
+ . await
1097
+ . map_err ( |e| Error :: QueryAncestorsSendQuery ( e) ) ?;
1098
+ rx. await
1099
+ . map_err ( |e| Error :: QueryAncestorsResponseChannel ( e) ) ?
1100
+ . map_err ( |e| Error :: QueryAncestors ( e) )
1033
1101
}
1034
1102
1035
1103
/// Query the session index of a relay parent
@@ -1047,9 +1115,11 @@ where
1047
1115
) ) ;
1048
1116
1049
1117
ctx. send_message ( query_session_idx_for_child)
1050
- . await ?;
1051
- rx. await ?
1052
- . map_err :: < Error , _ > ( Into :: into)
1118
+ . await
1119
+ . map_err ( |e| Error :: QuerySessionSendQuery ( e) ) ?;
1120
+ rx. await
1121
+ . map_err ( |e| Error :: QuerySessionResponseChannel ( e) ) ?
1122
+ . map_err ( |e| Error :: QuerySession ( e) )
1053
1123
}
1054
1124
1055
1125
/// Queries up to k ancestors with the constraints of equiv session
0 commit comments