Skip to content

Commit

Permalink
optimize balance console output
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Jan 29, 2024
1 parent c7eb92d commit bcecdfe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
15 changes: 14 additions & 1 deletion bcos-executor/src/executive/BillingTransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ CallParameters::UniquePtr BillingTransactionExecutive::start(CallParameters::Uni
u256 gasPrice = input->gasPrice;
auto message = TransactionExecutive::execute(std::move(input));

if ((currentSeq == 0) && !staticCall)
if ((currentSeq == 0) && !staticCall &&
message->status == (int32_t)protocol::TransactionStatus::None)
{
CallParameters::UniquePtr callParam4AccountPre =
std::make_unique<CallParameters>(CallParameters::MESSAGE);
Expand All @@ -28,14 +29,26 @@ CallParameters::UniquePtr BillingTransactionExecutive::start(CallParameters::Uni
auto newParams = codec.encode(codeParameters, subBalanceIn);
callParam4AccountPre->data = std::move(newParams);

EXECUTIVE_LOG(TRACE) << LOG_BADGE("Billing") << "Try to subAccount balance: "
<< LOG_KV("subBalance", gasUsed * gasPrice)
<< LOG_KV("gasUsed", gasUsed) << LOG_KV("gasPrice", gasPrice)
<< LOG_KV("origin", currentSenderAddr);
auto subBalanceRet = callPrecompiled(std::move(callParam4AccountPre));
if (subBalanceRet->type == CallParameters::REVERT)
{
message->type = subBalanceRet->type;
message->status = subBalanceRet->status;
message->message = subBalanceRet->message;
EXECUTIVE_LOG(TRACE) << LOG_BADGE("Billing") << "SubAccount balance failed: "
<< LOG_KV("subBalance", gasUsed * gasPrice)
<< LOG_KV("gasUsed", gasUsed) << LOG_KV("gasPrice", gasPrice)
<< LOG_KV("status", message->status) << LOG_KV("message", message);
return message;
}
EXECUTIVE_LOG(TRACE) << LOG_BADGE("Billing") << "SubAccount balance success: "
<< LOG_KV("subBalance", gasUsed * gasPrice)
<< LOG_KV("gasUsed", gasUsed) << LOG_KV("gasPrice", gasPrice)
<< LOG_KV("status", message->status) << LOG_KV("message", message);
}

EXECUTIVE_LOG(TRACE) << "Execute billing executive finish\t" << message->toFullString();
Expand Down
14 changes: 14 additions & 0 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,20 @@ CallParameters::UniquePtr TransactionExecutive::callPrecompiled(
}
precompiledCallParams->takeDataToCallParameter(callParameters);
}
// NotEnoughCashError
catch (protocol::NotEnoughCashError const& e)
{
EXECUTIVE_LOG(INFO) << "Revert transaction: "
<< "NotEnoughCashError"
<< LOG_KV("address", precompiledCallParams->m_precompiledAddress)
<< LOG_KV("message", e.what());
writeErrInfoToOutput(e.what(), *callParameters);
revert();
callParameters->type = CallParameters::REVERT;
callParameters->status = (int32_t)TransactionStatus::NotEnoughCash;
callParameters->evmStatus = EVMC_REVERT;
callParameters->message = e.what();
}
catch (protocol::PrecompiledError const& e)
{
EXECUTIVE_LOG(INFO) << "Revert transaction: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
PRECOMPILED_LOG(WARNING) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("AccountPrecompiled, subAccountBalance")
<< LOG_DESC("table not exist!");
BOOST_THROW_EXCEPTION(PrecompiledError("Account table not exist, subBalance failed!"));
BOOST_THROW_EXCEPTION(NotEnoughCashError("Account table not exist, subBalance failed!"));
return;
}

Expand All @@ -389,7 +389,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
PRECOMPILED_LOG(DEBUG) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("AccountPrecompiled, subAccountBalance")
<< LOG_DESC("account balance not enough");
BOOST_THROW_EXCEPTION(PrecompiledError("Account balance is not enough!"));
BOOST_THROW_EXCEPTION(NotEnoughCashError("Account balance is not enough!"));
return;
}
else
Expand All @@ -408,7 +408,7 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
Entry Balance;
Balance.importFields({boost::lexical_cast<std::string>(0)});
_executive->storage().setRow(accountTableName, ACCOUNT_BALANCE, std::move(Balance));
BOOST_THROW_EXCEPTION(PrecompiledError("Account balance is not enough!"));
BOOST_THROW_EXCEPTION(NotEnoughCashError("Account balance is not enough!"));
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ void BalancePrecompiled::addBalance(
if (!entry.has_value() || entry->get() == "0")
{
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("the request's sender not caller, addBalance failed"));
protocol::PrecompiledError("Permission denied. Please use \"listBalanceGovernor\" to "
"check which account(or contract) can addBalance"));
return;
}
PRECOMPILED_LOG(DEBUG) << BLOCK_NUMBER(blockContext.number()) << LOG_BADGE("BalancePrecompiled")
Expand Down Expand Up @@ -257,7 +258,8 @@ void BalancePrecompiled::subBalance(
<< LOG_KV("caller", caller)
<< LOG_KV("callerTableNotExist", "true");
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("the request's sender not caller, subBalance failed"));
protocol::PrecompiledError("Permission denied. Please use \"listBalanceGovernor\" to "
"check which account(or contract) can addBalance"));
return;
}
auto entry = table->getRow(caller);
Expand Down
8 changes: 8 additions & 0 deletions bcos-framework/bcos-framework/protocol/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@ class PrecompiledError : public Exception
PrecompiledError() : Exception() {}
PrecompiledError(std::string const& _msg) : Exception(_msg) {}
};

class NotEnoughCashError : public Exception
{
public:
NotEnoughCashError() : Exception() {}
NotEnoughCashError(std::string const& _msg) : Exception(_msg) {}
};

} // namespace protocol
} // namespace bcos

0 comments on commit bcecdfe

Please sign in to comment.