Delay deletion of completed/canceled events to avoid an error producing
blocks when a betting market group with no betting markets is canceled.
This commit is contained in:
parent
cfd77773c7
commit
5343c073bd
5 changed files with 42 additions and 3 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/range/combine.hpp>
|
||||
#include <boost/range/join.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
|
@ -276,9 +277,14 @@ void database::settle_betting_market_group(const betting_market_group_object& be
|
|||
|
||||
dlog("removing betting market group ${id}", ("id", betting_market_group.id));
|
||||
remove(betting_market_group);
|
||||
}
|
||||
|
||||
if (event.get_status() == event_status::canceled ||
|
||||
event.get_status() == event_status::settled) {
|
||||
void database::remove_completed_events()
|
||||
{
|
||||
const auto& event_index = get_index_type<event_object_index>().indices().get<by_event_status>();
|
||||
auto canceled_events = boost::make_iterator_range(event_index.equal_range(event_status::canceled));
|
||||
auto settled_events = boost::make_iterator_range(event_index.equal_range(event_status::settled));
|
||||
for (const event_object& event : boost::join(canceled_events, settled_events)) {
|
||||
dlog("removing event ${id}", ("id", event.id));
|
||||
remove(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -677,6 +677,7 @@ void process_settled_betting_markets(database& db, fc::time_point_sec current_bl
|
|||
void database::update_betting_markets(fc::time_point_sec current_block_time)
|
||||
{
|
||||
process_settled_betting_markets(*this, current_block_time);
|
||||
remove_completed_events();
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@ namespace graphene { namespace chain {
|
|||
void resolve_betting_market_group(const betting_market_group_object& betting_market_group,
|
||||
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions);
|
||||
void settle_betting_market_group(const betting_market_group_object& betting_market_group);
|
||||
void remove_completed_events();
|
||||
/**
|
||||
* @brief Process a new bet
|
||||
* @param new_bet_object The new bet to process
|
||||
|
|
|
|||
|
|
@ -95,11 +95,13 @@ class event_object : public graphene::db::abstract_object< event_object >
|
|||
};
|
||||
|
||||
struct by_event_group_id;
|
||||
struct by_event_status;
|
||||
typedef multi_index_container<
|
||||
event_object,
|
||||
indexed_by<
|
||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||
ordered_non_unique< tag<by_event_group_id>, member< event_object, event_group_id_type, &event_object::event_group_id > > > > event_object_multi_index_type;
|
||||
ordered_non_unique< tag<by_event_group_id>, member< event_object, event_group_id_type, &event_object::event_group_id > >,
|
||||
ordered_non_unique< tag<by_event_status>, const_mem_fun< event_object, event_status, &event_object::get_status > > > > event_object_multi_index_type;
|
||||
|
||||
typedef generic_index<event_object, event_object_multi_index_type> event_object_index;
|
||||
|
||||
|
|
|
|||
|
|
@ -731,6 +731,35 @@ BOOST_AUTO_TEST_CASE( chained_market_create_test )
|
|||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( testnet_witness_block_production_error )
|
||||
{
|
||||
try
|
||||
{
|
||||
CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0);
|
||||
create_betting_market_group({{"en", "Unused"}}, capitals_vs_blackhawks.id, betting_market_rules.id, asset_id_type(), false, 0);
|
||||
generate_blocks(1);
|
||||
|
||||
BOOST_TEST_MESSAGE("setting the event in progress");
|
||||
update_event(capitals_vs_blackhawks.id, _status = event_status::in_progress);
|
||||
generate_blocks(1);
|
||||
BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::in_progress);
|
||||
BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::in_play);
|
||||
|
||||
BOOST_TEST_MESSAGE("setting the event to finished");
|
||||
update_event(capitals_vs_blackhawks.id, _status = event_status::finished);
|
||||
generate_blocks(1);
|
||||
BOOST_CHECK(capitals_vs_blackhawks.get_status() == event_status::finished);
|
||||
BOOST_CHECK(moneyline_betting_markets.get_status() == betting_market_group_status::closed);
|
||||
BOOST_CHECK(capitals_win_market.get_status() == betting_market_status::unresolved);
|
||||
BOOST_CHECK(blackhawks_win_market.get_status() == betting_market_status::unresolved);
|
||||
//BOOST_CHECK(unused_betting_market_group.get_status() == betting_market_group_status::closed);
|
||||
|
||||
BOOST_TEST_MESSAGE("setting the event to canceled");
|
||||
update_event(capitals_vs_blackhawks.id, _status = event_status::canceled);
|
||||
generate_blocks(1);
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue