提交 f7c60216 编写于 作者: N Nathan Hourt

Improve error message

When rejecting a transaction due to excessive authorizations on a
message, include the authorizations which were not necessary in the
reported error
上级 35c4740f
......@@ -612,14 +612,16 @@ void chain_controller::validate_expiration(const SignedTransaction& trx) const
* The order of execution of precondition and apply can impact the validity of the
* entire message.
*/
void chain_controller::process_message( const ProcessedTransaction& trx, AccountName code, const Message& message, MessageOutput& output) {
void chain_controller::process_message(const ProcessedTransaction& trx, AccountName code,
const Message& message, MessageOutput& output) {
apply_context apply_ctx(*this, _db, trx, message, code);
apply_message(apply_ctx);
// process_message recurses for each notified account, but we only want to run this check at the top level
if (code == message.code && (_skip_flags & skip_authority_check) == false)
EOS_ASSERT(apply_ctx.all_authorizations_used(), tx_irrelevant_auth,
"Message declared an authority it did not need", ("message", message));
"Message declared authorities it did not need: ${unused}",
("unused", apply_ctx.unused_authorizations())("message", message));
output.notify.reserve( apply_ctx.notified.size() );
......
......@@ -136,6 +136,7 @@ public:
void require_recipient(const types::AccountName& account);
bool all_authorizations_used() const;
vector<types::AccountPermission> unused_authorizations() const;
const chain_controller& controller;
const chainbase::database& db; ///< database where state is stored
......
......@@ -6,6 +6,9 @@
#include <boost/algorithm/cxx11/all_of.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
namespace eos { namespace chain {
......@@ -44,6 +47,19 @@ bool apply_context::all_authorizations_used() const {
return boost::algorithm::all_of_equal(used_authorizations, true);
}
vector<types::AccountPermission> apply_context::unused_authorizations() const {
auto RemoveUsed = boost::adaptors::filtered([](const auto& tuple) {
return !boost::get<0>(tuple);
});
auto ToPermission = boost::adaptors::transformed([](const auto& tuple) {
return boost::get<1>(tuple);
});
// zip the parallel arrays, filter out the used authorizations, and return just the permissions that are left
auto range = boost::combine(used_authorizations, msg.authorization) | RemoveUsed | ToPermission;
return {range.begin(), range.end()};
}
//
// i64 functions
//
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册