@@ -3810,6 +3810,15 @@ impl NakamotoChainState {
3810
3810
active_reward_set : & RewardSet ,
3811
3811
) -> Result < ( ) , ChainstateError > {
3812
3812
if !tenure_block_commit. treatment . is_empty ( ) {
3813
+ let address_to_indeces: HashMap < _ , Vec < _ > > = active_reward_set
3814
+ . rewarded_addresses
3815
+ . iter ( )
3816
+ . enumerate ( )
3817
+ . fold ( HashMap :: new ( ) , |mut map, ( ix, addr) | {
3818
+ map. entry ( addr) . or_insert_with ( Vec :: new) . push ( ix) ;
3819
+ map
3820
+ } ) ;
3821
+
3813
3822
// our block commit issued a punishment, check the reward set and bitvector
3814
3823
// to ensure that this was valid.
3815
3824
for treated_addr in tenure_block_commit. treatment . iter ( ) {
@@ -3820,24 +3829,19 @@ impl NakamotoChainState {
3820
3829
}
3821
3830
// otherwise, we need to find the indices in the rewarded_addresses
3822
3831
// corresponding to this address.
3823
- let address_indices = active_reward_set
3824
- . rewarded_addresses
3825
- . iter ( )
3826
- . enumerate ( )
3827
- . filter_map ( |( ix, addr) | {
3828
- if addr == treated_addr. deref ( ) {
3829
- Some ( ix)
3830
- } else {
3831
- None
3832
- }
3833
- } ) ;
3832
+ let empty_vec = vec ! [ ] ;
3833
+ let address_indices = address_to_indeces
3834
+ . get ( treated_addr. deref ( ) )
3835
+ . unwrap_or ( & empty_vec) ;
3836
+
3834
3837
// if any of them are 0, punishment is okay.
3835
3838
// if all of them are 1, punishment is not okay.
3836
3839
// if all of them are 0, *must* have punished
3837
3840
let bitvec_values: Result < Vec < _ > , ChainstateError > = address_indices
3841
+ . iter ( )
3838
3842
. map (
3839
3843
|ix| {
3840
- let ix = u16:: try_from ( ix)
3844
+ let ix = u16:: try_from ( * ix)
3841
3845
. map_err ( |_| ChainstateError :: InvalidStacksBlock ( "Reward set index outside of u16" . into ( ) ) ) ?;
3842
3846
let bitvec_value = block_bitvec. get ( ix)
3843
3847
. unwrap_or_else ( || {
0 commit comments