Skip to content

Commit

Permalink
Fix double event emission on contract tx simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Lessa committed Feb 24, 2024
1 parent 04bc422 commit ad7841f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/contract/contractmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,34 @@ bool ContractManager::validateCallContractWithTx(const ethCallInfo& callInfo) {
this->callLogger_->setContractVars(this, from, from, value);
this->ethCall(callInfo);
this->callLogger_.reset();
this->eventManager_.revertEvents();
return true;
}

if (to == ProtocolContractAddresses.at("rdPoS")) {
this->callLogger_->setContractVars(&rdpos_, from, from, value);
rdpos_.ethCall(callInfo);
this->callLogger_.reset();
this->eventManager_.revertEvents();
return true;
}

std::shared_lock<std::shared_mutex> lock(this->contractsMutex_);
if (!this->contracts_.contains(to)) {
this->callLogger_.reset();
this->eventManager_.revertEvents();
return false;
}
const auto &contract = contracts_.at(to);
this->callLogger_->setContractVars(contract.get(), from, from, value);
contract->ethCall(callInfo);
} catch (std::exception &e) {
this->callLogger_.reset();
this->eventManager_.revertEvents();
throw DynamicException(e.what());
}
this->callLogger_.reset();
this->eventManager_.revertEvents();
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/contract/contractmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ class ContractManagerInterface {
// inside contracts and are not emitted if a transaction reverts.
// C++ itself already takes care of events not being emitted on pure/view
// functions due to its built-in const-correctness logic.
// TODO: check later if events are really not emitted on transaction revert
if (!this->manager_.callLogger_) throw DynamicException(
"Contracts going haywire! Trying to emit an event without an active contract call"
);
Expand Down
2 changes: 1 addition & 1 deletion tests/sdktestsuite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class SDKTestSuite {
);
ret = tx.hash();
// Check if the execution is not going to be reverted/throw
this->state_.estimateGas(tx.txToCallInfo()); // TODO: this is emitting duplicate events, needs to be fixed
this->state_.estimateGas(tx.txToCallInfo());
this->advanceChain(timestamp, {tx});
return ret;
}
Expand Down

0 comments on commit ad7841f

Please sign in to comment.