-
Notifications
You must be signed in to change notification settings - Fork 33
IF: Update new proposer policy algorithm #74
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c4bbe57
GH-6 Fix issue with setting proposed proposer schedule more than once…
heifner 4c0ff25
GH-6 Add comment
heifner 528490f
Merge remote-tracking branch 'spring/main' into GH-6-proposer-policy-2
heifner 5adf5f0
GH-6 Additional fixes and test cases
heifner 51d4488
GH-6 Update comment
heifner 7e10458
GH-6 Update logic to increment version on every new proposal schedule…
heifner 5c310b5
GH-6 Update tests for new version change scheme
heifner 887b057
GH-6 Revert back to flat_map for simpler and not storing unneeded imp…
heifner af51f07
Merge remote-tracking branch 'spring/main' into GH-6-proposer-policy-2
heifner ce2cb2e
GH-6 Simplify by doing diff during assemble_block
heifner 091ea81
GH-6 Use optional instead of tuple
heifner 2778bf7
Merge branch 'main' into GH-6-proposer-policy-2
heifner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -491,38 +491,27 @@ struct building_block { | |
|
|
||
| uint32_t get_block_num() const { return block_num; } | ||
|
|
||
| // returns the next proposer schedule version and true if different | ||
| // returns the next proposer schedule version and true if producers should be proposed in block | ||
| // if producers is not different then returns the current schedule version (or next schedule version) | ||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const vector<producer_authority>& producers) const { | ||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const shared_vector<shared_producer_authority>& producers) const { | ||
| assert(active_proposer_policy); | ||
|
|
||
| auto get_next_sched = [&]() -> const producer_authority_schedule& { | ||
| // if there are any policies already proposed but not active yet then they are what needs to be compared | ||
| if (!parent.proposer_policies.empty()) { | ||
| block_timestamp_type active_time = detail::get_next_next_round_block_time(timestamp); | ||
| if (auto itr = parent.proposer_policies.find(active_time); itr != parent.proposer_policies.cend()) { | ||
| // Same active time, a new proposer schedule will replace this entry, `next` therefore is the previous | ||
| if (itr != parent.proposer_policies.begin()) { | ||
| return (--itr)->second->proposer_schedule; | ||
| } | ||
| // no previous to what will be replaced, use active | ||
| return active_proposer_policy->proposer_schedule; | ||
| } | ||
| // will not replace any proposed policies, use next to become active | ||
| return parent.proposer_policies.begin()->second->proposer_schedule; | ||
| if (!parent.proposer_policies.empty()) { // proposed in-flight | ||
| // return the last proposed policy to use for comparison | ||
| return (--parent.proposer_policies.end())->second->proposer_schedule; | ||
greg7mdp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // none currently in-flight, use active | ||
| return active_proposer_policy->proposer_schedule; | ||
| }; | ||
|
|
||
| const producer_authority_schedule& lhs = get_next_sched(); | ||
|
|
||
| if (std::ranges::equal(lhs.producers, producers)) { | ||
| return {lhs.version, false}; | ||
| auto v = lhs.version; | ||
| if (!std::equal(lhs.producers.begin(), lhs.producers.end(), producers.begin(), producers.end())) { | ||
| ++v; | ||
| return {v, true}; | ||
| } | ||
|
|
||
| return {lhs.version + 1, true}; | ||
| return {v, false}; | ||
| } | ||
|
|
||
| }; | ||
|
|
@@ -613,7 +602,7 @@ struct building_block { | |
| v); | ||
| } | ||
|
|
||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const vector<producer_authority>& producers) const { | ||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const shared_vector<shared_producer_authority>& producers) const { | ||
| return std::visit( | ||
| overloaded{[](const building_block_legacy&) -> std::tuple<uint32_t, bool> { return {-1, false}; }, | ||
| [&](const building_block_if& bb) -> std::tuple<uint32_t, bool> { | ||
|
|
@@ -911,7 +900,7 @@ struct pending_state { | |
| _block_stage); | ||
| } | ||
|
|
||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const vector<producer_authority>& producers) const { | ||
| std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const shared_vector<shared_producer_authority>& producers) const { | ||
| return std::visit(overloaded{ | ||
| [&](const building_block& stage) -> std::tuple<uint32_t, bool> { | ||
| return stage.get_next_proposer_schedule_version(producers); | ||
|
|
@@ -3146,10 +3135,16 @@ struct controller_impl { | |
| auto process_new_proposer_policy = [&](auto&) -> void { | ||
| const auto& gpo = db.get<global_property_object>(); | ||
| if (gpo.proposed_schedule_block_num) { | ||
| new_proposer_policy = std::make_unique<proposer_policy>(); | ||
| new_proposer_policy->active_time = detail::get_next_next_round_block_time(bb.timestamp()); | ||
| new_proposer_policy->proposer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); | ||
| ilog("Scheduling proposer schedule change at ${t}: ${s}", ("t", new_proposer_policy->active_time)("s", new_proposer_policy->proposer_schedule)); | ||
|
|
||
| auto [version, should_propose] = pending->get_next_proposer_schedule_version(gpo.proposed_schedule.producers); | ||
| if (should_propose) { | ||
| new_proposer_policy = std::make_unique<proposer_policy>(); | ||
| new_proposer_policy->active_time = detail::get_next_next_round_block_time(bb.timestamp()); | ||
| new_proposer_policy->proposer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); | ||
| new_proposer_policy->proposer_schedule.version = version; | ||
| ilog("Scheduling proposer schedule change at ${t}: ${s}", | ||
| ("t", new_proposer_policy->active_time)("s", new_proposer_policy->proposer_schedule)); | ||
| } | ||
|
||
|
|
||
| db.modify( gpo, [&]( auto& gp ) { | ||
| gp.proposed_schedule_block_num = std::optional<block_num_type>(); | ||
|
|
@@ -5232,25 +5227,19 @@ int64_t controller_impl::set_proposed_producers( vector<producer_authority> prod | |
|
|
||
| assert(pending); | ||
|
|
||
| auto [version, diff] = pending->get_next_proposer_schedule_version(producers); | ||
| if (!diff) | ||
| return version; | ||
|
|
||
| producer_authority_schedule sch; | ||
| sch.version = version; | ||
| // sch.version is set in assemble_block | ||
| sch.producers = std::move(producers); | ||
|
|
||
| ilog( "proposed producer schedule with version ${v}", ("v", sch.version) ); | ||
|
|
||
| // overwrite any existing proposed_schedule set earlier in this block | ||
| // store schedule in gpo so it will be rolledback if transaction fails | ||
| auto cur_block_num = chain_head.block_num() + 1; | ||
| auto& gpo = db.get<global_property_object>(); | ||
| db.modify( gpo, [&]( auto& gp ) { | ||
| gp.proposed_schedule_block_num = cur_block_num; | ||
| gp.proposed_schedule = sch; | ||
| }); | ||
|
|
||
| return sch.version; | ||
| return std::numeric_limits<uint32_t>::max(); | ||
| } | ||
|
|
||
| int64_t controller_impl::set_proposed_producers_legacy( vector<producer_authority> producers ) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could return
std::optional<uint32_t>, i.e. return a new version if one is needed.