Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions csnode/src/backwardsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ void BackwardSync::request(const Context& ctx) {
requestedAll_ = true; // the floor rose (pruning) past what is left to ask for
break;
}
if (next_ - nextToRequest_ >= window) {
// what is asked for and not stored yet, this batch included, fits in the buffer: a reply
// never meets a full buffer however slowly the blocks are stored
if (next_ - nextToRequest_ + settings_.batch > window) {
break;
}
const Sequence hi = nextToRequest_;
Expand Down Expand Up @@ -299,15 +301,16 @@ void BackwardSync::onBlocks(const PublicKey& sender, PoolsBlock&& blocks) {
}
Batch& batch = it->second;
const size_t limit = kBufferBatches * settings_.batch;
std::set<Sequence> noRoom; // sent, but not kept: asked for again, not held against the peer
for (auto& block : blocks) {
const Sequence seq = block.sequence();
if (!block.is_valid() || batch.missing.count(seq) == 0) {
++dropped_;
continue;
}
if (buffer_.size() >= limit && buffer_.count(seq) == 0) {
// left missing: asked for again when the batch times out
++dropped_;
noRoom.insert(seq);
if (!bufferFullLogged_) {
bufferFullLogged_ = true;
log("BACKFILL: " + std::to_string(buffer_.size()) + " blocks wait to be stored: the others of " + keyText(sender) +
Expand All @@ -318,6 +321,13 @@ void BackwardSync::onBlocks(const PublicKey& sender, PoolsBlock&& blocks) {
buffer_[seq] = Buffered{std::move(block), sender};
batch.missing.erase(seq);
}
if (!noRoom.empty()) {
for (const Sequence seq : noRoom) {
batch.missing.erase(seq);
}
auto& again = retry_[*noRoom.rbegin()];
again.insert(noRoom.begin(), noRoom.end());
}
if (batch.missing.empty()) {
inFlight_.erase(it);
auto& state = peers_[sender];
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ lines under the new release.
| #142 | node: a `NodeStopRequest` from the network no longer stops the node (its signature was not checked since upstream `af4de3f8`, so it was not authenticated); it is counted and logged; a node too old for the network still stops by the special order of the version change |
| #143 | node: a `Utility` message (ban or unban a node key) is obeyed only with the blockchain key's signature, an exact length and a round at most 100 rounds old (its signature was not checked since upstream `af4de3f8`, so it was not authenticated) |
| #144 | csnode: stream reads bounded by the data: `IDataStream` checks a length without overflow, a vector reserves no more than the bytes left and stops at the first missing element, a smart stage-one message whose fee count exceeds its size or that lacks its hash is refused, the API checks a string field's length before reading it |
| #145 | csnode: backward sync asks for no more blocks than its buffer holds (a request could overrun it by one batch); blocks a reply brings when the buffer is full are asked for again at once and no longer count against the peer that sent them (with slow stores, on mainnet after a restart, peers that had answered were left out for an hour and the backfill fell to ~30 blocks/s) |

## community.14 — 2026-10-27

Expand Down
18 changes: 18 additions & 0 deletions tests/csnode/backwardsync_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,24 @@ TEST_F(BackfillTest, TheWorkPerTurnIsBounded) {

// a slow store ends the turn once it has used its time, however many blocks it may still store;
// such a turn is logged with where its time went
// stores slower than the replies arrive: the requests never ask for more than the buffer holds,
// so no block is dropped and no peer that answered is taken for one that did not
TEST_F(BackfillTest, SlowStoresNeitherDropBlocksNorMarkPeers) {
auto settings = settingsOf(20, 0, 50);
settings.turnBudgetMs = 30;
make(settings);
storeDelayMs_ = 12; // three blocks a turn
for (int i = 0; i < 400 && !sync_->stats().done; ++i) {
tick(100);
answerAll();
}
EXPECT_TRUE(sync_->stats().done);
EXPECT_EQ(first_, 0u);
EXPECT_EQ(sync_->stats().dropped, 0u);
EXPECT_EQ(logged("are dropped"), 0u);
EXPECT_EQ(logged("did not answer"), 0u);
}

TEST_F(BackfillTest, ASlowTurnStopsAtItsTimeBudget) {
auto settings = settingsOf(100, 0, 50);
settings.turnBudgetMs = 30;
Expand Down
Loading