Skip to content

Commit

Permalink
Create new hardfork_version_vote struct containing hardfork_version a…
Browse files Browse the repository at this point in the history
…nd time.
  • Loading branch information
Michael Vandeberg committed May 26, 2016
1 parent 6df6ce8 commit f93f33d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
39 changes: 17 additions & 22 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,15 +764,13 @@ signed_block database::_generate_block(

const auto& hfp = hardfork_property_id_type()( *this );

if( STEEMIT_NUM_HARDFORKS > hfp.last_hardfork ) // Binary knows of a new hardfork
if( hfp.last_hardfork < STEEMIT_NUM_HARDFORKS && ( witness.hardfork_version_vote != _hardfork_versions[ hfp.last_hardfork + 1 ] || witness.hardfork_time_vote != _hardfork_times[ hfp.last_hardfork + 1 ] ) ) // Binary knows of a new hardfork
{
pending_block.extensions.insert( future_extensions( _hardfork_versions[ hfp.last_hardfork + 1 ] ) );
pending_block.extensions.insert( future_extensions( _hardfork_times[ hfp.last_hardfork + 1 ] ) );
pending_block.extensions.insert( future_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork + 1 ], _hardfork_times[ hfp.last_hardfork + 1 ] ) ) );
}
else if( witness.hardfork_version_vote > _hardfork_versions[ hfp.last_hardfork ] ) // Don't know about the new hardfork and have previously voted for it
else if( witness.hardfork_version_vote > _hardfork_versions[ hfp.last_hardfork ] || ( hfp.last_hardfork < STEEMIT_NUM_HARDFORKS && witness.hardfork_time_vote != _hardfork_times[ hfp.last_hardfork + 1 ] ) ) // Don't know about the new hardfork and have previously voted for it
{
pending_block.extensions.insert( future_extensions( _hardfork_versions[ hfp.last_hardfork ] ) );
pending_block.extensions.insert( future_extensions( _hardfork_times[ hfp.last_hardfork ] ) );
pending_block.extensions.insert( future_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork + 1 ], _hardfork_times[ hfp.last_hardfork + 1 ] ) ) );
}
}

Expand Down Expand Up @@ -1122,6 +1120,15 @@ void database::update_witness_schedule4()

hf_itr++;
}

// We no longer have a majority
if( hf_itr == hardfork_version_votes.end() )
{
modify( hardfork_property_id_type()( *this ), [&]( hardfork_property_object& hpo )
{
hpo.next_hardfork = hpo.current_hardfork_version;
});
}
}

modify( wso, [&]( witness_schedule_object& _wso )
Expand Down Expand Up @@ -2273,26 +2280,14 @@ void database::process_header_extensions( const signed_block& next_block )
}
case 2: // hardfork_version vote
{
auto hfv = itr->get< hardfork_version >();
const auto& signing_witness = get_witness( next_block.witness );

if( hfv != signing_witness.hardfork_version_vote )
modify( signing_witness, [&]( witness_object& wo )
{
wo.hardfork_version_vote = hfv;
});

break;
}
case 3: // time_point_sec, for voting on hardfork time
{
auto hft = itr->get< time_point_sec >();
auto hfv = itr->get< hardfork_version_vote >();
const auto& signing_witness = get_witness( next_block.witness );

if( hft != signing_witness.hardfork_time_vote )
if( hfv.hf_version != signing_witness.hardfork_version_vote || hfv.hf_time != signing_witness.hardfork_time_vote )
modify( signing_witness, [&]( witness_object& wo )
{
wo.hardfork_time_vote = hft;
wo.hardfork_version_vote = hfv.hf_version;
wo.hardfork_time_vote = hfv.hf_time;
});

break;
Expand Down
5 changes: 2 additions & 3 deletions libraries/chain/include/steemit/chain/protocol/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ namespace steemit { namespace chain {

typedef static_variant<
void_t,
version, // Normal witness version reporting, for diagnostics and voting
hardfork_version, // Voting for the next hardfork to trigger
fc::time_point_sec // Voting for when that hardfork should happen
version, // Normal witness version reporting, for diagnostics and voting
hardfork_version_vote // Voting for the next hardfork to trigger
> future_extensions;
typedef flat_set<future_extensions> extensions_type;

Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/include/steemit/chain/protocol/version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <fc/string.hpp>
#include <fc/time.hpp>

namespace steemit { namespace chain {

Expand Down Expand Up @@ -48,6 +49,15 @@ struct hardfork_version : version
bool operator >= ( const version& o )const { return v_num >= ( o.v_num & 0xFFFF0000 ); }
};

struct hardfork_version_vote
{
hardfork_version_vote() {}
hardfork_version_vote( hardfork_version v, fc::time_point_sec t ):hf_version( v ),hf_time( t ) {}

hardfork_version hf_version;
fc::time_point_sec hf_time;
};

} } // steemit::chain

namespace fc
Expand All @@ -63,3 +73,5 @@ namespace fc
#include <fc/reflect/reflect.hpp>
FC_REFLECT( steemit::chain::version, (v_num) )
FC_REFLECT_DERIVED( steemit::chain::hardfork_version, (steemit::chain::version), )

FC_REFLECT( steemit::chain::hardfork_version_vote, (hf_version)(hf_time) )

0 comments on commit f93f33d

Please sign in to comment.