提交 88f499d8 编写于 作者: A Anton Perkov

cancel_deferred returns 0 (transaction not found) or 1 (canceled), don't reset...

cancel_deferred returns 0 (transaction not found) or 1 (canceled), don't reset refund timer when taking moner from refund to stake #3180
上级 a4789ed3
......@@ -296,6 +296,9 @@ namespace eosiosystem {
bool need_deferred_trx = false;
if ( req != refunds_tbl.end() ) { //need to update refund
refunds_tbl.modify( req, 0, [&]( refund_request& r ) {
if ( net_balance <= asset(0) || cpu_balance <= asset(0) ) {
r.request_time = now();
}
r.net_amount -= net_balance;
if ( r.net_amount < asset(0) ) {
net_balance = -r.net_amount;
......@@ -306,7 +309,6 @@ namespace eosiosystem {
cpu_balance = -r.cpu_amount;
r.cpu_amount = asset(0);
}
r.request_time = now();
});
eosio_assert( asset(0) <= req->net_amount, "negative net refund amount" ); //should never happen
eosio_assert( asset(0) <= req->cpu_amount, "negative cpu refund amount" ); //should never happen
......@@ -339,7 +341,7 @@ namespace eosiosystem {
out.delay_sec = refund_delay;
out.send( from, receiver, true );
} else {
//cancel_deferred( from );
cancel_deferred( from );
}
auto transfer_amount = net_balance + cpu_balance;
......
......@@ -60,7 +60,11 @@ extern "C" {
*/
void send_deferred(const uint128_t& sender_id, account_name payer, const char *serialized_transaction, size_t size, uint32_t replace_existing = 0);
void cancel_deferred(const uint128_t& sender_id);
/**
* cancel deferred transaction
* @return 1 if transaction was canceled, 0 if transaction was not found
*/
int cancel_deferred(const uint128_t& sender_id);
/**
* access a copy of the currently executing transaction
......
......@@ -138,7 +138,8 @@ extern "C" {
WASM_TEST_HANDLER_EX(test_transaction, send_deferred_transaction);
WASM_TEST_HANDLER_EX(test_transaction, send_deferred_transaction_replace);
WASM_TEST_HANDLER(test_transaction, send_deferred_tx_with_dtt_action);
WASM_TEST_HANDLER(test_transaction, cancel_deferred_transaction);
WASM_TEST_HANDLER(test_transaction, cancel_deferred_transaction_success);
WASM_TEST_HANDLER(test_transaction, cancel_deferred_transaction_not_found);
WASM_TEST_HANDLER(test_transaction, send_cf_action);
WASM_TEST_HANDLER(test_transaction, send_cf_action_fail);
WASM_TEST_HANDLER(test_transaction, stateful_api);
......
......@@ -169,7 +169,8 @@ struct test_transaction {
static void send_deferred_transaction(uint64_t receiver, uint64_t code, uint64_t action);
static void send_deferred_transaction_replace(uint64_t receiver, uint64_t code, uint64_t action);
static void send_deferred_tx_with_dtt_action();
static void cancel_deferred_transaction();
static void cancel_deferred_transaction_success();
static void cancel_deferred_transaction_not_found();
static void send_cf_action();
static void send_cf_action_fail();
static void stateful_api();
......
......@@ -271,9 +271,16 @@ void test_transaction::send_deferred_tx_with_dtt_action() {
}
void test_transaction::cancel_deferred_transaction() {
void test_transaction::cancel_deferred_transaction_success() {
using namespace eosio;
cancel_deferred( 0xffffffffffffffff ); //use the same id (0) as in send_deferred_transaction
auto r = cancel_deferred( 0xffffffffffffffff ); //use the same id (0) as in send_deferred_transaction
eosio_assert( r, "transaction was not found" );
}
void test_transaction::cancel_deferred_transaction_not_found() {
using namespace eosio;
auto r = cancel_deferred( 0xffffffffffffffff ); //use the same id (0) as in send_deferred_transaction
eosio_assert( !r, "transaction was canceled, whild should not be found" );
}
void test_transaction::send_cf_action() {
......
......@@ -290,16 +290,15 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
trx_context.checktime();
}
void apply_context::cancel_deferred_transaction( const uint128_t& sender_id, account_name sender ) {
bool apply_context::cancel_deferred_transaction( const uint128_t& sender_id, account_name sender ) {
auto& generated_transaction_idx = db.get_mutable_index<generated_transaction_multi_index>();
const auto* gto = db.find<generated_transaction_object,by_sender_id>(boost::make_tuple(sender, sender_id));
EOS_ASSERT( gto != nullptr, transaction_exception,
"there is no generated transaction created by account ${sender} with sender id ${sender_id}",
("sender", sender)("sender_id", sender_id) );
trx_context.add_ram_usage( gto->payer, -(config::billable_size_v<generated_transaction_object> + gto->packed_trx.size()) );
generated_transaction_idx.remove(*gto);
if ( gto ) {
trx_context.add_ram_usage( gto->payer, -(config::billable_size_v<generated_transaction_object> + gto->packed_trx.size()) );
generated_transaction_idx.remove(*gto);
}
trx_context.checktime();
return gto;
}
const table_id_object* apply_context::find_table( name code, name scope, name table ) {
......
......@@ -477,8 +477,8 @@ class apply_context {
void execute_inline( action&& a );
void execute_context_free_inline( action&& a );
void schedule_deferred_transaction( const uint128_t& sender_id, account_name payer, transaction&& trx, bool replace_existing );
void cancel_deferred_transaction( const uint128_t& sender_id, account_name sender );
void cancel_deferred_transaction( const uint128_t& sender_id ) { cancel_deferred_transaction(sender_id, receiver); }
bool cancel_deferred_transaction( const uint128_t& sender_id, account_name sender );
bool cancel_deferred_transaction( const uint128_t& sender_id ) { return cancel_deferred_transaction(sender_id, receiver); }
/// Authorization methods:
......
......@@ -1257,9 +1257,9 @@ class transaction_api : public context_aware_api {
} FC_CAPTURE_AND_RETHROW((fc::to_hex(data, data_len)));
}
void cancel_deferred( const unsigned __int128& val ) {
bool cancel_deferred( const unsigned __int128& val ) {
fc::uint128_t sender_id(val>>64, uint64_t(val) );
context.cancel_deferred_transaction( (unsigned __int128)sender_id );
return context.cancel_deferred_transaction( (unsigned __int128)sender_id );
}
};
......@@ -1754,7 +1754,7 @@ REGISTER_INTRINSICS(transaction_api,
(send_inline, void(int, int) )
(send_context_free_inline, void(int, int) )
(send_deferred, void(int, int64_t, int, int, int32_t) )
(cancel_deferred, void(int) )
(cancel_deferred, int(int) )
);
REGISTER_INTRINSICS(context_free_api,
......
......@@ -980,7 +980,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
transaction_trace_ptr trace;
auto c = control->applied_transaction.connect([&]( const transaction_trace_ptr& t) { if (t && t->scheduled) { trace = t; } } );
CALL_TEST_FUNCTION(*this, "test_transaction", "send_deferred_transaction", {});
CALL_TEST_FUNCTION(*this, "test_transaction", "cancel_deferred_transaction", {});
CALL_TEST_FUNCTION(*this, "test_transaction", "cancel_deferred_transaction_success", {});
produce_block( fc::seconds(2) );
BOOST_CHECK(!trace);
c.disconnect();
......@@ -988,9 +988,9 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {
produce_blocks(10);
//cancel_deferred() fails if no transaction is scheduled
//cancel_deferred() return zero if no scheduled transaction found
{
BOOST_CHECK_THROW(CALL_TEST_FUNCTION(*this, "test_transaction", "cancel_deferred_transaction", {}), transaction_exception);
CALL_TEST_FUNCTION(*this, "test_transaction", "cancel_deferred_transaction_not_found", {});
}
produce_blocks(10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册