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

Max witness #34

Open
wants to merge 3 commits into
base: master
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
28 changes: 26 additions & 2 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2505,16 +2505,38 @@ void database::update_last_irreversible_block()
wit_objs.reserve( wso.num_scheduled_witnesses );
for( int i = 0; i < wso.num_scheduled_witnesses; i++ )
wit_objs.push_back( &get_witness( wso.current_shuffled_witnesses[i] ) );

if (head_block_num() > 27654722)
{
static_assert( SMOKE_IRREVERSIBLE_THRESHOLD_0_1 > 0, "irreversible threshold must be nonzero" );
size_t offset = ((SMOKE_100_PERCENT - SMOKE_IRREVERSIBLE_THRESHOLD_0_1) * wit_objs.size() / SMOKE_100_PERCENT);
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;
} );

uint32_t new_last_irreversible_block_num = wit_objs[offset]->last_confirmed_block_num;

if( new_last_irreversible_block_num > dpo.last_irreversible_block_num )
{
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.last_irreversible_block_num = new_last_irreversible_block_num;
} );
}
}
else
{

static_assert( SMOKE_IRREVERSIBLE_THRESHOLD > 0, "irreversible threshold must be nonzero" );

// 1 1 1 2 2 2 2 2 2 2 -> 2 .7*10 = 7
// 1 1 1 1 1 1 1 2 2 2 -> 1
// 3 3 3 3 3 3 3 3 3 3 -> 3

size_t offset = ((SMOKE_100_PERCENT - SMOKE_IRREVERSIBLE_THRESHOLD) * wit_objs.size() / SMOKE_100_PERCENT);

std::nth_element( wit_objs.begin(), wit_objs.begin() + offset, wit_objs.end(),
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;
Expand All @@ -2529,6 +2551,8 @@ void database::update_last_irreversible_block()
_dpo.last_irreversible_block_num = new_last_irreversible_block_num;
} );
}
}

}

commit( dpo.last_irreversible_block_num );
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/witness_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void update_witness_schedule4( database& db )
}

size_t expected_active_witnesses = std::min( size_t(SMOKE_MAX_WITNESSES), widx.size() );
if (db.head_block_num() > 12000000) {
if (db.head_block_num() > 52000000) {
FC_ASSERT( active_witnesses.size() == expected_active_witnesses, "number of active witnesses does not equal expected_active_witnesses=${expected_active_witnesses}",
("active_witnesses.size()",active_witnesses.size()) ("SMOKE_MAX_WITNESSES",SMOKE_MAX_WITNESSES) ("expected_active_witnesses", expected_active_witnesses) );
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/protocol/include/smoke/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
#define SMOKE_MIN_TRANSACTION_EXPIRATION_LIMIT (SMOKE_BLOCK_INTERVAL * 5) // 5 transactions per block

#define SMOKE_IRREVERSIBLE_THRESHOLD (75 * SMOKE_1_PERCENT)

#define SMOKE_IRREVERSIBLE_THRESHOLD_0_1 (40 * SMOKE_1_PERCENT)
#define VIRTUAL_SCHEDULE_LAP_LENGTH ( fc::uint128::max_value() )

/**
Expand Down