Skip to content

Commit

Permalink
Restore duplicate work check for legacy PoW #256
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Aug 12, 2016
1 parent 35e061a commit 42d0523
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libraries/chain/include/steemit/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace steemit { namespace chain {
fc::uint128 virtual_scheduled_time = fc::uint128::max_value();
///@}

digest_type last_work;

/**
* This field represents the Steem blockchain version the witness is running.
*/
Expand Down Expand Up @@ -132,6 +134,7 @@ namespace steemit { namespace chain {
witness_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_non_unique< tag<by_work>, member<witness_object, digest_type, &witness_object::last_work> >,
ordered_unique< tag<by_name>, member<witness_object, string, &witness_object::owner> >,
ordered_non_unique< tag<by_pow>, member<witness_object, uint64_t, &witness_object::pow_worker> >,
ordered_unique< tag<by_vote_name>,
Expand Down Expand Up @@ -184,6 +187,7 @@ FC_REFLECT_DERIVED( steemit::chain::witness_object, (graphene::db::object),
(last_aslot)(last_confirmed_block_num)(pow_worker)(signing_key)
(props)
(sbd_exchange_rate)(last_sbd_exchange_update)
(last_work)
(running_version)
(hardfork_version_vote)(hardfork_time_vote)
)
Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,16 @@ void pow_apply( database& db, Operation o ) {

FC_ASSERT( db.head_block_time() > STEEMIT_MINING_TIME, "Mining cannot start until ${t}", ("t",STEEMIT_MINING_TIME) );

if( db.is_producing() || db.has_hardfork( STEEMIT_HARDFORK_0_5__59 ) )
{
const auto& witness_by_work = db.get_index_type<witness_index>().indices().get<by_work>();
auto work_itr = witness_by_work.find( o.work.work );
if( work_itr != witness_by_work.end() )
{
FC_ASSERT( !"DUPLICATE WORK DISCOVERED", "${w} ${witness}",("w",o)("wit",*work_itr) );
}
}

if( !db.has_hardfork( STEEMIT_HARDFORK_0_12__179 ) )
FC_ASSERT( o.props.maximum_block_size >= STEEMIT_MIN_BLOCK_SIZE_LIMIT * 2 );

Expand Down Expand Up @@ -1220,6 +1230,7 @@ void pow_apply( database& db, Operation o ) {
db.modify(*cur_witness, [&]( witness_object& w ){
w.props = o.props;
w.pow_worker = dgp.total_pow;
w.last_work = o.work.work;
});
} else {
db.create<witness_object>( [&]( witness_object& w )
Expand All @@ -1228,6 +1239,7 @@ void pow_apply( database& db, Operation o ) {
w.props = o.props;
w.signing_key = o.work.worker;
w.pow_worker = dgp.total_pow;
w.last_work = o.work.work;
});
}
/// POW reward depends upon whether we are before or after MINER_VOTING kicks in
Expand Down

0 comments on commit 42d0523

Please sign in to comment.