From 14f7b520bd58716d6fa28959474a4e857c67a7e0 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 7 Mar 2016 14:30:09 -0500 Subject: [PATCH] Disable negative voting on workers #607 --- libraries/chain/account_evaluator.cpp | 16 ++++++++++++++++ libraries/chain/db_maint.cpp | 3 ++- libraries/chain/hardfork.d/607.hf | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 libraries/chain/hardfork.d/607.hf diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index b44597e4..eb86764c 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -69,10 +70,25 @@ void verify_account_votes( const database& db, const account_options& options ) "Voted for more committee members than currently allowed (${c})", ("c", chain_params.maximum_committee_count) ); uint32_t max_vote_id = gpo.next_available_vote_id; + bool has_worker_votes = false; for( auto id : options.votes ) { FC_ASSERT( id < max_vote_id ); + has_worker_votes |= (id.type() == vote_id_type::worker); } + + if( has_worker_votes && (db.head_block_time() >= HARDFORK_607_TIME) ) + { + const auto& against_worker_idx = db.get_index_type().indices().get(); + for( auto id : options.votes ) + { + if( id.type() == vote_id_type::worker ) + { + FC_ASSERT( against_worker_idx.find( id ) == against_worker_idx.end() ); + } + } + } + } diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index c7e39d75..709cd583 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -102,11 +102,12 @@ void database::update_worker_votes() { auto& idx = get_index_type(); auto itr = idx.indices().get().begin(); + bool allow_negative_votes = (head_block_time() < HARDFORK_607_TIME); while( itr != idx.indices().get().end() ) { modify( *itr, [&]( worker_object& obj ){ obj.total_votes_for = _vote_tally_buffer[obj.vote_for]; - obj.total_votes_against = _vote_tally_buffer[obj.vote_against]; + obj.total_votes_against = allow_negative_votes ? _vote_tally_buffer[obj.vote_against] : 0; }); ++itr; } diff --git a/libraries/chain/hardfork.d/607.hf b/libraries/chain/hardfork.d/607.hf new file mode 100644 index 00000000..135619c2 --- /dev/null +++ b/libraries/chain/hardfork.d/607.hf @@ -0,0 +1,4 @@ +// #607 Disable negative voting on workers +#ifndef HARDFORK_607_TIME +#define HARDFORK_607_TIME (fc::time_point_sec( 1458061200 )) +#endif