Commit 021f3d6c authored by Mariusz's avatar Mariusz

Issue #59 - Increment major version, while not breaking the chain

parent 488e6db2
......@@ -214,7 +214,7 @@ void database::open( const open_args& args )
with_read_lock( [&]()
{
const auto& hardforks = get_hardfork_property_object();
if (hardforks.last_hardfork >= HIVE_HARDFORK_0_24)
if (hardforks.last_hardfork >= HIVE_HARDFORK_1_24)
{
ilog("Loaded blockchain which had already processed hardfork 24, setting Hive chain id");
set_chain_id(HIVE_CHAIN_ID);
......@@ -2162,7 +2162,7 @@ void database::clear_account( const account_object& account,
a.to_withdraw = 0;
a.withdrawn = 0;
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
a.delayed_votes.clear();
a.sum_delayed_votes = 0;
......@@ -2254,7 +2254,7 @@ void database::clear_account( const account_object& account,
}
// Touch SDB balances (to be sure all interests are added to balances)
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
adjust_balance( account, asset( 0, HBD_SYMBOL ) );
adjust_savings_balance( account, asset( 0, HBD_SYMBOL ) );
......@@ -2323,7 +2323,7 @@ void database::process_proposals( const block_notification& note )
void database::process_delayed_voting( const block_notification& note )
{
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
delayed_voting dv( *this );
dv.run( note.block.timestamp );
......@@ -2389,7 +2389,7 @@ void database::process_vesting_withdrawals()
optional< delayed_voting > dv;
delayed_voting::opt_votes_update_data_items _votes_update_data_items;
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
dv = delayed_voting( *this );
_votes_update_data_items = delayed_voting::votes_update_data_items();
......@@ -2429,7 +2429,7 @@ void database::process_vesting_withdrawals()
if( auto_vest_mode )
{
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
FC_ASSERT( dv.valid(), "The object processing `delayed votes` must exist" );
......@@ -2470,7 +2470,7 @@ void database::process_vesting_withdrawals()
operation vop = fill_vesting_withdraw_operation( from_account.name, from_account.name, asset( to_convert, VESTS_SYMBOL ), converted_hive );
pre_push_virtual_operation( vop );
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
FC_ASSERT( dv.valid(), "The object processing `delayed votes` must exist" );
......@@ -2504,7 +2504,7 @@ void database::process_vesting_withdrawals()
o.total_vesting_shares.amount -= to_convert;
});
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
FC_ASSERT( dv.valid(), "The object processing `delayed votes` must exist" );
......@@ -4686,7 +4686,7 @@ void database::update_virtual_supply()
{
uint16_t percent_hbd = 0;
if( has_hardfork( HIVE_HARDFORK_0_24 ) )
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
{
// Removing the hbd in the treasury from the debt ratio calculations
const auto &treasury_account = get_treasury();
......@@ -5560,13 +5560,13 @@ void database::init_hardforks()
FC_ASSERT( HIVE_HARDFORK_0_23 == 23, "Invalid hardfork configuration" );
_hardfork_versions.times[ HIVE_HARDFORK_0_23 ] = fc::time_point_sec( HIVE_HARDFORK_0_23_TIME );
_hardfork_versions.versions[ HIVE_HARDFORK_0_23 ] = HIVE_HARDFORK_0_23_VERSION;
FC_ASSERT( HIVE_HARDFORK_0_24 == 24, "Invalid hardfork configuration" );
_hardfork_versions.times[ HIVE_HARDFORK_0_24 ] = fc::time_point_sec( HIVE_HARDFORK_0_24_TIME );
_hardfork_versions.versions[ HIVE_HARDFORK_0_24 ] = HIVE_HARDFORK_0_24_VERSION;
FC_ASSERT( HIVE_HARDFORK_1_24 == 24, "Invalid hardfork configuration" );
_hardfork_versions.times[ HIVE_HARDFORK_1_24 ] = fc::time_point_sec( HIVE_HARDFORK_1_24_TIME );
_hardfork_versions.versions[ HIVE_HARDFORK_1_24 ] = HIVE_HARDFORK_1_24_VERSION;
#ifdef IS_TEST_NET
FC_ASSERT( HIVE_HARDFORK_0_25 == 25, "Invalid hardfork configuration" );
_hardfork_versions.times[ HIVE_HARDFORK_0_25 ] = fc::time_point_sec( HIVE_HARDFORK_0_25_TIME );
_hardfork_versions.versions[ HIVE_HARDFORK_0_25 ] = HIVE_HARDFORK_0_25_VERSION;
FC_ASSERT( HIVE_HARDFORK_1_25 == 25, "Invalid hardfork configuration" );
_hardfork_versions.times[ HIVE_HARDFORK_1_25 ] = fc::time_point_sec( HIVE_HARDFORK_1_25_TIME );
_hardfork_versions.versions[ HIVE_HARDFORK_1_25 ] = HIVE_HARDFORK_1_25_VERSION;
#endif
const auto& hardforks = get_hardfork_property_object();
......@@ -5954,7 +5954,7 @@ void database::apply_hardfork( uint32_t hardfork )
}
break;
}
case HIVE_HARDFORK_0_24:
case HIVE_HARDFORK_1_24:
{
restore_accounts( _hf23_items, hardforkprotect::get_restored_accounts() );
set_chain_id(HIVE_CHAIN_ID);
......
......@@ -756,7 +756,7 @@ void comment_options_evaluator::do_apply( const comment_options_operation& o )
*/
if( !comment_cashout )
{
FC_ASSERT( !_db.has_hardfork( HIVE_HARDFORK_0_24 ), "Updating parameters for comment that is paid out is forbidden." );
FC_ASSERT( !_db.has_hardfork( HIVE_HARDFORK_1_24 ), "Updating parameters for comment that is paid out is forbidden." );
return;
}
......@@ -1175,7 +1175,7 @@ void escrow_release_evaluator::do_apply( const escrow_release_operation& o )
void transfer_evaluator::do_apply( const transfer_operation& o )
{
if ( _db.has_hardfork(HIVE_HARDFORK_0_24) && o.amount.symbol == HIVE_SYMBOL && _db.is_treasury( o.to ) ) {
if ( _db.has_hardfork(HIVE_HARDFORK_1_24) && o.amount.symbol == HIVE_SYMBOL && _db.is_treasury( o.to ) ) {
const auto &fhistory = _db.get_feed_history();
FC_ASSERT(!fhistory.current_median_history.is_null(), "Cannot send HIVE to ${s} because there is no price feed.", ("s", o.to ));
......@@ -1220,7 +1220,7 @@ void transfer_to_vesting_evaluator::do_apply( const transfer_to_vesting_operatio
Therefore an idea is based on voting deferring. Default value is 30 days.
This range of time is enough long to defeat/block potential malicious intention.
*/
if( _db.has_hardfork( HIVE_HARDFORK_0_24 ) )
if( _db.has_hardfork( HIVE_HARDFORK_1_24 ) )
{
asset new_vesting = _db.adjust_account_vesting_balance( to_account, o.amount, false/*to_reward_balance*/, []( asset vests_created ) {} );
......@@ -1925,7 +1925,7 @@ void hf20_vote_evaluator( const vote_operation& o, database& _db )
}
else
{
FC_ASSERT( !_db.has_hardfork( HIVE_HARDFORK_0_24 ), "Votes evaluating for comment that is paid out is forbidden." );
FC_ASSERT( !_db.has_hardfork( HIVE_HARDFORK_1_24 ), "Votes evaluating for comment that is paid out is forbidden." );
}
if( !comment_cashout || _db.calculate_discussion_payout_time( *comment_cashout ) == fc::time_point_sec::maximum() )
......
......@@ -27,7 +27,7 @@ void create_proposal_evaluator::do_apply( const create_proposal_operation& o )
asset fee_hbd( HIVE_TREASURY_FEE, HBD_SYMBOL );
if(_db.has_hardfork(HIVE_HARDFORK_0_24))
if(_db.has_hardfork(HIVE_HARDFORK_1_24))
{
uint32_t proposal_run_time = o.end_date.sec_since_epoch() - o.start_date.sec_since_epoch();
......@@ -83,7 +83,7 @@ void update_proposal_evaluator::do_apply( const update_proposal_operation& o )
{
try
{
FC_ASSERT( _db.has_hardfork( HIVE_HARDFORK_0_24 ), "The update proposal functionality not enabled until hardfork ${hf}", ("hf", HIVE_HARDFORK_0_24) );
FC_ASSERT( _db.has_hardfork( HIVE_HARDFORK_1_24 ), "The update proposal functionality not enabled until hardfork ${hf}", ("hf", HIVE_HARDFORK_1_24) );
const auto& proposal = _db.get< proposal_object, by_proposal_id >( o.proposal_id );
......
#ifndef HIVE_HARDFORK_0_24
#define HIVE_HARDFORK_0_24 24
#define HIVE_TREASURY_RENAME_HARDFORK HIVE_HARDFORK_0_24
#ifndef HIVE_HARDFORK_1_24
#define HIVE_HARDFORK_1_24 24
#define HIVE_TREASURY_RENAME_HARDFORK HIVE_HARDFORK_1_24
long hf24_time();
#define HIVE_HARDFORK_0_24_TIME hf24_time()
#define HIVE_HARDFORK_1_24_TIME hf24_time()
#define HIVE_HARDFORK_0_24_VERSION hardfork_version( 0, 24 )
#define HIVE_HARDFORK_1_24_VERSION hardfork_version( 1, 24 )
#endif
#ifndef HIVE_HARDFORK_0_25
#define HIVE_HARDFORK_0_25 25
#define HIVE_SMT_HARDFORK HIVE_HARDFORK_0_25
#ifndef HIVE_HARDFORK_1_25
#define HIVE_HARDFORK_1_25 25
#define HIVE_SMT_HARDFORK HIVE_HARDFORK_1_25
#define HIVE_HARDFORK_0_25_TIME 1609416000 // Thursday, 31 December 2020 12:00:00 GMT
#define HIVE_HARDFORK_1_25_TIME 1609416000 // Thursday, 31 December 2020 12:00:00 GMT
#define HIVE_HARDFORK_0_25_VERSION hardfork_version( 0, 25 )
#define HIVE_HARDFORK_1_25_VERSION hardfork_version( 1, 25 )
#endif
......@@ -9,7 +9,7 @@
// This is checked by get_config_check.sh called from Dockerfile
#ifdef IS_TEST_NET
#define HIVE_BLOCKCHAIN_VERSION ( version(0, 25, 0) )
#define HIVE_BLOCKCHAIN_VERSION ( version(1, 25, 0) )
#define HIVE_INIT_PRIVATE_KEY (fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("init_key"))))
#define HIVE_INIT_PUBLIC_KEY_STR (std::string( hive::protocol::public_key_type(HIVE_INIT_PRIVATE_KEY.get_public_key()) ))
......@@ -49,7 +49,7 @@
#else // IS LIVE HIVE NETWORK
#define HIVE_BLOCKCHAIN_VERSION ( version(0, 24, 0) )
#define HIVE_BLOCKCHAIN_VERSION ( version(1, 24, 0) )
#define HIVE_INIT_PUBLIC_KEY_STR "STM8GC13uCZbP44HzMLV6zPZGwVQ8Nt4Kji8PapsPiNq1BK153XTX"
#define STEEM_CHAIN_ID fc::sha256()
......
......@@ -16,20 +16,62 @@ struct version
version( uint8_t m, uint8_t h, uint16_t r );
virtual ~version() {}
bool operator == ( const version& o )const { return v_num == o.v_num; }
bool operator != ( const version& o )const { return v_num != o.v_num; }
bool operator < ( const version& o )const { return v_num < o.v_num; }
bool operator <= ( const version& o )const { return v_num <= o.v_num; }
bool operator > ( const version& o )const { return v_num > o.v_num; }
bool operator >= ( const version& o )const { return v_num >= o.v_num; }
bool operator == ( const version& o )const { return _operator< operator_type::equal >( o.v_num ); }
bool operator != ( const version& o )const { return _operator< operator_type::not_equal >( o.v_num ); }
bool operator < ( const version& o )const { return _operator< operator_type::less >( o.v_num ); }
bool operator <= ( const version& o )const { return _operator< operator_type::less_equal >( o.v_num ); }
bool operator > ( const version& o )const { return _operator< operator_type::greater >( o.v_num ); }
bool operator >= ( const version& o )const { return _operator< operator_type::greater_equal >( o.v_num ); }
operator fc::string()const;
uint32_t major_v() { return ( v_num & 0XFF000000 ) >> 24; }
uint32_t minor_v() { return ( v_num & 0x00FF0000 ) >> 16; }
uint32_t rev_v() { return v_num & 0x0000FFFF; }
uint32_t major_v() const { return ( v_num & 0XFF000000 ) >> 24; }
uint32_t minor_v() const { return ( v_num & 0x00FF0000 ) >> 16; }
uint32_t rev_v() const { return v_num & 0x0000FFFF; }
uint32_t v_num = 0;
protected:
enum class operator_type
{
equal,
not_equal,
less,
less_equal,
greater,
greater_equal
};
template< operator_type op_type >
bool _operator( uint32_t val, std::function< uint32_t( uint32_t ) >&& val_call = []( uint32_t val ){ return val; } ) const
{
/*
There is allowed after HF24, that major version can be different from another one.
The old major version always had '0' value, new major version has always `1` value.
Some witnesses can still use nodes before HF24, so loosening restrictions regarding a version is necessary.
*/
auto _val = ( val & 0xFF000000 ) >> 24;
if( major_v() == 0 && _val == 1 )//0.HARDFORK_NUMBER == 1.HARDFORK_NUMBER
val &= 0x00FFFFFF;
else if( major_v() == 1 && _val == 0 )//1.HARDFORK_NUMBER == 0.HARDFORK_NUMBER
val &= 0x01FFFFFF;
if( op_type == operator_type::equal )
return v_num == val_call( val );
else if( op_type == operator_type::not_equal )
return v_num != val_call( val );
else if( op_type == operator_type::less )
return v_num < val_call( val );
else if( op_type == operator_type::less_equal )
return v_num <= val_call( val );
else if( op_type == operator_type::greater )
return v_num > val_call( val );
else if( op_type == operator_type::greater_equal )
return v_num >= val_call( val );
}
};
struct hardfork_version : version
......@@ -42,19 +84,19 @@ struct hardfork_version : version
void operator = ( const version& o ) { v_num = o.v_num & 0xFFFF0000; }
void operator = ( const hardfork_version& o ) { v_num = o.v_num & 0xFFFF0000; }
bool operator == ( const hardfork_version& o )const { return v_num == o.v_num; }
bool operator != ( const hardfork_version& o )const { return v_num != o.v_num; }
bool operator < ( const hardfork_version& o )const { return v_num < o.v_num; }
bool operator <= ( const hardfork_version& o )const { return v_num <= o.v_num; }
bool operator > ( const hardfork_version& o )const { return v_num > o.v_num; }
bool operator >= ( const hardfork_version& o )const { return v_num >= o.v_num; }
bool operator == ( const version& o )const { return v_num == ( o.v_num & 0xFFFF0000 ); }
bool operator != ( const version& o )const { return v_num != ( o.v_num & 0xFFFF0000 ); }
bool operator < ( const version& o )const { return v_num < ( o.v_num & 0xFFFF0000 ); }
bool operator <= ( const version& o )const { return v_num <= ( o.v_num & 0xFFFF0000 ); }
bool operator > ( const version& o )const { return v_num > ( o.v_num & 0xFFFF0000 ); }
bool operator >= ( const version& o )const { return v_num >= ( o.v_num & 0xFFFF0000 ); }
bool operator == ( const hardfork_version& o )const { return _operator< operator_type::equal >( o.v_num ); }
bool operator != ( const hardfork_version& o )const { return _operator< operator_type::not_equal >( o.v_num ); }
bool operator < ( const hardfork_version& o )const { return _operator< operator_type::less >( o.v_num ); }
bool operator <= ( const hardfork_version& o )const { return _operator< operator_type::less_equal >( o.v_num ); }
bool operator > ( const hardfork_version& o )const { return _operator< operator_type::greater >( o.v_num ); }
bool operator >= ( const hardfork_version& o )const { return _operator< operator_type::greater_equal >( o.v_num ); }
bool operator == ( const version& o )const { return _operator< operator_type::equal >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
bool operator != ( const version& o )const { return _operator< operator_type::not_equal >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
bool operator < ( const version& o )const { return _operator< operator_type::less >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
bool operator <= ( const version& o )const { return _operator< operator_type::less_equal >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
bool operator > ( const version& o )const { return _operator< operator_type::greater >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
bool operator >= ( const version& o )const { return _operator< operator_type::greater_equal >( o.v_num, []( uint32_t val ){ return val & 0xFFFF0000; } ); }
};
struct hardfork_version_vote
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment