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
crate::ix!();

pub trait MaybePunishNodeForTx {

    fn maybe_punish_node_for_tx(self: Arc<Self>, 
        nodeid:  NodeId,
        state:   &TxValidationState,
        message: Option<&str>) -> bool;
}

impl MaybePunishNodeForTx for PeerManager {

    /**
      | Potentially disconnect and discourage
      | a node based on the contents of a TxValidationState
      | object
      | 
      | 
      | -----------
      | @return
      | 
      | Returns true if the peer was punished
      | (probably disconnected)
      |
      */
    fn maybe_punish_node_for_tx(self: Arc<Self>, 
        nodeid:  NodeId,
        state:   &TxValidationState,
        message: Option<&str>) -> bool {

        let message: &str = message.unwrap_or("");
        
        match state.get_result() {
            TxValidationResult::TX_RESULT_UNSET  => { },

            TxValidationResult::TX_CONSENSUS  => {
                //  The node is providing invalid data:
                self.misbehaving(nodeid,100,message);
                return true;
            },

            // Conflicting (but not necessarily
            // invalid) data or different policy:
            TxValidationResult::TX_RECENT_CONSENSUS_CHANGE  
                | TxValidationResult::TX_INPUTS_NOT_STANDARD
                | TxValidationResult::TX_NOT_STANDARD
                | TxValidationResult::TX_MISSING_INPUTS
                | TxValidationResult::TX_PREMATURE_SPEND
                | TxValidationResult::TX_WITNESS_MUTATED
                | TxValidationResult::TX_WITNESS_STRIPPED
                | TxValidationResult::TX_CONFLICT
                | TxValidationResult::TX_MEMPOOL_POLICY
                => { },
        }

        if message != "" {
            log_print!(LogFlags::NET, "peer=%d: %s\n", nodeid, message);
        }

        false
    }
}