Skip to content

Commit

Permalink
Merge pull request #2357 from AntelopeIO/GH-2057-producer-schedule
Browse files Browse the repository at this point in the history
IF: Ignore proposed producers during transition
  • Loading branch information
heifner authored Mar 29, 2024
2 parents 70fb9a9 + e384b43 commit 57bf131
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,10 @@ struct building_block {
R apply_l(F&& f) {
if constexpr (std::is_same_v<void, R>)
std::visit(overloaded{[&](building_block_legacy& bb) { std::forward<F>(f)(bb); },
[&](building_block_if& bb) {}}, v);
[&](building_block_if&) {}}, v);
else
return std::visit(overloaded{[&](building_block_legacy& bb) -> R { return std::forward<F>(f)(bb); },
[&](building_block_if& bb) -> R { return {}; }}, v);
[&](building_block_if&) -> R { return {}; }}, v);
}

void set_proposed_finalizer_policy(const finalizer_policy& fin_pol) {
Expand Down Expand Up @@ -3195,7 +3195,7 @@ struct controller_impl {
auto& bb = std::get<building_block>(pending->_block_stage);
bb.set_proposed_finalizer_policy(fin_pol);

apply_l<void>(chain_head, [&](auto&) {
bb.apply_l<void>([&](building_block::building_block_legacy& bl) {
// Savanna uses new algorithm for proposer schedule change, prevent any in-flight legacy proposer schedule changes
const auto& gpo = db.get<global_property_object>();
if (gpo.proposed_schedule_block_num) {
Expand All @@ -3205,6 +3205,8 @@ struct controller_impl {
gp.proposed_schedule.producers.clear();
});
}
bl.new_pending_producer_schedule = {};
bl.pending_block_header_state.prev_pending_schedule.schedule.producers.clear();
});
}

Expand Down Expand Up @@ -5046,6 +5048,15 @@ int64_t controller_impl::set_proposed_producers_legacy( vector<producer_authorit
if( std::equal( producers.begin(), producers.end(), begin, end ) )
return -1; // the producer schedule would not change

// ignore proposed producers during transition
assert(pending);
auto& bb = std::get<building_block>(pending->_block_stage);
bool transition_block = bb.apply_l<bool>([](building_block::building_block_legacy& bl) {
return bl.pending_block_header_state.is_if_transition_block() || bl.new_finalizer_policy;
});
if (transition_block)
return -1;

sch.producers = std::move(producers);

int64_t version = sch.version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct pending_block_header_state_legacy : public detail::block_header_state_leg
uint16_t confirmed = 1;
std::optional<qc_claim_t> qc_claim; // transition to savanna has begun

bool is_if_transition_block() const { return !!qc_claim; }

signed_block_header make_block_header( const checksum256_type& transaction_mroot,
const checksum256_type& action_mroot,
const std::optional<producer_authority_schedule>& new_producers,
Expand Down
1 change: 1 addition & 0 deletions unittests/producer_schedule_if_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat
auto setfin_block = produce_block(); // this block contains the header extension of the finalizer set

for (block_num_type active_block_num = setfin_block->block_num(); active_block_num > lib; produce_block()) {
set_producers({"initc"_n, "inite"_n}); // should be ignored since in transition
(void)active_block_num; // avoid warning
};

Expand Down

0 comments on commit 57bf131

Please sign in to comment.