@@ -1122,8 +1122,10 @@ fn vote_equivocation_current_voters_duplicate() {
1122
1122
1123
1123
// Current block author + slot matches that of the vote
1124
1124
let voter_keypair = Keypair :: generate ( ) ;
1125
+ let other_voter_keypair = Keypair :: generate ( ) ;
1125
1126
let slot = Subspace :: current_slot ( ) ;
1126
1127
let reward_address = 0 ;
1128
+ let other_reward_address = 1 ;
1127
1129
1128
1130
let signed_vote = create_signed_vote (
1129
1131
& voter_keypair,
@@ -1153,15 +1155,43 @@ fn vote_equivocation_current_voters_duplicate() {
1153
1155
map
1154
1156
} ) ;
1155
1157
1158
+ // Insert another voter that is not equivocating
1159
+ {
1160
+ let other_signed_vote = create_signed_vote (
1161
+ & other_voter_keypair,
1162
+ 2 ,
1163
+ frame_system:: Pallet :: < Test > :: block_hash ( 1 ) ,
1164
+ slot,
1165
+ Default :: default ( ) ,
1166
+ Default :: default ( ) ,
1167
+ archived_segment,
1168
+ other_reward_address,
1169
+ pallet:: SolutionRanges :: < Test > :: get ( ) . current ,
1170
+ pallet:: SolutionRanges :: < Test > :: get ( ) . voting_current ,
1171
+ ) ;
1172
+
1173
+ CurrentBlockVoters :: < Test > :: mutate ( |map| {
1174
+ map. as_mut ( ) . unwrap ( ) . insert (
1175
+ (
1176
+ PublicKey :: from ( other_voter_keypair. public . to_bytes ( ) ) ,
1177
+ other_signed_vote. vote . solution ( ) . sector_index ,
1178
+ other_signed_vote. vote . solution ( ) . piece_offset ,
1179
+ other_signed_vote. vote . solution ( ) . chunk ,
1180
+ slot,
1181
+ ) ,
1182
+ ( Some ( other_reward_address) , other_signed_vote. signature ) ,
1183
+ ) ;
1184
+ } ) ;
1185
+ }
1186
+
1156
1187
// Identical vote submitted twice leads to duplicate error
1157
1188
assert_err ! (
1158
1189
super :: check_vote:: <Test >( & signed_vote, true ) ,
1159
1190
CheckVoteError :: DuplicateVote
1160
1191
) ;
1161
1192
1162
- CurrentBlockVoters :: < Test > :: put ( {
1163
- let mut map = BTreeMap :: new ( ) ;
1164
- map. insert (
1193
+ CurrentBlockVoters :: < Test > :: mutate ( |map| {
1194
+ map. as_mut ( ) . unwrap ( ) . insert (
1165
1195
(
1166
1196
PublicKey :: from ( voter_keypair. public . to_bytes ( ) ) ,
1167
1197
signed_vote. vote . solution ( ) . sector_index ,
@@ -1171,14 +1201,17 @@ fn vote_equivocation_current_voters_duplicate() {
1171
1201
) ,
1172
1202
( Some ( reward_address) , RewardSignature :: from ( [ 0 ; 64 ] ) ) ,
1173
1203
) ;
1174
- map
1175
1204
} ) ;
1176
1205
1177
1206
// Different vote for the same sector index and time slot leads to equivocation
1178
1207
Subspace :: pre_dispatch_vote ( & signed_vote) . unwrap ( ) ;
1179
1208
1180
- // Voter doesn't get reward after equivocation
1181
- assert_eq ! ( Subspace :: find_voting_reward_addresses( ) . len( ) , 0 ) ;
1209
+ // Equivocating voter doesn't get reward, but the other voter does
1210
+ assert_eq ! ( Subspace :: find_voting_reward_addresses( ) . len( ) , 1 ) ;
1211
+ assert_eq ! (
1212
+ Subspace :: find_voting_reward_addresses( ) . first( ) . unwrap( ) ,
1213
+ & other_reward_address
1214
+ ) ;
1182
1215
} ) ;
1183
1216
}
1184
1217
0 commit comments