Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/WBP-1221 remove deferred logic #86

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions contracts/eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ namespace eosiosystem {
//create/update/delete refund
auto net_balance = stake_net_delta;
auto cpu_balance = stake_cpu_delta;
bool need_deferred_trx = false;


// net and cpu are same sign by assertions in delegatebw and undelegatebw
Expand Down Expand Up @@ -293,9 +292,6 @@ namespace eosiosystem {

if ( req->is_empty() ) {
refunds_tbl.erase( req );
need_deferred_trx = false;
danielvo11 marked this conversation as resolved.
Show resolved Hide resolved
} else {
need_deferred_trx = true;
}
} else if ( net_balance.amount < 0 || cpu_balance.amount < 0 ) { //need to create refund
refunds_tbl.emplace( from, [&]( refund_request& r ) {
Expand All @@ -314,23 +310,9 @@ namespace eosiosystem {
}
r.request_time = current_time_point();
});
need_deferred_trx = true;
} // else stake increase requested with no existing row in refunds_tbl -> nothing to do with refunds_tbl
} /// end if is_delegating_to_self || is_undelegating

if ( need_deferred_trx ) {
eosio::transaction out;
out.actions.emplace_back( permission_level{from, active_permission},
get_self(), "refund"_n,
from
);
out.delay_sec = refund_delay_sec;
eosio::cancel_deferred( from.value ); // TODO: Remove this line when replacing deferred transactions is fixed
out.send( from.value, from, true );
} else {
eosio::cancel_deferred( from.value );
}

auto transfer_amount = net_balance + cpu_balance;
if ( 0 < transfer_amount.amount ) {
token::transfer_action transfer_act{ token_account, { {source_stake_from, active_permission} } };
Expand Down Expand Up @@ -440,7 +422,7 @@ namespace eosiosystem {
cb.unclaimed_balance = zero_asset;
});
}

// Deal with paying
const asset payable_rewards ( unclaimed_balance, core_symbol() );

Expand Down
10 changes: 0 additions & 10 deletions contracts/eosio.system/src/name_bidding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ namespace eosiosystem {
});
}

eosio::transaction t;
t.actions.emplace_back( permission_level{current->high_bidder, active_permission},
get_self(), "bidrefund"_n,
std::make_tuple( current->high_bidder, newname )
);
t.delay_sec = 0;
uint128_t deferred_id = (uint128_t(newname.value) << 64) | current->high_bidder.value;
eosio::cancel_deferred( deferred_id );
t.send( deferred_id, bidder );

bids.modify( current, bidder, [&]( auto& b ) {
b.high_bidder = bidder;
b.high_bid = bid.amount;
Expand Down
22 changes: 22 additions & 0 deletions tests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
produce_blocks(1);
BOOST_REQUIRE_EQUAL( core_sym::from_string("700.0000"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( init_eosio_stake_balance + core_sym::from_string("300.0000"), get_balance( "eosio.stake"_n ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("refund is not available yet"),
push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
//after 3 days funds should be released
produce_block( fc::hours(1) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( success(), push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("1000.0000"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( init_eosio_stake_balance, get_balance( "eosio.stake"_n ) );

Expand All @@ -231,10 +234,14 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
produce_block( fc::hours(3*24-1) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( core_sym::from_string("700.0000"), get_balance( "alice1111111" ) );

BOOST_REQUIRE_EQUAL( wasm_assert_msg("refund is not available yet"),
push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
//after 3 days funds should be released
produce_block( fc::hours(1) );
produce_blocks(1);

BOOST_REQUIRE_EQUAL( success(), push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("0.0000") ), get_voter_info( "alice1111111" ) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( core_sym::from_string("1000.0000"), get_balance( "alice1111111" ) );
Expand Down Expand Up @@ -275,11 +282,18 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake_with_transfer, eosio_system_tester ) try
produce_block( fc::hours(3*24-1) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( core_sym::from_string("700.0000"), get_balance( "alice1111111" ) );

// call refund expected to fail too early
BOOST_REQUIRE_EQUAL( wasm_assert_msg("refund is not available yet"),
push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );

//after 3 days funds should be released

produce_block( fc::hours(1) );
produce_blocks(1);

// now we can do the refund
BOOST_REQUIRE_EQUAL( success(), push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("1300.0000"), get_balance( "alice1111111" ) );

//stake should be equal to what was staked in constructor, voting power should be 0
Expand Down Expand Up @@ -341,9 +355,13 @@ BOOST_FIXTURE_TEST_CASE( stake_while_pending_refund, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( core_sym::from_string("700.0000"), get_balance( "alice1111111" ) );
//after 3 days funds should be released

BOOST_REQUIRE_EQUAL( wasm_assert_msg("refund is not available yet"),
push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );

produce_block( fc::hours(1) );
produce_blocks(1);

BOOST_REQUIRE_EQUAL( success(), push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("1300.0000"), get_balance( "alice1111111" ) );

//stake should be equal to what was staked in constructor, voting power should be 0
Expand Down Expand Up @@ -606,6 +624,7 @@ BOOST_FIXTURE_TEST_CASE( adding_stake_partial_unstake, eosio_system_tester ) try
BOOST_REQUIRE_EQUAL( core_sym::from_string("550.0000"), get_balance( "alice1111111" ) );
produce_block( fc::days(1) );
produce_blocks(1);
BOOST_REQUIRE_EQUAL( success(), push_action( "alice1111111"_n, "refund"_n, mvo()("owner", "alice1111111") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("850.0000"), get_balance( "alice1111111" ) );

} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -977,6 +996,7 @@ BOOST_FIXTURE_TEST_CASE( vote_for_producer, eosio_system_tester, * boost::unit_t
//carol1111111 should receive funds in 3 days
produce_block( fc::days(3) );
produce_block();
BOOST_REQUIRE_EQUAL( success(), push_action( "carol1111111"_n, "refund"_n, mvo()("owner", "carol1111111") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("3000.0000"), get_balance( "carol1111111" ) );

} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -3738,6 +3758,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try {
const asset initial_names_balance = get_balance("eosio.names"_n);
BOOST_REQUIRE_EQUAL( success(),
bidname( "alice", "prefb", core_sym::from_string("1.1001") ) );
BOOST_REQUIRE_EQUAL( success(), push_action( "bob"_n, "bidrefund"_n, mvo()("bidder","bob")("newname", "prefb") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string( "9997.9997" ), get_balance("bob") );
BOOST_REQUIRE_EQUAL( core_sym::from_string( "9998.8999" ), get_balance("alice") );
BOOST_REQUIRE_EQUAL( initial_names_balance + core_sym::from_string("0.1001"), get_balance("eosio.names"_n) );
Expand All @@ -3749,6 +3770,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( core_sym::from_string( "10000.0000" ), get_balance("david") );
BOOST_REQUIRE_EQUAL( success(),
bidname( "david", "prefd", core_sym::from_string("1.9900") ) );
BOOST_REQUIRE_EQUAL( success(), push_action( "carl"_n, "bidrefund"_n, mvo()("bidder","carl")("newname", "prefd") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string( "9999.0000" ), get_balance("carl") );
BOOST_REQUIRE_EQUAL( core_sym::from_string( "9998.0100" ), get_balance("david") );
}
Expand Down
Loading