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
3 changes: 3 additions & 0 deletions solver/include/solver/smartcontracts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ public slots:
std::unordered_set<csdb::Address> blacklistedContracts_;

std::unordered_set<csdb::Address> locked_contracts;
// contracts whose state this node asked the confidants for, with the round of the last request;
// a StateReply for any other contract is not an answer to this node
std::unordered_map<csdb::Address, cs::RoundNumber> pending_state_requests;

//uint64_t testValue = 0;

Expand Down
19 changes: 19 additions & 0 deletions solver/src/smartcontracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,7 @@ bool SmartContracts::wait_until_executor(unsigned int test_freq, unsigned int ma
}

void SmartContracts::net_request_contract_state(const csdb::Address& abs_addr) {
pending_state_requests[abs_addr] = cs::Conveyer::instance().currentRoundNumber();
pnode->sendStateRequest(abs_addr, cs::Conveyer::instance().confidants());
}

Expand All @@ -3281,6 +3282,23 @@ void SmartContracts::net_update_contract_state(const csdb::Address& contract_abs
stream >> ref.sequence >> ref.transaction >> state;

if (stream.isValid() && !stream.isAvailable(1)) {
// several confidants answer one request, so the entry stays until it expires
constexpr cs::RoundNumber kStateRequestRounds = 1000;
const cs::RoundNumber round = cs::Conveyer::instance().currentRoundNumber();
const auto pending = pending_state_requests.find(contract_abs_addr);
if (pending == pending_state_requests.end() || pending->second + kStateRequestRounds < round) {
if (pending != pending_state_requests.end()) {
pending_state_requests.erase(pending);
}
cswarning() << kLogPrefix << "ignore " << cs::SmartContracts::to_base58(contract_abs_addr) << " state, it was not requested";
return;
}
// a state cannot refer to a block later than the current round, and caching one would make every
// real update look outdated
if (ref.sequence > round) {
cswarning() << kLogPrefix << "ignore " << cs::SmartContracts::to_base58(contract_abs_addr) << " state of future " << ref;
return;
}

if (in_known_contracts(contract_abs_addr)) {
auto& item = known_contracts[contract_abs_addr];
Expand Down Expand Up @@ -3482,6 +3500,7 @@ void SmartContracts::clear() {
exe_queue.clear();
blacklistedContracts_.clear();
locked_contracts.clear();
pending_state_requests.clear();
}


Expand Down
Loading