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

Producer schedule change doesn't seem correct in Savanna mode #256

Closed
greg7mdp opened this issue Jun 7, 2024 · 3 comments
Closed

Producer schedule change doesn't seem correct in Savanna mode #256

greg7mdp opened this issue Jun 7, 2024 · 3 comments
Labels

Comments

@greg7mdp
Copy link
Contributor

greg7mdp commented Jun 7, 2024

Say you have an active schedule with 3 proposers: {"dan"_n,"sam"_n,"pam"_n}

On sam's last block, you change the schedule to: {"dan"_n,"sam"_n,"pam"_n,"cam"_n}

The next 12 blocks are produced by pam as expected.

And then the next block is produced by sam??? I would have expected cam, or dan if the transition hadn't taken place.

Test case reproducing the issue, which fails on the last BOOST_REQUIRE.

#include "fork_test_utilities.hpp"

BOOST_AUTO_TEST_CASE( switch_producers_test_exact ) try {
   tester c;

   c.create_accounts( {"dan"_n,"sam"_n,"pam"_n} );
   c.set_producers( {"dan"_n,"sam"_n,"pam"_n} );

   BOOST_REQUIRE( produce_until_transition( c, "dan"_n, "sam"_n ) );
   c.produce_blocks(35);

   signed_block_ptr b = c.produce_block();
   BOOST_REQUIRE_EQUAL( b->producer.to_string(), "dan"_n.to_string() );

   b = c.produce_block();
   BOOST_REQUIRE_EQUAL( b->producer.to_string(), "sam"_n.to_string() );
   c.produce_blocks(10);
   c.create_accounts( {"cam"_n} );
   c.set_producers( {"dan"_n,"sam"_n,"pam"_n,"cam"_n} );
   c.produce_block();
   BOOST_REQUIRE_EQUAL( b->producer.to_string(), "sam"_n.to_string() );

   // The next 12 blocks should be produced by `pam`.
   for (size_t i=0; i<12; ++i) {
      b = c.produce_block(); // pam produces 12 blocks
      BOOST_REQUIRE_EQUAL( b->producer.to_string(), "pam"_n.to_string() );
   }

   // after `pam`, we should have either `dan` or `cam` (I think `cam`), but we get `sam`???
   b = c.produce_block();
   BOOST_REQUIRE_EQUAL( b->producer.to_string(), "sam"_n.to_string() ); // should fail I think!
   BOOST_REQUIRE( b->producer == "dam"_n || b->producer == "cam"_n);

} FC_LOG_AND_RETHROW()
@heifner
Copy link
Member

heifner commented Jun 7, 2024

This is because you have changed the size of the producers. If you used the same number or producers when updating you would see more what you expect. The schedule is a modulus of the producers, so changing the size creates a different index into the schedule according to the time slot.

See.

inline const producer_authority& get_scheduled_producer(const vector<producer_authority>& producers, block_timestamp_type t) {
auto index = t.slot % (producers.size() * config::producer_repetitions);
index /= config::producer_repetitions;
return producers[index];
}

@greg7mdp
Copy link
Contributor Author

greg7mdp commented Jun 7, 2024

That explains it, thanks Kevin!

@greg7mdp
Copy link
Contributor Author

greg7mdp commented Jun 7, 2024

Not an issue

@greg7mdp greg7mdp closed this as completed Jun 7, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Team Backlog Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

3 participants