|
7 | 7 | #include <eosio/singleton.hpp> |
8 | 8 | #include <eosio/system.hpp> |
9 | 9 | #include <eosio/time.hpp> |
| 10 | +#include <eosio/instant_finality.hpp> |
10 | 11 |
|
11 | 12 | #include <eosio.system/exchange_state.hpp> |
12 | 13 | #include <eosio.system/native.hpp> |
@@ -427,6 +428,75 @@ namespace eosiosystem { |
427 | 428 | EOSLIB_SERIALIZE( producer_info2, (owner)(votepay_share)(last_votepay_share_update) ) |
428 | 429 | }; |
429 | 430 |
|
| 431 | + // finalizer_key_info stores information about a finalizer key. |
| 432 | + struct [[eosio::table("finkeys"), eosio::contract("eosio.system")]] finalizer_key_info { |
| 433 | + uint64_t id; // automatically generated ID for the key in the table |
| 434 | + name finalizer_name; // name of the finalizer owning the key |
| 435 | + std::string finalizer_key; // finalizer key in base64url format |
| 436 | + std::vector<char> finalizer_key_binary; // finalizer key in binary format in Affine little endian non-montgomery g1 |
| 437 | + |
| 438 | + uint64_t primary_key() const { return id; } |
| 439 | + uint64_t by_fin_name() const { return finalizer_name.value; } |
| 440 | + eosio::checksum256 by_fin_key() const { return eosio::sha256(finalizer_key_binary.data(), finalizer_key_binary.size()); } |
| 441 | + |
| 442 | + bool is_active(uint64_t finalizer_active_key_id) const { return id == finalizer_active_key_id; } |
| 443 | + }; |
| 444 | + |
| 445 | + typedef eosio::multi_index< |
| 446 | + "finkeys"_n, finalizer_key_info, |
| 447 | + indexed_by<"byfinname"_n, const_mem_fun<finalizer_key_info, uint64_t, &finalizer_key_info::by_fin_name>>, |
| 448 | + indexed_by<"byfinkey"_n, const_mem_fun<finalizer_key_info, eosio::checksum256, &finalizer_key_info::by_fin_key>> |
| 449 | + > finalizer_keys_table; |
| 450 | + |
| 451 | + // finalizer_info stores information about a finalizer. |
| 452 | + struct [[eosio::table("finalizers"), eosio::contract("eosio.system")]] finalizer_info { |
| 453 | + name finalizer_name; // finalizer's name |
| 454 | + uint64_t active_key_id; // finalizer's active finalizer key's id in finalizer_keys_table |
| 455 | + std::vector<char> active_key_binary; // active finalizer key in binary format |
| 456 | + uint32_t finalizer_key_count = 0; // number of finalizer keys registered by this finalizer |
| 457 | + |
| 458 | + uint64_t primary_key() const { return finalizer_name.value; } |
| 459 | + }; |
| 460 | + |
| 461 | + typedef eosio::multi_index< "finalizers"_n, finalizer_info > finalizers_table; |
| 462 | + |
| 463 | + // finalizer_auth_info stores a finalizer's key id and its finalizer authority. |
| 464 | + struct finalizer_auth_info { |
| 465 | + finalizer_auth_info() = default; |
| 466 | + explicit finalizer_auth_info(const finalizer_info& finalizer); |
| 467 | + |
| 468 | + uint64_t key_id; |
| 469 | + eosio::finalizer_authority fin_authority; |
| 470 | + |
| 471 | + bool operator==(const finalizer_auth_info& other) const { |
| 472 | + return key_id == other.key_id && |
| 473 | + fin_authority.public_key == other.fin_authority.public_key; |
| 474 | + } |
| 475 | + |
| 476 | + EOSLIB_SERIALIZE( finalizer_auth_info, (key_id)(fin_authority) ) |
| 477 | + }; |
| 478 | + |
| 479 | + // A single entry storing information about last proposed finalizers. |
| 480 | + struct [[eosio::table("lastpropfins"), eosio::contract("eosio.system")]] last_prop_finalizers_info { |
| 481 | + std::vector<finalizer_auth_info> last_proposed_finalizers; // sorted by ascending finalizer key id |
| 482 | + |
| 483 | + uint64_t primary_key() const { return 0; } |
| 484 | + |
| 485 | + EOSLIB_SERIALIZE( last_prop_finalizers_info, (last_proposed_finalizers) ) |
| 486 | + }; |
| 487 | + |
| 488 | + typedef eosio::multi_index< "lastpropfins"_n, last_prop_finalizers_info > last_prop_fins_table; |
| 489 | + |
| 490 | + // A single entry storing next available finalizer key_id so IDs are never reused. |
| 491 | + struct [[eosio::table("finkeyidgen"), eosio::contract("eosio.system")]] fin_key_id_generator_info { |
| 492 | + uint64_t next_finalizer_key_id = 0; |
| 493 | + uint64_t primary_key() const { return 0; } |
| 494 | + |
| 495 | + EOSLIB_SERIALIZE( fin_key_id_generator_info, (next_finalizer_key_id) ) |
| 496 | + }; |
| 497 | + |
| 498 | + typedef eosio::multi_index< "finkeyidgen"_n, fin_key_id_generator_info > fin_key_id_gen_table; |
| 499 | + |
430 | 500 | // Voter info. Voter info stores information about the voter: |
431 | 501 | // - `owner` the voter |
432 | 502 | // - `proxy` the proxy set by the voter, if any |
@@ -903,6 +973,11 @@ namespace eosiosystem { |
903 | 973 | voters_table _voters; |
904 | 974 | producers_table _producers; |
905 | 975 | producers_table2 _producers2; |
| 976 | + finalizer_keys_table _finalizer_keys; |
| 977 | + finalizers_table _finalizers; |
| 978 | + last_prop_fins_table _last_prop_finalizers; |
| 979 | + std::optional<std::vector<finalizer_auth_info>> _last_prop_finalizers_cached; |
| 980 | + fin_key_id_gen_table _fin_key_id_generator; |
906 | 981 | global_state_singleton _global; |
907 | 982 | global_state2_singleton _global2; |
908 | 983 | global_state3_singleton _global3; |
@@ -1411,10 +1486,47 @@ namespace eosiosystem { |
1411 | 1486 | * |
1412 | 1487 | * Deactivate the block producer with account name `producer`. |
1413 | 1488 | * @param producer - the block producer account to unregister. |
1414 | | - */ |
| 1489 | + */ |
1415 | 1490 | [[eosio::action]] |
1416 | 1491 | void unregprod( const name& producer ); |
1417 | 1492 |
|
| 1493 | + /** |
| 1494 | + * Permanently transition to Savanna consensus by establishing the first finalizer policy. |
| 1495 | + * |
| 1496 | + * @pre Requires authority of the system contract. |
| 1497 | + * @pre The current Telos producer schedule must have active finalizer keys. |
| 1498 | + */ |
| 1499 | + [[eosio::action]] |
| 1500 | + void switchtosvnn(); |
| 1501 | + |
| 1502 | + /** |
| 1503 | + * Register a BLS finalizer key for a registered producer. |
| 1504 | + * |
| 1505 | + * @param finalizer_name - producer account registering the finalizer key. |
| 1506 | + * @param finalizer_key - public finalizer key in base64url format. |
| 1507 | + * @param proof_of_possession - proof of possession signature in base64url format. |
| 1508 | + */ |
| 1509 | + [[eosio::action]] |
| 1510 | + void regfinkey( const name& finalizer_name, const std::string& finalizer_key, const std::string& proof_of_possession ); |
| 1511 | + |
| 1512 | + /** |
| 1513 | + * Activate a registered finalizer key. |
| 1514 | + * |
| 1515 | + * @param finalizer_name - producer account activating the finalizer key. |
| 1516 | + * @param finalizer_key - registered public finalizer key. |
| 1517 | + */ |
| 1518 | + [[eosio::action]] |
| 1519 | + void actfinkey( const name& finalizer_name, const std::string& finalizer_key ); |
| 1520 | + |
| 1521 | + /** |
| 1522 | + * Delete a registered finalizer key. |
| 1523 | + * |
| 1524 | + * @param finalizer_name - producer account deleting the finalizer key. |
| 1525 | + * @param finalizer_key - registered public finalizer key. |
| 1526 | + */ |
| 1527 | + [[eosio::action]] |
| 1528 | + void delfinkey( const name& finalizer_name, const std::string& finalizer_key ); |
| 1529 | + |
1418 | 1530 | /** |
1419 | 1531 | * Set ram action sets the ram supply. |
1420 | 1532 | * @param max_ram_size - the amount of ram supply to set. |
@@ -1786,14 +1898,25 @@ namespace eosiosystem { |
1786 | 1898 | // defined in voting.cpp |
1787 | 1899 | void register_producer( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location ); |
1788 | 1900 | void update_elected_producers( const block_timestamp& timestamp ); |
1789 | | - void update_votes( const name& voter, const name& proxy, const std::vector<name>& producers, bool voting ); |
| 1901 | + void update_votes( const name& voter, const name& proxy, const std::vector<name>& producers, bool voting, bool recalculating = false ); |
1790 | 1902 | void propagate_weight_change( const voter_info& voter ); |
1791 | 1903 | double update_producer_votepay_share( const producers_table2::const_iterator& prod_itr, |
1792 | | - const time_point& ct, |
1793 | | - double shares_rate, bool reset_to_zero = false ); |
| 1904 | + const time_point& ct, |
| 1905 | + double shares_rate, bool reset_to_zero = false ); |
1794 | 1906 | double update_total_votepay_share( const time_point& ct, |
1795 | 1907 | double additional_shares_delta = 0.0, double shares_rate_delta = 0.0 ); |
1796 | 1908 |
|
| 1909 | + // defined in finalizer_key.cpp |
| 1910 | + bool is_savanna_consensus(); |
| 1911 | + bool has_active_finalizer_key( const name& producer ) const; |
| 1912 | + void set_proposed_finalizers( std::vector<finalizer_auth_info> finalizers ); |
| 1913 | + const std::vector<finalizer_auth_info>& get_last_proposed_finalizers(); |
| 1914 | + uint64_t get_next_finalizer_key_id(); |
| 1915 | + finalizers_table::const_iterator get_finalizer_itr( const name& finalizer_name ) const; |
| 1916 | + std::vector<finalizer_auth_info> get_finalizers_for_producers( const std::vector<producer_location_pair>& producers ) const; |
| 1917 | + bool active_schedule_matches_last_scheduled_producers( const std::vector<name>& active_schedule ) const; |
| 1918 | + std::vector<producer_location_pair> get_last_scheduled_producers() const; |
| 1919 | + |
1797 | 1920 | template <auto system_contract::*...Ptrs> |
1798 | 1921 | class registration { |
1799 | 1922 | public: |
|
0 commit comments