Skip to content

Fix storing is_applied flag - #2487

Open
SpyCheese wants to merge 8 commits into
testnetfrom
apply-fix
Open

Fix storing is_applied flag#2487
SpyCheese wants to merge 8 commits into
testnetfrom
apply-fix

Conversation

@SpyCheese

Copy link
Copy Markdown
Member

No description provided.

}
if (!masterchain_handle_->inited_unix_time() || !masterchain_handle_->inited_is_key_block() ||
!masterchain_handle_->is_applied()) {
if (last_known_key_block_.is_valid() && masterchain_handle_->inited_unix_time() &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle the no-timestamp case using information that does not come from the corrupted handle.

This change makes recovery unreachable for a missing handle. The lookup uses get_block_handle(..., true), which substitutes an empty handle when the DB returns notready; that handle has neither inited_unix_time() nor inited_next_left(). The serializer therefore returns here without recovering, and the next top-block check can abort on CHECK(masterchain_handle_->inited_next_left()).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is intended for handles with missing applied flag, which is technically possible and was actually observed on some nodes. We don't expect corrupted handles with other missing flags.

auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), handle = handle_](td::Result<td::Unit> R) {
CHECK(handle->handle_moved_to_archive());
CHECK(handle->moved_to_archive())
handle->set_applied_stored();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check R first, explicitly flush/update dirty already-moved handles, and set applied_stored only after that write succeeds.

archive() does not guarantee that the changes made above were persisted. BlockArchiver::run_inner() returns success immediately when moved_to_archive() is already true, so set_applied() can merely dirty an existing archived handle while this line nevertheless marks it as stored. ApplyBlock can then take the new early-return path even though the archive still contains is_applied=false.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@SpyCheese
SpyCheese force-pushed the apply-fix branch 2 times, most recently from f38f11e to 4ef97a6 Compare July 29, 2026 06:38
Due to a bug, some historical blocks may miss is_applied flag. We check is_applied for blocks in litequeries to prevent accessing non-masterchain-finalized blocks via LS.
handle_moved_to_archive is also usable for this check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants