@@ -100,6 +100,7 @@ impl EcdsaComplaintHandlerImpl {
100
100
block_reader : & dyn EcdsaBlockReader ,
101
101
) -> EcdsaChangeSet {
102
102
let active_transcripts = self . active_transcripts ( block_reader) ;
103
+ let requested_transcripts = self . requested_transcripts ( block_reader) ;
103
104
104
105
// Collection of validated complaints <complainer Id, transcript Id, dealer Id>
105
106
let mut validated_complaints = BTreeSet :: new ( ) ;
@@ -125,6 +126,7 @@ impl EcdsaComplaintHandlerImpl {
125
126
match Action :: action (
126
127
block_reader,
127
128
& active_transcripts,
129
+ & requested_transcripts,
128
130
complaint. idkg_complaint . transcript_id . source_height ( ) ,
129
131
& complaint. idkg_complaint . transcript_id ,
130
132
) {
@@ -182,6 +184,10 @@ impl EcdsaComplaintHandlerImpl {
182
184
. validated ( )
183
185
. complaints ( )
184
186
. filter ( |( _, signed_complaint) | {
187
+ // Do not try to create openings for own complaints.
188
+ if signed_complaint. signature . signer == self . node_id {
189
+ return false ;
190
+ }
185
191
let complaint = signed_complaint. get ( ) ;
186
192
!self . has_node_issued_opening (
187
193
ecdsa_pool,
@@ -217,6 +223,7 @@ impl EcdsaComplaintHandlerImpl {
217
223
block_reader : & dyn EcdsaBlockReader ,
218
224
) -> EcdsaChangeSet {
219
225
let active_transcripts = self . active_transcripts ( block_reader) ;
226
+ let requested_transcripts = self . requested_transcripts ( block_reader) ;
220
227
221
228
// Collection of validated openings <opener Id, transcript Id, dealer Id>
222
229
let mut validated_openings = BTreeSet :: new ( ) ;
@@ -240,6 +247,7 @@ impl EcdsaComplaintHandlerImpl {
240
247
match Action :: action (
241
248
block_reader,
242
249
& active_transcripts,
250
+ & requested_transcripts,
243
251
opening. idkg_opening . transcript_id . source_height ( ) ,
244
252
& opening. idkg_opening . transcript_id ,
245
253
) {
@@ -749,6 +757,17 @@ impl EcdsaComplaintHandlerImpl {
749
757
. map ( |transcript_ref| ( transcript_ref. transcript_id , * transcript_ref) )
750
758
. collect :: < BTreeMap < _ , _ > > ( )
751
759
}
760
+
761
+ /// Returns the requested transcript map.
762
+ fn requested_transcripts (
763
+ & self ,
764
+ block_reader : & dyn EcdsaBlockReader ,
765
+ ) -> BTreeSet < IDkgTranscriptId > {
766
+ block_reader
767
+ . requested_transcripts ( )
768
+ . map ( |transcript_ref| transcript_ref. transcript_id )
769
+ . collect :: < BTreeSet < _ > > ( )
770
+ }
752
771
}
753
772
754
773
impl EcdsaComplaintHandler for EcdsaComplaintHandlerImpl {
@@ -922,6 +941,7 @@ impl<'a> Action<'a> {
922
941
fn action (
923
942
block_reader : & ' a dyn EcdsaBlockReader ,
924
943
active_transcripts : & ' a BTreeMap < IDkgTranscriptId , TranscriptRef > ,
944
+ requested_transcripts : & ' a BTreeSet < IDkgTranscriptId > ,
925
945
msg_height : Height ,
926
946
msg_transcript_id : & IDkgTranscriptId ,
927
947
) -> Action < ' a > {
@@ -931,10 +951,17 @@ impl<'a> Action<'a> {
931
951
return Action :: Defer ;
932
952
}
933
953
934
- match active_transcripts. get ( msg_transcript_id) {
935
- Some ( transcript_ref) => Action :: Process ( transcript_ref) ,
936
- None => Action :: Drop ,
954
+ if let Some ( transcript_ref) = active_transcripts. get ( msg_transcript_id) {
955
+ return Action :: Process ( transcript_ref) ;
956
+ }
957
+
958
+ // The transcript is not yet completed on this node, process
959
+ // the message later when it is.
960
+ if requested_transcripts. contains ( msg_transcript_id) {
961
+ return Action :: Defer ;
937
962
}
963
+
964
+ Action :: Drop
938
965
}
939
966
}
940
967
@@ -955,44 +982,53 @@ mod tests {
955
982
// Tests the Action logic
956
983
#[ test]
957
984
fn test_ecdsa_complaint_action ( ) {
958
- let ( id_1, id_2, id_3, id_4) = (
985
+ let ( id_1, id_2, id_3, id_4, id_5 ) = (
959
986
create_transcript_id ( 1 ) ,
960
987
create_transcript_id ( 2 ) ,
961
988
create_transcript_id ( 3 ) ,
962
989
create_transcript_id ( 4 ) ,
990
+ create_transcript_id ( 5 ) ,
963
991
) ;
964
992
965
993
let ref_1 = TranscriptRef :: new ( Height :: new ( 10 ) , id_1) ;
966
994
let ref_2 = TranscriptRef :: new ( Height :: new ( 20 ) , id_2) ;
967
995
let block_reader =
968
996
TestEcdsaBlockReader :: for_complainer_test ( Height :: new ( 100 ) , vec ! [ ref_1, ref_2] ) ;
969
- let mut active_transcripts = BTreeMap :: new ( ) ;
970
- active_transcripts. insert ( id_1, ref_1) ;
971
- active_transcripts. insert ( id_2, ref_2) ;
997
+ let mut active = BTreeMap :: new ( ) ;
998
+ active. insert ( id_1, ref_1) ;
999
+ active. insert ( id_2, ref_2) ;
1000
+ let mut requested = BTreeSet :: new ( ) ;
1001
+ requested. insert ( id_5) ;
972
1002
973
1003
// Message from a node ahead of us
974
1004
assert_eq ! (
975
- Action :: action( & block_reader, & active_transcripts , Height :: from( 200 ) , & id_3) ,
1005
+ Action :: action( & block_reader, & active , & requested , Height :: from( 200 ) , & id_3) ,
976
1006
Action :: Defer
977
1007
) ;
978
1008
979
1009
// Messages for transcripts not currently active
980
1010
assert_eq ! (
981
- Action :: action( & block_reader, & active_transcripts , Height :: from( 10 ) , & id_3) ,
1011
+ Action :: action( & block_reader, & active , & requested , Height :: from( 10 ) , & id_3) ,
982
1012
Action :: Drop
983
1013
) ;
984
1014
assert_eq ! (
985
- Action :: action( & block_reader, & active_transcripts , Height :: from( 20 ) , & id_4) ,
1015
+ Action :: action( & block_reader, & active , & requested , Height :: from( 20 ) , & id_4) ,
986
1016
Action :: Drop
987
1017
) ;
988
1018
1019
+ // Messages for transcripts not currently active but requested
1020
+ assert_eq ! (
1021
+ Action :: action( & block_reader, & active, & requested, Height :: from( 10 ) , & id_5) ,
1022
+ Action :: Defer
1023
+ ) ;
1024
+
989
1025
// Messages for transcripts currently active
990
1026
assert ! ( matches!(
991
- Action :: action( & block_reader, & active_transcripts , Height :: from( 10 ) , & id_1) ,
1027
+ Action :: action( & block_reader, & active , & requested , Height :: from( 10 ) , & id_1) ,
992
1028
Action :: Process ( _)
993
1029
) ) ;
994
1030
assert ! ( matches!(
995
- Action :: action( & block_reader, & active_transcripts , Height :: from( 20 ) , & id_2) ,
1031
+ Action :: action( & block_reader, & active , & requested , Height :: from( 20 ) , & id_2) ,
996
1032
Action :: Process ( _)
997
1033
) ) ;
998
1034
}
0 commit comments