Skip to content

Commit 3cf1af3

Browse files
committed
Check ticket parameters
1 parent 597e70e commit 3cf1af3

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Ticket issues
2+
#ifndef SOFTFORK_20250518_TIME
3+
#define SOFTFORK_20250518_TIME (fc::time_point_sec( 1747555200 )) // Sunday, May 18, 2025 8:00:00 UTC
4+
#define SOFTFORK_20250518_PASSED(head_block_time) (head_block_time >= SOFTFORK_20250518_TIME)
5+
#endif

libraries/chain/proposal_evaluator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,16 @@ struct proposal_operation_hardfork_visitor
262262
}
263263
void operator()(const graphene::chain::ticket_create_operation&) const {
264264
FC_ASSERT( HARDFORK_CORE_2103_PASSED(block_time), "Not allowed until hardfork 2103" );
265+
if( SOFTFORK_20250518_PASSED(block_time) ) {
266+
FC_ASSERT( false, "Temporarily disabled" );
267+
}
265268
}
266-
void operator()(const graphene::chain::ticket_update_operation&) const {
269+
void operator()(const graphene::chain::ticket_update_operation& op) const {
267270
FC_ASSERT( HARDFORK_CORE_2103_PASSED(block_time), "Not allowed until hardfork 2103" );
271+
if( SOFTFORK_20250518_PASSED(block_time)
272+
&& op.target_type == static_cast<uint64_t>(ticket_type::lock_forever) ) {
273+
FC_ASSERT( false, "Temporarily disabled" );
274+
}
268275
}
269276
void operator()(const graphene::chain::liquidity_pool_create_operation&) const {
270277
FC_ASSERT( HARDFORK_LIQUIDITY_POOL_PASSED(block_time), "Not allowed until the LP hardfork" );

libraries/chain/ticket_evaluator.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,53 @@
3333

3434
namespace graphene { namespace chain {
3535

36+
namespace detail {
37+
38+
void check_ticket_params_sf250518(const database& d, const ticket_create_operation& op)
39+
{
40+
const auto& idx = d.get_index_type<ticket_index>().indices().get<by_account>();
41+
auto itr = idx.lower_bound( op.account );
42+
auto itr_end = idx.upper_bound( op.account );
43+
share_type total_forever_amount;
44+
share_type total_other_amount;
45+
for( ; itr != itr_end; ++itr )
46+
{
47+
const auto& t = *itr;
48+
if( t.target_type == ticket_type::lock_forever )
49+
total_forever_amount += t.amount.amount;
50+
else
51+
total_other_amount += t.amount.amount;
52+
}
53+
54+
if( op.target_type == static_cast<uint64_t>(ticket_type::lock_forever) )
55+
{
56+
const share_type max_forever_amount( int64_t(1000) * GRAPHENE_BLOCKCHAIN_PRECISION );
57+
if ( total_forever_amount + op.amount.amount > max_forever_amount )
58+
FC_ASSERT( false, "Temporarily unacceptable" );
59+
}
60+
else
61+
{
62+
const asset_id_type a(6623);
63+
const auto b = d.get_balance( op.account, a );
64+
const share_type max_other_amount = b.amount;
65+
if ( total_other_amount + op.amount.amount > max_other_amount )
66+
FC_ASSERT( false, "Temporarily unacceptable" );
67+
}
68+
}
69+
70+
};
71+
3672
void_result ticket_create_evaluator::do_evaluate(const ticket_create_operation& op)
3773
{ try {
3874
const database& d = db();
3975
const auto block_time = d.head_block_time();
4076

4177
FC_ASSERT( HARDFORK_CORE_2103_PASSED(block_time), "Not allowed until hardfork 2103" );
4278

79+
if( SOFTFORK_20250518_PASSED(block_time) ) {
80+
detail::check_ticket_params_sf250518( d, op );
81+
}
82+
4383
return void_result();
4484
} FC_CAPTURE_AND_RETHROW( (op) ) }
4585

@@ -70,6 +110,12 @@ void_result ticket_update_evaluator::do_evaluate(const ticket_update_operation&
70110
{ try {
71111
database& d = db();
72112

113+
const auto block_time = d.head_block_time();
114+
if( SOFTFORK_20250518_PASSED(block_time)
115+
&& op.target_type == static_cast<uint64_t>(ticket_type::lock_forever) ) {
116+
FC_ASSERT( false, "Temporarily disabled" );
117+
}
118+
73119
_ticket = &op.ticket(d);
74120

75121
FC_ASSERT( _ticket->account == op.account, "Ticket is not owned by the account" );

0 commit comments

Comments
 (0)