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

Require two consecutive successful productions when counting witnesses for LIB #2473

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
48 changes: 31 additions & 17 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3402,21 +3402,30 @@ void database::update_global_dynamic_data( const signed_block& b )
for( uint32_t i = 0; i < missed_blocks; ++i )
{
const auto& witness_missed = get_witness( get_scheduled_witness( i + 1 ) );
if( witness_missed.owner != b.witness )

modify( witness_missed, [&]( witness_object& w )
{
modify( witness_missed, [&]( witness_object& w )
w.current_run = 0;
if( witness_missed.owner != b.witness )
{
//
// total_missed does not increment when witness_missed.owner == b.witness
// because a low total_missed is a "prestige" item and a witness that
// restarts a dead network is "rewarded" by not having total_missed
// increase for any blocks they missed in the gap.
// Also, this prevents initminer from having a large total_missed.
//

w.total_missed++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped in the if( witness_missed.owner != b.witness ) conditional to preserve existing behavior.

if( has_hardfork( STEEM_HARDFORK_0_14__278 ) )
if( (_dgp.head_block_number - w.last_confirmed_block_num > STEEM_BLOCKS_PER_DAY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace

&& has_hardfork( STEEM_HARDFORK_0_14__278 )
)
{
if( head_block_num() - w.last_confirmed_block_num > STEEM_BLOCKS_PER_DAY )
{
w.signing_key = public_key_type();
push_virtual_operation( shutdown_witness_operation( w.owner ) );
}
w.signing_key = public_key_type();
push_virtual_operation( shutdown_witness_operation( w.owner ) );
}
} );
}
}
} );
}
}

Expand Down Expand Up @@ -3482,6 +3491,9 @@ void database::update_signing_witness(const witness_object& signing_witness, con
{
_wit.last_aslot = new_block_aslot;
_wit.last_confirmed_block_num = new_block.block_num();
if( _wit.current_run >= STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN )
_wit.last_supported_block_num = _wit.last_confirmed_block_num;
_wit.current_run++;
} );
} FC_CAPTURE_AND_RETHROW() }

Expand All @@ -3494,13 +3506,15 @@ void database::update_last_irreversible_block()
* Prior to voting taking over, we must be more conservative...
*
*/
if( head_block_num() < STEEM_START_MINER_VOTING_BLOCK )
if( dpo.head_block_number < STEEM_START_MINER_VOTING_BLOCK )
{
modify( dpo, [&]( dynamic_global_property_object& _dpo )
if ( dpo.head_block_number > STEEM_MAX_WITNESSES )
{
if ( head_block_num() > STEEM_MAX_WITNESSES )
_dpo.last_irreversible_block_num = head_block_num() - STEEM_MAX_WITNESSES;
} );
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.last_irreversible_block_num = _dpo.head_block_number - STEEM_MAX_WITNESSES;
} );
}
}
else
{
Expand All @@ -3522,10 +3536,10 @@ void database::update_last_irreversible_block()
std::nth_element( wit_objs.begin(), wit_objs.begin() + offset, wit_objs.end(),
[]( const witness_object* a, const witness_object* b )
{
return a->last_confirmed_block_num < b->last_confirmed_block_num;
return a->last_supported_block_num < b->last_supported_block_num;
} );

uint32_t new_last_irreversible_block_num = wit_objs[offset]->last_confirmed_block_num;
uint32_t new_last_irreversible_block_num = wit_objs[offset]->last_supported_block_num;

if( new_last_irreversible_block_num > dpo.last_irreversible_block_num )
{
Expand Down
7 changes: 6 additions & 1 deletion libraries/chain/include/steem/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace steem { namespace chain {
uint32_t total_missed = 0;
uint64_t last_aslot = 0;
uint64_t last_confirmed_block_num = 0;
/** Number of blocks produced since beginning of time or last missed block */
uint64_t current_run = 0;
/** Last block produced when current_run >= STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN */
uint64_t last_supported_block_num = 0;

/**
* Some witnesses have the job because they did a proof of work,
Expand Down Expand Up @@ -272,7 +276,8 @@ FC_REFLECT( steem::chain::witness_object,
(owner)
(created)
(url)(votes)(schedule)(virtual_last_update)(virtual_position)(virtual_scheduled_time)(total_missed)
(last_aslot)(last_confirmed_block_num)(pow_worker)(signing_key)
(last_aslot)(last_confirmed_block_num)(current_run)(last_supported_block_num)
(pow_worker)(signing_key)
(props)
(sbd_exchange_rate)(last_sbd_exchange_update)
(last_work)
Expand Down
1 change: 1 addition & 0 deletions libraries/protocol/get_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fc::variant_object get_config()
#endif
result["STEEM_INIT_SUPPLY"] = STEEM_INIT_SUPPLY;
result["STEEM_INIT_TIME"] = STEEM_INIT_TIME;
result["STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN"] = STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN;
result["STEEM_IRREVERSIBLE_THRESHOLD"] = STEEM_IRREVERSIBLE_THRESHOLD;
result["STEEM_LIQUIDITY_APR_PERCENT"] = STEEM_LIQUIDITY_APR_PERCENT;
result["STEEM_LIQUIDITY_REWARD_BLOCKS"] = STEEM_LIQUIDITY_REWARD_BLOCKS;
Expand Down
2 changes: 2 additions & 0 deletions libraries/protocol/include/steem/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
#define STEEM_MAX_URL_LENGTH 127

#define STEEM_IRREVERSIBLE_THRESHOLD (75 * STEEM_1_PERCENT)
/** Irreversibility only counts blocks produced if wit.current_run >= STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN */
#define STEEM_IRREVERSIBLE_SUPPORT_MIN_RUN 2

#define STEEM_VIRTUAL_SCHEDULE_LAP_LENGTH ( fc::uint128(uint64_t(-1)) )
#define STEEM_VIRTUAL_SCHEDULE_LAP_LENGTH2 ( fc::uint128::max_value() )
Expand Down