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

Increment finalizer_policy's generation when set_finalizers is executed. #2388

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion libraries/chain/block_header_state_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace eosio::chain {
}

if (new_finalizer_policy) {
new_finalizer_policy->generation = 1; // only allowed to be set once
assert(new_finalizer_policy->generation == 1); // only allowed to be set once
// set current block_num as qc_claim.last_qc_block_num in the IF extension
qc_claim_t initial_if_claim { .block_num = block_num,
.is_strong_qc = false };
Expand Down
21 changes: 15 additions & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,17 @@ struct building_block {
[&](building_block_if&) -> R { return {}; }}, v);
}

void set_proposed_finalizer_policy(const finalizer_policy& fin_pol) {
std::visit([&](auto& bb) { bb.new_finalizer_policy = fin_pol; }, v);
void set_proposed_finalizer_policy(finalizer_policy&& fin_pol)
{
std::visit(overloaded{ [&](building_block_legacy& bb) {
fin_pol.generation = 1; // only allowed to be set once in legacy mode
bb.new_finalizer_policy = std::move(fin_pol);
},
[&](building_block_if& bb) {
fin_pol.generation = bb.parent.active_finalizer_policy->generation + 1;
bb.new_finalizer_policy = std::move(fin_pol);
} },
v);
}

deque<transaction_metadata_ptr> extract_trx_metas() {
Expand Down Expand Up @@ -3185,10 +3194,10 @@ struct controller_impl {
pending->push();
}

void set_proposed_finalizers(const finalizer_policy& fin_pol) {
void set_proposed_finalizers(finalizer_policy&& fin_pol) {
assert(pending); // has to exist and be building_block since called from host function
auto& bb = std::get<building_block>(pending->_block_stage);
bb.set_proposed_finalizer_policy(fin_pol);
bb.set_proposed_finalizer_policy(std::move(fin_pol));

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
Expand Down Expand Up @@ -5155,8 +5164,8 @@ int64_t controller_impl::set_proposed_producers_legacy( vector<producer_authorit
return version;
}

void controller::set_proposed_finalizers( const finalizer_policy& fin_pol ) {
my->set_proposed_finalizers(fin_pol);
void controller::set_proposed_finalizers( finalizer_policy&& fin_pol ) {
my->set_proposed_finalizers(std::move(fin_pol));
}

// called from net threads
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ namespace eosio::chain {
int64_t set_proposed_producers( vector<producer_authority> producers );

// called by host function set_finalizers
void set_proposed_finalizers( const finalizer_policy& fin_set );
void set_proposed_finalizers( finalizer_policy&& fin_pol );
// called from net threads
vote_status process_vote_message( const vote_message& msg );
// thread safe, for testing
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/webassembly/privileged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace eosio { namespace chain { namespace webassembly {

EOS_ASSERT( weight_sum >= finpol.threshold && finpol.threshold > weight_sum / 2, wasm_execution_error, "Finalizer policy threshold (${t}) must be greater than half of the sum of the weights (${w}), and less than or equal to the sum of the weights", ("t", finpol.threshold)("w", weight_sum) );

context.control.set_proposed_finalizers( finpol );
context.control.set_proposed_finalizers( std::move(finpol) );
}

uint32_t interface::get_blockchain_parameters_packed( legacy_span<char> packed_blockchain_parameters ) const {
Expand Down
Loading