depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

analysis.rs (1740B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2022-2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 use tracing::warn;
     18 
     19 use super::LoopResult;
     20 use crate::rpc::{ChainTipsStatus, Rpc};
     21 
     22 /// Analyse blockchain behavior and return the new confirmation delay
     23 pub async fn analysis(rpc: &mut Rpc, current: u32, max: u32) -> LoopResult<u32> {
     24     // Get biggest known valid fork
     25     let fork = rpc
     26         .get_chain_tips()
     27         .await?
     28         .into_iter()
     29         .filter_map(|t| (t.status == ChainTipsStatus::ValidFork).then_some(t.length))
     30         .max()
     31         .unwrap_or(0) as u32;
     32     // If new fork is bigger than what current confirmation delay protect against
     33     if fork >= current {
     34         // Limit confirmation growth
     35         let new_conf = fork.saturating_add(1).min(max);
     36         warn!(
     37             target: "analysis",
     38             "found dangerous fork of {fork} blocks, adapt confirmation to {new_conf} blocks capped at {max}, you should update taler.conf"
     39         );
     40         return Ok(new_conf);
     41     }
     42 
     43     // TODO smarter analysis: suspicious transaction value, limit wire bitcoin throughput
     44     Ok(current)
     45 }