mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Check is_applied in liteserver
This commit is contained in:
parent
9465fd866a
commit
be824e9649
2 changed files with 149 additions and 79 deletions
|
@ -269,8 +269,13 @@ void LiteQuery::perform_getBlock(BlockIdExt blkid) {
|
||||||
fatal_error("invalid BlockIdExt");
|
fatal_error("invalid BlockIdExt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_data_from_db_short, blkid,
|
get_block_handle_checked(blkid, [manager = manager_, Self = actor_id(this), blkid](td::Result<ConstBlockHandle> R) {
|
||||||
[Self = actor_id(this), blkid](td::Result<Ref<ton::validator::BlockData>> res) {
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||||
|
[=](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,6 +283,7 @@ void LiteQuery::perform_getBlock(BlockIdExt blkid) {
|
||||||
res.move_as_ok());
|
res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiteQuery::continue_getBlock(BlockIdExt blkid, Ref<ton::validator::BlockData> block) {
|
void LiteQuery::continue_getBlock(BlockIdExt blkid, Ref<ton::validator::BlockData> block) {
|
||||||
|
@ -295,8 +301,13 @@ void LiteQuery::perform_getBlockHeader(BlockIdExt blkid, int mode) {
|
||||||
fatal_error("invalid BlockIdExt");
|
fatal_error("invalid BlockIdExt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_data_from_db_short, blkid,
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
[Self = actor_id(this), blkid, mode](td::Result<Ref<ton::validator::BlockData>> res) {
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||||
|
[=](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||||
} else {
|
} else {
|
||||||
|
@ -304,6 +315,7 @@ void LiteQuery::perform_getBlockHeader(BlockIdExt blkid, int mode) {
|
||||||
mode, res.move_as_ok());
|
mode, res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool visit(Ref<vm::Cell> cell);
|
static bool visit(Ref<vm::Cell> cell);
|
||||||
|
@ -409,9 +421,14 @@ void LiteQuery::perform_getState(BlockIdExt blkid) {
|
||||||
fatal_error("cannot request total state: possibly too large");
|
fatal_error("cannot request total state: possibly too large");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (blkid.id.seqno) {
|
if (blkid.id.seqno) {
|
||||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_shard_state_from_db_short, blkid,
|
td::actor::send_closure_later(manager, &ValidatorManager::get_shard_state_from_db, R.move_as_ok(),
|
||||||
[Self = actor_id(this), blkid](td::Result<Ref<ton::validator::ShardState>> res) {
|
[=](td::Result<Ref<ton::validator::ShardState>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||||
} else {
|
} else {
|
||||||
|
@ -420,8 +437,8 @@ void LiteQuery::perform_getState(BlockIdExt blkid) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_zero_state, blkid,
|
td::actor::send_closure_later(manager, &ValidatorManager::get_zero_state, blkid,
|
||||||
[Self = actor_id(this), blkid](td::Result<td::BufferSlice> res) {
|
[=](td::Result<td::BufferSlice> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||||
} else {
|
} else {
|
||||||
|
@ -430,6 +447,7 @@ void LiteQuery::perform_getState(BlockIdExt blkid) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiteQuery::continue_getState(BlockIdExt blkid, Ref<ton::validator::ShardState> state) {
|
void LiteQuery::continue_getState(BlockIdExt blkid, Ref<ton::validator::ShardState> state) {
|
||||||
|
@ -481,6 +499,23 @@ void LiteQuery::perform_sendMessage(td::BufferSlice data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LiteQuery::get_block_handle_checked(BlockIdExt blkid, td::Promise<ConstBlockHandle> promise) {
|
||||||
|
auto P = td::PromiseCreator::lambda(
|
||||||
|
[promise = std::move(promise)](td::Result<BlockHandle> R) mutable {
|
||||||
|
if (R.is_error()) {
|
||||||
|
promise.set_error(R.move_as_error());
|
||||||
|
} else {
|
||||||
|
auto handle = R.move_as_ok();
|
||||||
|
if (handle->is_applied()) {
|
||||||
|
promise.set_result(std::move(handle));
|
||||||
|
} else {
|
||||||
|
promise.set_error(td::Status::Error("block is not applied"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
td::actor::send_closure(manager_, &ValidatorManager::get_block_handle, blkid, false, std::move(P));
|
||||||
|
}
|
||||||
|
|
||||||
bool LiteQuery::request_mc_block_data(BlockIdExt blkid) {
|
bool LiteQuery::request_mc_block_data(BlockIdExt blkid) {
|
||||||
if (!blkid.is_masterchain() || !blkid.is_valid_full()) {
|
if (!blkid.is_masterchain() || !blkid.is_valid_full()) {
|
||||||
return fatal_error("reference block must belong to the masterchain");
|
return fatal_error("reference block must belong to the masterchain");
|
||||||
|
@ -579,9 +614,14 @@ bool LiteQuery::request_block_state(BlockIdExt blkid) {
|
||||||
}
|
}
|
||||||
blk_id_ = blkid;
|
blk_id_ = blkid;
|
||||||
++pending_;
|
++pending_;
|
||||||
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
td::actor::send_closure_later(
|
td::actor::send_closure_later(
|
||||||
manager_, &ValidatorManager::get_shard_state_from_db_short, blkid,
|
manager, &ValidatorManager::get_shard_state_from_db, R.move_as_ok(),
|
||||||
[Self = actor_id(this), blkid](td::Result<Ref<ShardState>> res) {
|
[=](td::Result<Ref<ShardState>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||||
res.move_as_error_prefix("cannot load state for "s + blkid.to_str() + " : "));
|
res.move_as_error_prefix("cannot load state for "s + blkid.to_str() + " : "));
|
||||||
|
@ -589,6 +629,7 @@ bool LiteQuery::request_block_state(BlockIdExt blkid) {
|
||||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_state, blkid, res.move_as_ok());
|
td::actor::send_closure_later(Self, &LiteQuery::got_block_state, blkid, res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,9 +642,14 @@ bool LiteQuery::request_block_data(BlockIdExt blkid) {
|
||||||
}
|
}
|
||||||
blk_id_ = blkid;
|
blk_id_ = blkid;
|
||||||
++pending_;
|
++pending_;
|
||||||
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
td::actor::send_closure_later(
|
td::actor::send_closure_later(
|
||||||
manager_, &ValidatorManager::get_block_data_from_db_short, blkid,
|
manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||||
[Self = actor_id(this), blkid](td::Result<Ref<BlockData>> res) {
|
[=](td::Result<Ref<BlockData>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||||
res.move_as_error_prefix("cannot load block "s + blkid.to_str() + " : "));
|
res.move_as_error_prefix("cannot load block "s + blkid.to_str() + " : "));
|
||||||
|
@ -611,6 +657,7 @@ bool LiteQuery::request_block_data(BlockIdExt blkid) {
|
||||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_data, blkid, res.move_as_ok());
|
td::actor::send_closure_later(Self, &LiteQuery::got_block_data, blkid, res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,16 +693,23 @@ bool LiteQuery::request_proof_link(BlockIdExt blkid) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
td::actor::send_closure_later(
|
td::actor::send_closure_later(
|
||||||
manager_, &ValidatorManager::get_block_proof_link_from_db_short, blkid,
|
manager, &ValidatorManager::get_block_proof_link_from_db, R.move_as_ok(),
|
||||||
[Self = actor_id(this), blkid](td::Result<Ref<ProofLink>> res) {
|
[=](td::Result<Ref<ProofLink>> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
td::actor::send_closure(
|
||||||
|
Self, &LiteQuery::abort_query,
|
||||||
res.move_as_error_prefix("cannot load proof link for "s + blkid.to_str() + " : "));
|
res.move_as_error_prefix("cannot load proof link for "s + blkid.to_str() + " : "));
|
||||||
} else {
|
} else {
|
||||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_proof_link, blkid, res.move_as_ok());
|
td::actor::send_closure_later(Self, &LiteQuery::got_block_proof_link, blkid, res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -672,9 +726,14 @@ bool LiteQuery::request_zero_state(BlockIdExt blkid) {
|
||||||
}
|
}
|
||||||
blk_id_ = blkid;
|
blk_id_ = blkid;
|
||||||
++pending_;
|
++pending_;
|
||||||
|
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
td::actor::send_closure_later(
|
td::actor::send_closure_later(
|
||||||
manager_, &ValidatorManager::get_zero_state, blkid,
|
manager, &ValidatorManager::get_zero_state, blkid,
|
||||||
[Self = actor_id(this), blkid](td::Result<td::BufferSlice> res) {
|
[=](td::Result<td::BufferSlice> res) {
|
||||||
if (res.is_error()) {
|
if (res.is_error()) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||||
res.move_as_error_prefix("cannot load zerostate of "s + blkid.to_str() + " : "));
|
res.move_as_error_prefix("cannot load zerostate of "s + blkid.to_str() + " : "));
|
||||||
|
@ -682,6 +741,7 @@ bool LiteQuery::request_zero_state(BlockIdExt blkid) {
|
||||||
td::actor::send_closure_later(Self, &LiteQuery::got_zero_state, blkid, res.move_as_ok());
|
td::actor::send_closure_later(Self, &LiteQuery::got_zero_state, blkid, res.move_as_ok());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1397,6 +1457,11 @@ void LiteQuery::continue_getTransactions(unsigned remaining, bool exact) {
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_getTransactions, res.move_as_error(), ton::BlockIdExt{});
|
td::actor::send_closure(Self, &LiteQuery::abort_getTransactions, res.move_as_error(), ton::BlockIdExt{});
|
||||||
} else {
|
} else {
|
||||||
auto handle = res.move_as_ok();
|
auto handle = res.move_as_ok();
|
||||||
|
if (!handle->is_applied()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_getTransactions, td::Status::Error("block is not applied"),
|
||||||
|
ton::BlockIdExt{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
LOG(DEBUG) << "requesting data for block " << handle->id().to_str();
|
LOG(DEBUG) << "requesting data for block " << handle->id().to_str();
|
||||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, handle,
|
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, handle,
|
||||||
[Self, blkid = handle->id(), remaining](td::Result<Ref<BlockData>> res) {
|
[Self, blkid = handle->id(), remaining](td::Result<Ref<BlockData>> res) {
|
||||||
|
@ -1722,6 +1787,10 @@ void LiteQuery::perform_lookupBlock(BlockId blkid, int mode, LogicalTime lt, Uni
|
||||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||||
} else {
|
} else {
|
||||||
auto handle = res.move_as_ok();
|
auto handle = res.move_as_ok();
|
||||||
|
if (!handle->is_applied()) {
|
||||||
|
td::actor::send_closure(Self, &LiteQuery::abort_query, td::Status::Error("block is not applied"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
LOG(DEBUG) << "requesting data for block " << handle->id().to_str();
|
LOG(DEBUG) << "requesting data for block " << handle->id().to_str();
|
||||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, handle,
|
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, handle,
|
||||||
[Self, blkid = handle->id(), mode](td::Result<Ref<BlockData>> res) {
|
[Self, blkid = handle->id(), mode](td::Result<Ref<BlockData>> res) {
|
||||||
|
|
|
@ -152,6 +152,7 @@ class LiteQuery : public td::actor::Actor {
|
||||||
void finish_loadPrevKeyBlock(ton::BlockIdExt blkid, td::Result<Ref<BlockData>> res,
|
void finish_loadPrevKeyBlock(ton::BlockIdExt blkid, td::Result<Ref<BlockData>> res,
|
||||||
td::Promise<std::pair<BlockIdExt, Ref<BlockQ>>> promise);
|
td::Promise<std::pair<BlockIdExt, Ref<BlockQ>>> promise);
|
||||||
|
|
||||||
|
void get_block_handle_checked(BlockIdExt blkid, td::Promise<ConstBlockHandle> promise);
|
||||||
bool request_block_data(BlockIdExt blkid);
|
bool request_block_data(BlockIdExt blkid);
|
||||||
bool request_block_state(BlockIdExt blkid);
|
bool request_block_state(BlockIdExt blkid);
|
||||||
bool request_block_data_state(BlockIdExt blkid);
|
bool request_block_data_state(BlockIdExt blkid);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue