• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 17372468680

01 Sep 2025 08:43AM UTC coverage: 60.111% (-1.0%) from 61.105%
17372468680

push

github

SWvheerden
feat: improve header sync (#7421)

Description
---
When we have a valid PoW equal to or higher than what we have or what
has been advertised by the sync peer, we need to commit the headers, so
any downstream block sync error does not invalidate the headers that
have been downloaded.

_**Edit:** When block sync fails, we also make sure to swap to the best
PoW chain, also preserving banked headers if we do not need to reorg._

Closes #7342

Motivation and Context
---
See #7342

How Has This Been Tested?
---
System-level tests passed:
- Synching a previously synced node, a couple of days old.
- Syncing from scratch, encountering multiple block-sync failures, but
using the good PoW headers already banked.
```rust
   51952: 2025-08-18 16:07:02.097680100 [c::bn::block_sync] DEBUG Validating block body #22624 (PoW = RandomXTari, input(s): 1, output(s): 54, kernel(s): 2, latency: 108.00µs)
   51961: 2025-08-18 16:07:02.111648900 [c::bn::block_sync] DEBUG Validated in 14ms. Storing block body #22624 (PoW = RandomXTari, input(s): 1, output(s): 54, kernel(s): 2)
   51962: 2025-08-18 16:07:02.111668100 [c::bn::block_sync] TRACE Hash: <a class=hub.com/tari-project/tari/commit/91a1fbccc1f94e2aa93b6efdaf9c3fbf16d0588c">91a1fbccc<a href="https://github.com/tari-project/tari/commit/6fb8d66c20efe20d9ba71db70213e46332f9e8f5">3458b7ef444e605f62375077
   54024: 2025-08-18 16:11:06.389482300 [c::bn::block_sync] WARN  Peer did not supply all the blocks they claimed they had: Their claim - height: 74721, accumulated difficulty: <a class="double-link" href="https://github.com/tari-project/tari/commit/4089235547434023187024157117581153168163">408923554</a><a href="https://github.com/tari-project/tari/commit/6fb8d66c20efe20d9ba71db70213e46332f9e8f5">715651441378. Our status after block sync - height: 22624, accumulated difficulty: </a><a class="double-link" href="https://github.com/tari-project/tari/commit/1547640955349056263010512134240412613668">154764095</a><a href="https://github.com/tari-project/tari/commit/6fb8d66c20efe20d9ba71db70213e46332f9e8f5">889130919000
   54028: 2025-08-18 16:11:06.390047900 [c::bn::block_sync] WARN  Block sync failed - best header: 74723/1bcf293971df2d6c888a6589dca3a323b, best block: 22624/91a1fbccc1f94e2aa93b6efdaf9c3fbf16d0588c3458b7ef444e605f62375077. No more sync peers available: Block sync failed
   54109: 2025-08-18 16:11:11.596105400 [c::bn::header_sync] DEBUG Starting header sync.
   54110: 2025-08-18 16:11:11.59617... (continued)

33 of 132 new or added lines in 3 files covered. (25.0%)

1427 existing lines in 30 files now uncovered.

71522 of 118983 relevant lines covered (60.11%)

536188.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_layer/core/src/base_node/proto/rpc.rs
1
//  Copyright 2020, The Tari Project
2
//
3
//  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
//  following conditions are met:
5
//
6
//  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
//  disclaimer.
8
//
9
//  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
//  following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
//  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
//  products derived from this software without specific prior written permission.
14
//
15
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
//  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
//  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
//  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
use std::convert::{TryFrom, TryInto};
24

25
use tari_node_components::blocks::Block;
26
use tari_transaction_components::rpc::models::FeePerGramStat;
27
use tari_utilities::ByteArray;
28

29
use crate::proto::base_node as proto;
30

31
impl TryFrom<Block> for proto::BlockBodyResponse {
32
    type Error = String;
33

UNCOV
34
    fn try_from(block: Block) -> Result<Self, Self::Error> {
×
UNCOV
35
        Ok(Self {
×
UNCOV
36
            hash: block.hash().to_vec(),
×
UNCOV
37
            body: Some(block.body.try_into()?),
×
38
        })
UNCOV
39
    }
×
40
}
41

42
impl From<Vec<FeePerGramStat>> for proto::GetMempoolFeePerGramStatsResponse {
43
    fn from(stats: Vec<FeePerGramStat>) -> Self {
×
44
        Self {
×
45
            stats: stats.into_iter().map(Into::into).collect(),
×
46
        }
×
47
    }
×
48
}
49

50
impl From<FeePerGramStat> for proto::MempoolFeePerGramStat {
51
    fn from(stat: FeePerGramStat) -> Self {
×
52
        Self {
×
53
            order: stat.order,
×
54
            min_fee_per_gram: stat.min_fee_per_gram.as_u64(),
×
55
            avg_fee_per_gram: stat.avg_fee_per_gram.as_u64(),
×
56
            max_fee_per_gram: stat.max_fee_per_gram.as_u64(),
×
57
        }
×
58
    }
×
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc