Fix incorrect waiting blocks applying.

This commit is contained in:
John Preston 2025-03-29 00:21:18 +05:00
parent a300a25419
commit 1d32e5267c

View file

@ -195,6 +195,7 @@ void Call::apply(int subchain, const Block &last) {
}); });
if (subchain) { if (subchain) {
auto &entry = _subchains[subchain];
auto result = tde2e_api::call_receive_inbound_message( auto result = tde2e_api::call_receive_inbound_message(
libId(), libId(),
Slice(last.data)); Slice(last.data));
@ -299,7 +300,7 @@ void Call::apply(
} else if (!_id || entry.height == index) { } else if (!_id || entry.height == index) {
apply(subchain, block); apply(subchain, block);
} }
entry.height = index + 1; entry.height = std::max(entry.height, index + 1);
checkWaitingBlocks(subchain); checkWaitingBlocks(subchain);
} }
@ -320,15 +321,15 @@ void Call::checkWaitingBlocks(int subchain, bool waited) {
auto &waiting = entry.waiting; auto &waiting = entry.waiting;
entry.shortPollTimer.cancel(); entry.shortPollTimer.cancel();
while (!waiting.empty()) { while (!waiting.empty()) {
const auto level = waiting.begin()->first; const auto index = waiting.begin()->first;
if (level > entry.height + 1) { if (index > entry.height) {
if (waited) { if (waited) {
shortPoll(subchain); shortPoll(subchain);
} else { } else {
entry.waitingTimer.callOnce(kShortPollChainBlocksWaitFor); entry.waitingTimer.callOnce(kShortPollChainBlocksWaitFor);
} }
return; return;
} else if (level == entry.height + 1) { } else if (index == entry.height) {
const auto slice = Slice(waiting.begin()->second.data); const auto slice = Slice(waiting.begin()->second.data);
if (subchain) { if (subchain) {
auto result = tde2e_api::call_receive_inbound_message( auto result = tde2e_api::call_receive_inbound_message(
@ -352,7 +353,7 @@ void Call::checkWaitingBlocks(int subchain, bool waited) {
} }
_participantsSet = ParseParticipantsSet(result.value()); _participantsSet = ParseParticipantsSet(result.value());
} }
entry.height = level; entry.height = std::max(entry.height, index + 1);
} }
waiting.erase(waiting.begin()); waiting.erase(waiting.begin());
} }