1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
crate::ix!();

impl BlockChecked for PeerManager {

    /**
      | Handle invalid block rejection and
      | consequent peer discouragement, maintain
      | which peers announce compact blocks.
      |
      */
    fn block_checked(self: Arc<Self>, 
        block: &Block,
        state: &BlockValidationState)  {

        let mut guard = CS_MAIN.lock();

        let hash: u256 = block.get_hash();

        let cself = self.clone();

        let mut inner = self.inner.lock();

        let it = inner.map_block_source.get(&hash);

        // If the block failed validation, we know
        // where it came from and we're still
        // connected to that peer, maybe punish.
        if state.is_invalid() 
        && it != None 
        && create_state(it.as_ref().unwrap().0).is_some() {

            cself.maybe_punish_node_for_block(

                /*nodeid=*/ 
                it.as_ref().unwrap().0, 

                state, 

                /*via_compact_block=*/ 
                !it.as_ref().unwrap().1,

                None
            );

        } else {

            let mbif = inner.map_blocks_in_flight.lock();

            if state.is_valid() 
            && !cself.chainman.get().active_chainstate().is_initial_block_download() 
            && (mbif.get(&hash).is_some() == (mbif.len() == 1))
            {

                if it.is_some() {

                    cself.maybe_set_peer_as_announcing_header_and_ids(
                        it.as_ref().unwrap().0
                    );
                }
            }
        }

        if it.is_some() {
            inner.map_block_source.remove(&hash);
        }
    }
}