提交 9bca2de9 编写于 作者: A arhag

reorganize exceptions and progress towards better handling of soft fails

上级 fd76f372
......@@ -144,7 +144,7 @@ void apply_context::require_authorization( const account_name& account ) {
return;
}
}
EOS_ASSERT( false, tx_missing_auth, "missing authority of ${account}", ("account",account));
EOS_ASSERT( false, missing_auth_exception, "missing authority of ${account}", ("account",account));
}
bool apply_context::has_authorization( const account_name& account )const {
......@@ -163,7 +163,7 @@ void apply_context::require_authorization(const account_name& account,
return;
}
}
EOS_ASSERT( false, tx_missing_auth, "missing authority of ${account}/${permission}",
EOS_ASSERT( false, missing_auth_exception, "missing authority of ${account}/${permission}",
("account",account)("permission",permission) );
}
......
......@@ -137,10 +137,10 @@ namespace eosio { namespace chain {
const vector<permission_level>& auths
)const
{
EOS_ASSERT( auths.size() == 1, tx_irrelevant_auth,
EOS_ASSERT( auths.size() == 1, irrelevant_auth_exception,
"updateauth action should only have one declared authorization" );
const auto& auth = auths[0];
EOS_ASSERT( auth.actor == update.account, tx_irrelevant_auth,
EOS_ASSERT( auth.actor == update.account, irrelevant_auth_exception,
"the owner of the affected permission needs to be the actor of the declared authorization" );
const auto* min_permission = find_permission({update.account, update.permission});
......@@ -153,7 +153,7 @@ namespace eosio { namespace chain {
const auto delay = get_permission(auth).satisfies( *min_permission,
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"updateauth action declares irrelevant authority '${auth}'; minimum authority is ${min}",
("auth", auth)("min", permission_level{update.account, min_permission->name}) );
......@@ -164,17 +164,17 @@ namespace eosio { namespace chain {
const vector<permission_level>& auths
)const
{
EOS_ASSERT( auths.size() == 1, tx_irrelevant_auth,
EOS_ASSERT( auths.size() == 1, irrelevant_auth_exception,
"deleteauth action should only have one declared authorization" );
const auto& auth = auths[0];
EOS_ASSERT( auth.actor == del.account, tx_irrelevant_auth,
EOS_ASSERT( auth.actor == del.account, irrelevant_auth_exception,
"the owner of the permission to delete needs to be the actor of the declared authorization" );
const auto& min_permission = get_permission({del.account, del.permission});
const auto delay = get_permission(auth).satisfies( min_permission,
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"updateauth action declares irrelevant authority '${auth}'; minimum authority is ${min}",
("auth", auth)("min", permission_level{min_permission.owner, min_permission.name}) );
......@@ -185,10 +185,10 @@ namespace eosio { namespace chain {
const vector<permission_level>& auths
)const
{
EOS_ASSERT( auths.size() == 1, tx_irrelevant_auth,
EOS_ASSERT( auths.size() == 1, irrelevant_auth_exception,
"link action should only have one declared authorization" );
const auto& auth = auths[0];
EOS_ASSERT( auth.actor == link.account, tx_irrelevant_auth,
EOS_ASSERT( auth.actor == link.account, irrelevant_auth_exception,
"the owner of the linked permission needs to be the actor of the declared authorization" );
EOS_ASSERT( link.type != updateauth::get_name(), action_validate_exception,
......@@ -211,7 +211,7 @@ namespace eosio { namespace chain {
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"link action declares irrelevant authority '${auth}'; minimum authority is ${min}",
("auth", auth)("min", permission_level{link.account, *linked_permission_name}) );
......@@ -222,10 +222,10 @@ namespace eosio { namespace chain {
const vector<permission_level>& auths
)const
{
EOS_ASSERT( auths.size() == 1, tx_irrelevant_auth,
EOS_ASSERT( auths.size() == 1, irrelevant_auth_exception,
"unlink action should only have one declared authorization" );
const auto& auth = auths[0];
EOS_ASSERT( auth.actor == unlink.account, tx_irrelevant_auth,
EOS_ASSERT( auth.actor == unlink.account, irrelevant_auth_exception,
"the owner of the linked permission needs to be the actor of the declared authorization" );
const auto unlinked_permission_name = lookup_linked_permission(unlink.account, unlink.code, unlink.type);
......@@ -240,7 +240,7 @@ namespace eosio { namespace chain {
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"unlink action declares irrelevant authority '${auth}'; minimum authority is ${min}",
("auth", auth)("min", permission_level{unlink.account, *unlinked_permission_name}) );
......@@ -251,14 +251,14 @@ namespace eosio { namespace chain {
const vector<permission_level>& auths
)const
{
EOS_ASSERT( auths.size() == 1, tx_irrelevant_auth,
EOS_ASSERT( auths.size() == 1, irrelevant_auth_exception,
"canceldelay action should only have one declared authorization" );
const auto& auth = auths[0];
const auto delay = get_permission(auth).satisfies( get_permission(cancel.canceling_auth),
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"canceldelay action declares irrelevant authority '${auth}'; specified authority to satisfy is ${min}",
("auth", auth)("min", cancel.canceling_auth) );
}
......@@ -372,7 +372,7 @@ namespace eosio { namespace chain {
auto delay = get_permission(declared_auth).satisfies( min_permission,
_db.get_index<permission_index>().indices() );
EOS_ASSERT( delay.valid(),
tx_irrelevant_auth,
irrelevant_auth_exception,
"action declares irrelevant authority '${auth}'; minimum authority is ${min}",
("auth", declared_auth)("min", permission_level{min_permission.owner, min_permission.name}) );
max_delay = std::max( max_delay, *delay );
......
#include <eosio/chain/controller.hpp>
#include <eosio/chain/block_context.hpp>
#include <eosio/chain/transaction_context.hpp>
#include <eosio/chain/block_log.hpp>
......@@ -35,6 +36,7 @@ struct pending_state {
vector<action_receipt> _actions;
block_context _block_ctx;
void push() {
_db_session.push();
......
......@@ -491,7 +491,7 @@ class apply_context {
* This method will check that @ref account is listed in the message's declared authorizations, and marks the
* authorization as used. Note that all authorizations on a message must be used, or the message is invalid.
*
* @throws tx_missing_auth If no sufficient permission was found
* @throws missing_auth_exception If no sufficient permission was found
*/
void require_authorization(const account_name& account);
bool has_authorization(const account_name& account) const;
......
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
namespace eosio { namespace chain {
class block_context {
public:
enum block_status {
dpos_irreversible = 0, ///< this block has already been applied before by this node and is considered irreversible by DPOS standards
bft_irreversible = 1, ///< this block has already been applied before by this node and is considered irreversible by BFT standards (but not yet DPOS standards)
validated_block = 2, ///< this is a complete block signed by a valid producer and has been previously applied by this node and therefore validated but it is not yet irreversible
completed_block = 3, ///< this is a complete block signed by a valid producer but is not yet irreversible nor has it yet been applied by this node
producing_block = 4, ///< this is an incomplete block that is being produced by a valid producer for their time slot and will be signed by them after the block is completed
speculative_block = 5 ///< this is an incomplete block that is only being speculatively produced by the node (whether it is the node of an active producer or not)
};
block_status status = speculative_block;
bool is_active_producer = false; ///< whether the node applying the block is an active producer (this further modulates behavior when the block status is completed_block)
};
} }
......@@ -50,6 +50,8 @@ namespace eosio { namespace chain { namespace resource_limits {
void add( uint64_t units, uint32_t ordinal, uint32_t window_size /* must be positive */ )
{
if( last_ordinal != ordinal ) {
if( ordinal <= last_ordinal )
wdump((ordinal)(last_ordinal));
FC_ASSERT( ordinal > last_ordinal, "new ordinal cannot be less than the previous ordinal" );
if( (uint64_t)last_ordinal + window_size > (uint64_t)ordinal ) {
const auto delta = ordinal - last_ordinal; // clearly 0 < delta < window_size
......
......@@ -86,6 +86,8 @@ namespace eosio { namespace chain {
uint64_t& net_usage; /// reference to trace->net_usage
uint64_t& cpu_usage; /// reference to trace->cpu_usage
bool net_limit_due_to_block = false;
bool cpu_limit_due_to_block = false;
};
......
......@@ -97,7 +97,7 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
uint128_t capacity_cpu_ex = state.virtual_cpu_limit * config::rate_limiting_precision;
EOS_ASSERT( state.total_cpu_weight > 0 && (consumed_cpu_ex * state.total_cpu_weight) <= (limits.cpu_weight * capacity_cpu_ex),
tx_resource_exhausted,
tx_cpu_resource_exhausted,
"authorizing account '${n}' has insufficient cpu resources for this transaction",
("n", name(a))
("consumed", (double)consumed_cpu_ex/(double)config::rate_limiting_precision)
......@@ -112,7 +112,7 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
uint128_t capacity_net_ex = state.virtual_net_limit * config::rate_limiting_precision;
EOS_ASSERT( state.total_net_weight > 0 && (consumed_net_ex * state.total_net_weight) <= (limits.net_weight * capacity_net_ex),
tx_resource_exhausted,
tx_net_resource_exhausted,
"authorizing account '${n}' has insufficient net resources for this transaction",
("n", name(a))
("consumed", (double)consumed_net_ex/(double)config::rate_limiting_precision)
......@@ -156,7 +156,7 @@ void resource_limits_manager::verify_account_ram_usage( const account_name accou
const auto& usage = _db.get<resource_usage_object,by_owner>( account );
if( ram_bytes >= 0 && usage.ram_usage > ram_bytes ) {
tx_resource_exhausted e(FC_LOG_MESSAGE(error, "account ${a} has insufficient ram bytes", ("a", account)));
ram_usage_exceeded e(FC_LOG_MESSAGE(error, "account ${a} has insufficient ram bytes", ("a", account)));
e.append_log(FC_LOG_MESSAGE(error, "needs ${d} has ${m}", ("d",usage.ram_usage)("m",ram_bytes)));
throw e;
}
......
......@@ -71,8 +71,6 @@ namespace eosio { namespace chain {
rl.add_transaction_usage( bill_to_accounts, 0, 0, block_timestamp_type(control.pending_block_time()).slot );
// Lower limits to what the billed accounts can afford to pay
max_net = std::min( max_net, rl.get_block_net_limit() );
max_cpu = std::min( max_cpu, rl.get_block_cpu_limit() );
for( const auto& a : bill_to_accounts ) {
auto net_limit = rl.get_account_net_limit(a);
if( net_limit >= 0 )
......@@ -82,11 +80,20 @@ namespace eosio { namespace chain {
max_cpu = std::min( max_cpu, static_cast<uint64_t>(cpu_limit) ); // reduce max_cpu to the amount the account is able to pay
}
if( rl.get_block_net_limit() < max_net ) {
max_net = rl.get_block_net_limit();
net_limit_due_to_block = true;
}
if( rl.get_block_cpu_limit() < max_cpu ) {
max_cpu = rl.get_block_cpu_limit();
cpu_limit_due_to_block = true;
}
// Round down network and CPU usage limits so that comparison to actual usage is more efficient
max_net = (max_net/8)*8; // Round down to nearest multiple of word size (8 bytes)
max_cpu = (max_cpu/1024)*1024; // Round down to nearest multiple of 1024
if( initial_net_usage > 0 )
check_net_usage();
check_net_usage(); // Fail early if current net usage is already greater than the calculated limit
check_cpu_usage(); // Fail early if current CPU usage is already greater than the calculated limit
}
......@@ -175,13 +182,13 @@ namespace eosio { namespace chain {
}
void transaction_context::check_net_usage()const {
EOS_ASSERT( BOOST_LIKELY(net_usage <= max_net), tx_resource_exhausted,
EOS_ASSERT( BOOST_LIKELY(net_usage <= max_net), tx_net_resource_exhausted,
"net usage of transaction is too high: ${actual_net_usage} > ${net_usage_limit}",
("actual_net_usage", net_usage)("net_usage_limit", max_net) );
}
void transaction_context::check_cpu_usage()const {
EOS_ASSERT( BOOST_LIKELY(cpu_usage <= max_cpu), tx_resource_exhausted,
EOS_ASSERT( BOOST_LIKELY(cpu_usage <= max_cpu), tx_cpu_resource_exhausted,
"cpu usage of transaction is too high: ${actual_net_usage} > ${cpu_usage_limit}",
("actual_net_usage", cpu_usage)("cpu_usage_limit", max_cpu) );
}
......@@ -245,7 +252,7 @@ namespace eosio { namespace chain {
transaction.expiration = expire;
});
} catch ( ... ) {
EOS_ASSERT( false, transaction_exception,
EOS_ASSERT( false, tx_duplicate,
"duplicate transaction ${id}", ("id", id ) );
}
} /// record_transaction
......
......@@ -57,40 +57,6 @@
std::current_exception() ); \
}
#define EOS_DECLARE_OP_BASE_EXCEPTIONS( op_name ) \
FC_DECLARE_DERIVED_EXCEPTION( \
op_name ## _validate_exception, \
eosio::chain::message_validate_exception, \
3040000 + 100 * operation::tag< op_name ## _operation >::value, \
#op_name "_operation validation exception" \
) \
FC_DECLARE_DERIVED_EXCEPTION( \
op_name ## _evaluate_exception, \
eosio::chain::message_evaluate_exception, \
3050000 + 100 * operation::tag< op_name ## _operation >::value, \
#op_name "_operation evaluation exception" \
)
#define EOS_DECLARE_OP_VALIDATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \
FC_DECLARE_DERIVED_EXCEPTION( \
op_name ## _ ## exc_name, \
eosio::chain::op_name ## _validate_exception, \
3040000 + 100 * operation::tag< op_name ## _operation >::value \
+ seqnum, \
msg \
)
#define EOS_DECLARE_OP_EVALUATE_EXCEPTION( exc_name, op_name, seqnum, msg ) \
FC_DECLARE_DERIVED_EXCEPTION( \
op_name ## _ ## exc_name, \
eosio::chain::op_name ## _evaluate_exception, \
3050000 + 100 * operation::tag< op_name ## _operation >::value \
+ seqnum, \
msg \
)
#define EOS_RECODE_EXC( cause_type, effect_type ) \
catch( const cause_type& e ) \
{ throw( effect_type( e.what(), e.get_log() ) ); }
......@@ -1654,7 +1654,7 @@ int main( int argc, char** argv ) {
if (!proposer.empty()) {
accountPermissions = vector<permission_level>{{proposer, config::active_name}};
} else {
EOS_THROW(tx_missing_auth, "Authority is not provided (either by multisig parameter <proposer> or -p)");
EOS_THROW(missing_auth_exception, "Authority is not provided (either by multisig parameter <proposer> or -p)");
}
}
if (proposer.empty()) {
......@@ -1787,7 +1787,7 @@ int main( int argc, char** argv ) {
if (!canceler.empty()) {
accountPermissions = vector<permission_level>{{canceler, config::active_name}};
} else {
EOS_THROW(tx_missing_auth, "Authority is not provided (either by multisig parameter <canceler> or -p)");
EOS_THROW(missing_auth_exception, "Authority is not provided (either by multisig parameter <canceler> or -p)");
}
}
if (canceler.empty()) {
......@@ -1819,7 +1819,7 @@ int main( int argc, char** argv ) {
if (!executer.empty()) {
accountPermissions = vector<permission_level>{{executer, config::active_name}};
} else {
EOS_THROW(tx_missing_auth, "Authority is not provided (either by multisig parameter <executer> or -p)");
EOS_THROW(missing_auth_exception, "Authority is not provided (either by multisig parameter <executer> or -p)");
}
}
if (executer.empty()) {
......
......@@ -201,11 +201,10 @@ bool is_access_violation(const Runtime::Exception& e) {
}
bool is_assert_exception(fc::assert_exception const & e) { return true; }
bool is_page_memory_error(page_memory_error const &e) { return true; }
bool is_tx_missing_auth(tx_missing_auth const & e) { return true; }
bool is_tx_missing_recipient(tx_missing_recipient const & e) { return true;}
bool is_tx_missing_sigs(tx_missing_sigs const & e) { return true;}
bool is_wasm_execution_error(eosio::chain::wasm_execution_error const& e) {return true;}
bool is_tx_resource_exhausted(const tx_resource_exhausted& e) { return true; }
bool is_tx_net_resource_exhausted(const tx_net_resource_exhausted& e) { return true; }
bool is_tx_cpu_resource_exhausted(const tx_cpu_resource_exhausted& e) { return true; }
bool is_checktime_exceeded(const checktime_exceeded& e) { return true; }
/*
......@@ -307,24 +306,24 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try {
);
// test require_auth
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", {}), tx_missing_auth,
[](const tx_missing_auth& e) {
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", {}), missing_auth_exception,
[](const missing_auth_exception& e) {
return expect_assert_message(e, "missing authority of");
}
);
// test require_auth
auto a3only = std::vector<permission_level>{{N(acc3), config::active_name}};
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", fc::raw::pack(a3only)), tx_missing_auth,
[](const tx_missing_auth& e) {
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", fc::raw::pack(a3only)), missing_auth_exception,
[](const missing_auth_exception& e) {
return expect_assert_message(e, "missing authority of");
}
);
// test require_auth
auto a4only = std::vector<permission_level>{{N(acc4), config::active_name}};
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", fc::raw::pack(a4only)), tx_missing_auth,
[](const tx_missing_auth& e) {
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "require_auth", fc::raw::pack(a4only)), missing_auth_exception,
[](const missing_auth_exception& e) {
return expect_assert_message(e, "missing authority of");
}
);
......@@ -500,7 +499,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try {
return expect_assert_message(e, "context free actions cannot have authorizations");
}
);
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW() }
......@@ -568,7 +567,7 @@ BOOST_AUTO_TEST_CASE(checktime_fail_tests) { try {
test.produce_block();
};
BOOST_CHECK_EXCEPTION(call_test( t, test_api_action<TEST_METHOD("test_checktime", "checktime_failure")>{}), tx_resource_exhausted, is_tx_resource_exhausted /*checktime_exceeded, is_checktime_exceeded*/);
BOOST_CHECK_EXCEPTION(call_test( t, test_api_action<TEST_METHOD("test_checktime", "checktime_failure")>{}), tx_cpu_resource_exhausted, is_tx_cpu_resource_exhausted /*checktime_exceeded, is_checktime_exceeded*/);
BOOST_REQUIRE_EQUAL( t.validate(), true );
} FC_LOG_AND_RETHROW() }
......@@ -641,7 +640,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, TESTER) { try {
produce_blocks(100);
set_code( N(testapi), test_api_wast );
produce_blocks(1);
// test for zero auth
{
signed_transaction trx;
......@@ -751,11 +750,11 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
control->push_next_scheduled_transaction();
BOOST_CHECK(!trace);
produce_block( fc::seconds(2) );
//check that it gets executed afterwards
control->push_next_scheduled_transaction();
BOOST_CHECK(trace);
//confirm printed message
BOOST_TEST(!trace->action_traces.empty());
BOOST_TEST(trace->action_traces.back().console == "deferred executed\n");
......@@ -770,7 +769,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
CALL_TEST_FUNCTION(*this, "test_transaction", "send_deferred_transaction", {});
CALL_TEST_FUNCTION(*this, "test_transaction", "send_deferred_transaction", {});
produce_block( fc::seconds(2) );
//check that only one deferred transaction executed
control->push_next_scheduled_transaction();
BOOST_CHECK(trace);
......@@ -806,7 +805,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
// Send deferred transaction with payer != receiver, payer is alice in this case, this should fail since we don't have authorization of alice
BOOST_CHECK_THROW(CALL_TEST_FUNCTION(*this, "test_transaction", "send_deferred_tx_given_payer", fc::raw::pack(account_name("alice"))), transaction_exception);
// If we make testapi to be priviledge account, deferred transaction will work no matter who is the payer
push_action(config::system_account_name, N(setpriv), config::system_account_name, mutable_variant_object()
("account", "testapi")
......
......@@ -1227,9 +1227,8 @@ BOOST_AUTO_TEST_CASE(account_ram_limit) { try {
BOOST_REQUIRE_EXCEPTION(
chain.create_account(N(acc4), acc1),
tx_resource_exhausted,
[] (const tx_resource_exhausted &e)->bool {
BOOST_REQUIRE_EQUAL(std::string("transaction exhausted allowed resources"), e.what());
ram_usage_exceeded,
[] (const ram_usage_exceeded &e)->bool {
return true;
}
);
......
......@@ -53,7 +53,7 @@ BOOST_FIXTURE_TEST_CASE( missing_auths, TESTER ) { try {
produce_block();
/// action not provided from authority
BOOST_REQUIRE_THROW( push_reqauth( N(alice), {permission_level{N(bob), config::active_name}}, { get_private_key(N(bob), "active") } ), tx_missing_auth);
BOOST_REQUIRE_THROW( push_reqauth( N(alice), {permission_level{N(bob), config::active_name}}, { get_private_key(N(bob), "active") } ), missing_auth_exception);
} FC_LOG_AND_RETHROW() } /// transfer_test
......@@ -156,7 +156,7 @@ try {
// Bob attempts to create new spending auth for Alice
BOOST_CHECK_THROW( chain.set_authority( "alice", "spending", authority(spending_pub_key), "active",
{ permission_level{"bob", "active"} }, { chain.get_private_key("bob", "active") } ),
transaction_exception );
irrelevant_auth_exception );
// Create new spending auth
chain.set_authority("alice", "spending", authority(spending_pub_key), "active",
......@@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(link_auths) { try {
chain.set_authority("alice", "scud", scud_pub_key, "spending");
// Send req auth action with alice's spending key, it should fail
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "spending"} }, { spending_priv_key }), tx_irrelevant_auth);
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "spending"} }, { spending_priv_key }), irrelevant_auth_exception);
// Link authority for eosio reqauth action with alice's spending key
chain.link_authority("alice", "eosio", "spending", "reqauth");
// Now, req auth action with alice's spending key should succeed
......@@ -254,12 +254,12 @@ BOOST_AUTO_TEST_CASE(link_auths) { try {
// Unlink alice with eosio reqauth
chain.unlink_authority("alice", "eosio", "reqauth");
// Now, req auth action with alice's spending key should fail
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "spending"} }, { spending_priv_key }), tx_irrelevant_auth);
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "spending"} }, { spending_priv_key }), irrelevant_auth_exception);
chain.produce_block();
// Send req auth action with scud key, it should fail
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "scud"} }, { scud_priv_key }), tx_irrelevant_auth);
BOOST_CHECK_THROW(chain.push_reqauth("alice", { permission_level{N(alice), "scud"} }, { scud_priv_key }), irrelevant_auth_exception);
// Link authority for any eosio action with alice's scud key
chain.link_authority("alice", "eosio", "scud");
// Now, req auth action with alice's scud key should succeed
......@@ -323,7 +323,7 @@ BOOST_AUTO_TEST_CASE( any_auth ) { try {
/// this should fail because spending is not active which is default for reqauth
BOOST_REQUIRE_THROW( chain.push_reqauth("alice", { permission_level{N(alice), "spending"} }, { spending_priv_key }),
tx_irrelevant_auth );
irrelevant_auth_exception );
chain.produce_block();
......@@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE( any_auth ) { try {
/// this should fail because bob cannot authorize for alice, the permission given must be one-of alices
BOOST_REQUIRE_THROW( chain.push_reqauth("alice", { permission_level{N(bob), "spending"} }, { spending_priv_key }),
tx_missing_auth );
missing_auth_exception );
chain.produce_block();
......
......@@ -2163,7 +2163,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try {
chain::canceldelay{{N(tester), N(first)}, trx_id});
chain.set_transaction_headers(trx);
trx.sign(chain.get_private_key(N(tester), "second"), chain_id_type());
BOOST_REQUIRE_THROW( chain.push_transaction(trx), tx_irrelevant_auth );
BOOST_REQUIRE_THROW( chain.push_transaction(trx), irrelevant_auth_exception );
}
// canceldelay with "active" permission for delayed transfer of 1.0000 CUR
......@@ -2289,7 +2289,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try {
chain::canceldelay{{N(tester), config::owner_name}, trx_id});
chain.set_transaction_headers(trx);
trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type());
BOOST_REQUIRE_THROW( chain.push_transaction(trx), tx_irrelevant_auth );
BOOST_REQUIRE_THROW( chain.push_transaction(trx), irrelevant_auth_exception );
}
// canceldelay with "owner" permission for delayed transfer of 10.0000 CUR
......
......@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
// relax from the starting state (congested) to the idle state as fast as possible
uint32_t iterations = 0;
while (get_virtual_block_cpu_limit() < desired_virtual_limit && iterations <= expected_relax_iterations) {
while( get_virtual_block_cpu_limit() < desired_virtual_limit && iterations <= expected_relax_iterations ) {
add_transaction_usage({account},0,0,iterations);
process_block_usage(iterations++);
}
......@@ -86,13 +86,13 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
BOOST_REQUIRE_EQUAL(get_virtual_block_cpu_limit(), desired_virtual_limit);
// push maximum resources to go from idle back to congested as fast as possible
iterations = 0;
while (get_virtual_block_cpu_limit() > config::default_max_block_cpu_usage && iterations <= expected_contract_iterations) {
while( get_virtual_block_cpu_limit() > config::default_max_block_cpu_usage
&& iterations <= expected_relax_iterations + expected_contract_iterations ) {
add_transaction_usage({account}, config::default_max_block_cpu_usage, 0, iterations);
process_block_usage(iterations++);
}
BOOST_REQUIRE_EQUAL(iterations, expected_contract_iterations);
BOOST_REQUIRE_EQUAL(iterations, expected_relax_iterations + expected_contract_iterations);
BOOST_REQUIRE_EQUAL(get_virtual_block_cpu_limit(), config::default_max_block_cpu_usage);
} FC_LOG_AND_RETHROW();
......@@ -116,7 +116,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
// relax from the starting state (congested) to the idle state as fast as possible
uint32_t iterations = 0;
while (get_virtual_block_net_limit() < desired_virtual_limit && iterations <= expected_relax_iterations) {
while( get_virtual_block_net_limit() < desired_virtual_limit && iterations <= expected_relax_iterations ) {
add_transaction_usage({account},0,0,iterations);
process_block_usage(iterations++);
}
......@@ -125,13 +125,13 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
BOOST_REQUIRE_EQUAL(get_virtual_block_net_limit(), desired_virtual_limit);
// push maximum resources to go from idle back to congested as fast as possible
iterations = 0;
while (get_virtual_block_net_limit() > config::default_max_block_net_usage && iterations <= expected_contract_iterations) {
while( get_virtual_block_net_limit() > config::default_max_block_net_usage
&& iterations <= expected_relax_iterations + expected_contract_iterations ) {
add_transaction_usage({account},0, config::default_max_block_net_usage, iterations);
process_block_usage(iterations++);
}
BOOST_REQUIRE_EQUAL(iterations, expected_contract_iterations);
BOOST_REQUIRE_EQUAL(iterations, expected_relax_iterations + expected_contract_iterations);
BOOST_REQUIRE_EQUAL(get_virtual_block_net_limit(), config::default_max_block_net_usage);
} FC_LOG_AND_RETHROW();
......@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
}
// use too much, and expect failure;
BOOST_REQUIRE_THROW(add_transaction_usage({account}, expected_limits.at(idx) + 1, 0, 0), tx_resource_exhausted);
BOOST_REQUIRE_THROW(add_transaction_usage({account}, expected_limits.at(idx) + 1, 0, 0), tx_cpu_resource_exhausted);
}
} FC_LOG_AND_RETHROW();
......@@ -195,7 +195,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
}
// use too much, and expect failure;
BOOST_REQUIRE_THROW(add_transaction_usage({account}, 0, expected_limits.at(idx) + 1, 0), tx_resource_exhausted);
BOOST_REQUIRE_THROW(add_transaction_usage({account}, 0, expected_limits.at(idx) + 1, 0), tx_net_resource_exhausted);
}
} FC_LOG_AND_RETHROW();
......@@ -250,7 +250,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
}
add_pending_ram_usage(account, increment);
BOOST_REQUIRE_THROW(verify_account_ram_usage(account), tx_resource_exhausted);
BOOST_REQUIRE_THROW(verify_account_ram_usage(account), ram_usage_exceeded);
} FC_LOG_AND_RETHROW();
BOOST_FIXTURE_TEST_CASE(enforce_account_ram_limit_underflow, resource_limits_fixture) try {
......@@ -298,7 +298,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test)
}
set_account_limits(account, limit - increment * expected_iterations, -1, -1);
BOOST_REQUIRE_THROW(verify_account_ram_usage(account), tx_resource_exhausted);
BOOST_REQUIRE_THROW(verify_account_ram_usage(account), ram_usage_exceeded);
} FC_LOG_AND_RETHROW();
BOOST_AUTO_TEST_SUITE_END()
......@@ -421,14 +421,14 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_overflow_tests, tester ) try {
// the maximum value below 2^31 representable in IEEE float32
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f32", "f32.const 2147483520"));
// -2^31
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f32", "f32.const -2147483648"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f32", "f32.const -2147483648"));
// the maximum value below -2^31 in IEEE float32
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_s_f32", "f32.const -2147483904"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_s_f32", "f32.const -2147483904"));
//
//// float32 => uint32
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const 0"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const -1"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const 0"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const -1"));
// max value below 2^32 in IEEE float32
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const 4294967040"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f32", "f32.const 4294967296"));
......@@ -437,13 +437,13 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_overflow_tests, tester ) try {
//// double => int32
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const 2147483648"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const 2147483647"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const -2147483648"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const -2147483649"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const -2147483648"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_s_f64", "f64.const -2147483649"));
//
//// double => uint32
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const 0"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const -1"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const 0"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const -1"));
BOOST_REQUIRE_EQUAL(true, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const 4294967295"));
BOOST_REQUIRE_EQUAL(false, check(i32_overflow_wast, "i32_trunc_u_f64", "f64.const 4294967296"));
......@@ -454,16 +454,16 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_overflow_tests, tester ) try {
// the maximum value below 2^63 representable in IEEE float32
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f32", "f32.const 9223371487098961920"));
// -2^63
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f32", "f32.const -9223372036854775808"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f32", "f32.const -9223372036854775808"));
// the maximum value below -2^63 in IEEE float32
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_s_f32", "f32.const -9223373136366403584"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_s_f32", "f32.const -9223373136366403584"));
//// float32 => uint64
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const -1"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const 0"));
// max value below 2^64 in IEEE float32
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const 18446742974197923840"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const 18446744073709551616"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const 18446742974197923840"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f32", "f32.const 18446744073709551616"));
//// double => int64
// 2^63
......@@ -471,24 +471,24 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_overflow_tests, tester ) try {
// the maximum value below 2^63 representable in IEEE float64
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f64", "f64.const 9223372036854774784"));
// -2^63
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f64", "f64.const -9223372036854775808"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_s_f64", "f64.const -9223372036854775808"));
// the maximum value below -2^63 in IEEE float64
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_s_f64", "f64.const -9223372036854777856"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_s_f64", "f64.const -9223372036854777856"));
//// double => uint64
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const -1"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const 0"));
// max value below 2^64 in IEEE float64
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const 18446744073709549568"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const 18446744073709551616"));
BOOST_REQUIRE_EQUAL(true, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const 18446744073709549568"));
BOOST_REQUIRE_EQUAL(false, check(i64_overflow_wast, "i64_trunc_u_f64", "f64.const 18446744073709551616"));
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(misaligned_tests, tester ) try {
produce_blocks(2);
create_accounts( {N(aligncheck)} );
produce_block();
auto check_aligned = [&]( auto wast ) {
auto check_aligned = [&]( auto wast ) {
set_code(N(aligncheck), wast);
produce_blocks(10);
......@@ -503,7 +503,7 @@ BOOST_FIXTURE_TEST_CASE(misaligned_tests, tester ) try {
trx.sign(get_private_key( N(aligncheck), "active" ), chain_id_type());
push_transaction(trx);
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id()));
};
......@@ -560,7 +560,7 @@ BOOST_FIXTURE_TEST_CASE(cpu_usage_tests, tester ) try {
produce_blocks(1);
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id()));
pass = true;
} catch (eosio::chain::tx_resource_exhausted &) {
} catch (eosio::chain::tx_cpu_resource_exhausted &) {
produce_blocks(1);
}
......@@ -621,10 +621,10 @@ BOOST_FIXTURE_TEST_CASE(weighted_cpu_limit_tests, tester ) try {
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id()));
pass = true;
count++;
} catch (eosio::chain::tx_resource_exhausted &) {
} catch (eosio::chain::tx_cpu_resource_exhausted &) {
BOOST_REQUIRE_EQUAL(count, 3);
break;
}
}
BOOST_REQUIRE_EQUAL(true, validate());
if (count == 2) { // add a big weight on acc2, making f_tests out of resource
......@@ -1423,7 +1423,7 @@ BOOST_FIXTURE_TEST_CASE( trigger_serialization_errors, TESTER) try {
0x00, 0x05, 0x03, 0x01, 0x00, 0x20, 0x07, 0x09, 0x01, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x00,
0x01, 0x0a, 0x0c, 0x01, 0x0a, 0x00, 0x41, 0x04, 0x41, 0x05, 0x41, 0x10, 0x10, 0x00, 0x0b, 0x0b,
0x0b, 0x01, 0x00, 0x41, 0x04, 0x0b, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f };
const vector<uint8_t> malformed_wasm = { 0x00, 0x61, 0x03, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x02, 0x60, 0x03, 0x7f, 0x7f, 0x7f,
0x00, 0x60, 0x03, 0x7e, 0x7e, 0x7e, 0x00, 0x02, 0x0e, 0x01, 0x03, 0x65, 0x6e, 0x76, 0x06, 0x73,
0x68, 0x61, 0x32, 0x38, 0x36, 0x00, 0x00, 0x03, 0x03, 0x01, 0x01, 0x04, 0x04, 0x01, 0x70, 0x00,
......@@ -1487,7 +1487,7 @@ BOOST_FIXTURE_TEST_CASE(net_usage_tests, tester ) try {
push_transaction(trx);
produce_blocks(1);
return true;
} catch (tx_resource_exhausted &) {
} catch (tx_net_resource_exhausted &) {
return false;
} catch (transaction_exception &) {
return false;
......@@ -1538,7 +1538,7 @@ BOOST_FIXTURE_TEST_CASE(weighted_net_usage_tests, tester ) try {
push_transaction(trx);
produce_blocks(1);
return true;
} catch (tx_resource_exhausted &) {
} catch (tx_net_resource_exhausted &) {
return false;
}
};
......@@ -1547,7 +1547,7 @@ BOOST_FIXTURE_TEST_CASE(weighted_net_usage_tests, tester ) try {
resource_limits_manager mgr = control->get_mutable_resource_limits_manager();
mgr.set_account_limits(account, -1, 1, -1); // set weight = 1 for account
BOOST_REQUIRE_EQUAL(true, check(128));
BOOST_REQUIRE_EQUAL(true, check(128));
mgr.set_account_limits(acc2, -1, 1000, -1); // set a big weight for other account
BOOST_REQUIRE_EQUAL(false, check(128));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册