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

Internal wiring of finalizers in qc chain #1615

Closed
wants to merge 191 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
402fad5
Added narrow interface bls-signatures
systemzax Nov 7, 2022
50fb0f9
Initial hotstuff related structures
systemzax Nov 11, 2022
bda4ff3
Instant Finality Prototype
systemzax Dec 23, 2022
43ff8ea
Implemented chained hotstuff core logic
systemzax Dec 30, 2022
960415b
Implemented chained hotstuff core logic
systemzax Dec 30, 2022
bc5957c
Added pseudo code file
systemzax Dec 30, 2022
a0007c2
Updated process_propsal to verify block height
systemzax Dec 31, 2022
5925d0a
Updated pseudo code
systemzax Dec 31, 2022
41c99da
Event driven hotstuff core functionalities
systemzax Mar 8, 2023
0deeba7
Re-engineered hotstuff as a library
systemzax Mar 9, 2023
35c1cff
Refactor for easier unit testing
systemzax Mar 16, 2023
176ac1e
Refactor for easier unit testing
systemzax Mar 16, 2023
8d38b09
Refactor to extract liveness component and work on unit tests
systemzax Mar 24, 2023
d0e907a
Fixed scope issue in unit tests
systemzax Mar 24, 2023
ffd1d1f
Fixed scope issue in unit tests
systemzax Mar 24, 2023
5fe630d
Added more unit tests
systemzax Mar 28, 2023
14ba4b1
Completed finality violation unit test, improved logging
systemzax Apr 1, 2023
9c1be07
Misc changes
systemzax Apr 4, 2023
606a9e0
merged feature/hotstuff 91cbe07 from systemzax/leap into leap 4 dev a…
fcecin Apr 5, 2023
bdfd95e
light formatting
fcecin Apr 12, 2023
5517d4b
starting refactor
fcecin Apr 13, 2023
f55f0eb
update hotstuff netcode, revert quorum_certificate FC_REFLECT change
fcecin Apr 14, 2023
0b6933e
hscore profiler; _b_leaf send_proposal fix
fcecin Apr 19, 2023
f3409f3
IF proto version; fix localhost send vote msg; hs-core optimizations
fcecin Apr 20, 2023
a5f632f
Hotstuff refactor batch 1
fcecin Apr 29, 2023
b6cd0ca
Removing hardcoded check for 'eosio' producer name.
fcecin May 1, 2023
14a5b13
hotstuff get_state(); v1/chain/get_finalizer_state API
fcecin May 2, 2023
82e0cf1
cleos get finalizer_state; get_finalizer_state result key-name changes
fcecin May 3, 2023
c63979f
separate leader and proposer (WIP)
fcecin May 4, 2023
48826a3
Fixed networked leader/proposer separation tester; qc_chain trace log…
fcecin May 7, 2023
005d500
added instant_finality protocol-feature switch
fcecin May 8, 2023
e9cd524
Merge remote-tracking branch 'origin/main' into hotstuff_integration_…
heifner Aug 17, 2023
53f697d
Fix merge issues
heifner Aug 18, 2023
5e67e26
Switch to bls12_381 library
heifner Aug 18, 2023
129e62a
Remove bls-signatures subdirectory
heifner Aug 18, 2023
57be9e8
Remove bls-signatures subdirectory
heifner Aug 18, 2023
0c1a5ad
Move test_sig_single to the test that uses it
heifner Aug 18, 2023
2a949ba
Fix aggregate of signatures
heifner Aug 18, 2023
8f1f3f1
Fix memory leak in generate()
heifner Aug 18, 2023
6bb77ba
Uncomment serialization now that it is implemented
heifner Aug 18, 2023
e853e34
bls_private_key cleanup
heifner Aug 18, 2023
064c5e5
Fix warnings
heifner Aug 18, 2023
829f956
Attempt to fix libtester
heifner Aug 18, 2023
5df30b6
Add virtual destructor to remove warning
heifner Aug 18, 2023
48ec519
Remove aggregate_signatures protocol feature and host functions. Repl…
heifner Aug 18, 2023
9873720
Move chain_pacemaker from producer_plugin to chain_plugin.
heifner Aug 18, 2023
7c0e647
Remove unneeded default constructors
heifner Aug 18, 2023
54c9c60
Removed commented out include
heifner Aug 18, 2023
6ded0f3
Regenerate deep-mind log for new instant_finality protocol feature
heifner Aug 18, 2023
3b78eb9
GH-1533 Remove failing test since scheduled to be fixed by GH-1531
heifner Aug 18, 2023
c778050
Minor cleanup
heifner Aug 18, 2023
776e265
Merge pull request #1534 from AntelopeIO/GH-1533-deep-mind
heifner Aug 18, 2023
5655681
Merge pull request #1527 from AntelopeIO/hotstuff_integration_main
heifner Aug 18, 2023
ca123d9
Merge remote-tracking branch 'origin/main' into hs_main
heifner Aug 19, 2023
91fe09d
Merge pull request #1537 from AntelopeIO/hs_main
heifner Aug 19, 2023
2cfd42c
Clean up of bls_private_key, bls_public_key and bls_signature, remove…
systemzax Aug 21, 2023
4b373a0
Added wif import / export + checksum based on the fc::private_key model
systemzax Aug 21, 2023
23d049d
remove cout statements
systemzax Aug 21, 2023
8351034
Quick cleanups
heifner Aug 21, 2023
2315323
Merge pull request #1539 from AntelopeIO/hotstuff_cleanup
heifner Aug 22, 2023
a3a372a
Fix threading 1/2 (#1541) & qc_chain private:
fcecin Aug 23, 2023
479f0c9
Atomic version counter, cleanup & clarity
fcecin Aug 23, 2023
d4b3e3e
fix const type& arg
fcecin Aug 23, 2023
4db2e1b
scoped_exit for state_version & const
fcecin Aug 23, 2023
a1ced9c
Added back prefixes for bls_private_key, bls_public_key and bls_signa…
systemzax Aug 23, 2023
a82c129
Renamed serialization tests in test_bls.cpp
systemzax Aug 23, 2023
8bcb4e7
Avoid redundant state cache updates
fcecin Aug 23, 2023
20e5cb0
Set up hotstuff_logger at initial time
linh2931 Aug 23, 2023
9062952
Fix weak ++_state_version w/ make_scoped_exit
fcecin Aug 24, 2023
abd0508
Link all hotstuff components to FC logging
linh2931 Aug 24, 2023
587abb1
Merge pull request #1550 from AntelopeIO/hotstuff_1541_getstate_cache
fcecin Aug 24, 2023
cb13c75
use fc_ilog, fc_elog, fc_dlog, and fc_tlog instead of one ilog
linh2931 Aug 24, 2023
4918c7b
update logging.json
linh2931 Aug 24, 2023
14929cb
Merge branch 'hotstuff_integration' into hotstuff_logging_framework
linh2931 Aug 24, 2023
aa926f0
Merge pull request #1552 from AntelopeIO/hotstuff_logging_framework
linh2931 Aug 24, 2023
5d81bdd
GH-1519 Rm unused file
heifner Aug 25, 2023
32e9243
GH-1519 Remove hotstuff emit messages in controller. Simplify and opt…
heifner Aug 25, 2023
5f5ebe1
Fixed serialization / deserialization and checksum, key / signatures …
systemzax Aug 25, 2023
cf2920e
Changed private key storage type from vector<uint8_t> to array<uint64…
systemzax Aug 25, 2023
3cef6f1
Removed commented code
systemzax Aug 25, 2023
fae6f9e
Merge branch 'hotstuff_integration' into bls_cleanup_test_changes
systemzax Aug 25, 2023
54129ed
GH-1547 Support unlimited finalizers
heifner Aug 25, 2023
dcb04cb
set_finalizers host function (#1511)
fcecin Aug 25, 2023
44f76c4
Fixed prefix verfication + various cosmetic / style improvements
systemzax Aug 25, 2023
14fc742
Added correct prefix verification for bls signature
systemzax Aug 25, 2023
0b181fb
Merge branch 'bls_cleanup_test_changes' of https://github.com/Antelop…
systemzax Aug 25, 2023
e27c827
Fixes & get finalizer info to pacemaker
fcecin Aug 25, 2023
f198385
Added == operator to bls_private_key + unit test for binary construct…
systemzax Aug 25, 2023
5aaad89
Placeholder fix for bls_public_key operators
fcecin Aug 25, 2023
02abeb4
Added tests for public key encoding, use std::string for key prefixes
systemzax Aug 26, 2023
ee8eff1
controller::get_finalizer returns finalizer info
fcecin Aug 26, 2023
1cc704b
Remove vector copy
fcecin Aug 26, 2023
83183dd
Small fixes
fcecin Aug 26, 2023
c9fec69
Refactor finalizer_authority
fcecin Aug 26, 2023
3b3f55a
Refactor finalizer_authority
fcecin Aug 26, 2023
2c8720e
GH-1547 Address peer review comments
heifner Aug 26, 2023
22c0a44
GH-1553 Rewrite to rm recursive implementation
heifner Aug 26, 2023
02841ab
Misc fixes
fcecin Aug 26, 2023
dd9802a
GH-1547 Create a seperate quorum_certificate_message type
heifner Aug 26, 2023
33ac700
GH-1545 Remove NULL_BLOCK_ID and NULL_PROPOSAL_ID and use empty() ins…
heifner Aug 26, 2023
dd18c2f
GH-1545 Prefer {} to block_id_type{}
heifner Aug 26, 2023
86c4305
GH-1547 Minor cleanup
heifner Aug 26, 2023
ceed0e1
Merge branch 'main' of github.com:AntelopeIO/leap into main_catchup
greg7mdp Aug 27, 2023
d6cf723
Merge pull request #1571 from AntelopeIO/main_catchup
greg7mdp Aug 27, 2023
8966a29
Expanded bls unit tests to include additional format + checksum tests…
systemzax Aug 27, 2023
a0650f4
Updated bls_public_key and bls_signature == operator to use the corre…
systemzax Aug 27, 2023
d169dee
Updated bls_public_key and bls_signature == operator to use the corre…
systemzax Aug 27, 2023
1a05a40
Update libraries/libfc/src/crypto/bls_signature.cpp
systemzax Aug 27, 2023
98e1ae8
Update libraries/libfc/include/fc/crypto/bls_signature.hpp
systemzax Aug 27, 2023
22aac3b
Replace constexpr with const keyword for bls_signature_prefix declara…
systemzax Aug 27, 2023
d588704
GH-1547 Use set instead of flip as this is indicating the specified f…
heifner Aug 28, 2023
863033f
GH-1547 Use std::vector<unsigned_int> for quorum_certificate_message …
heifner Aug 28, 2023
c2c0446
GH-1547 Minor cleanup
heifner Aug 28, 2023
6af3110
GH-1519 Use a std::variant for hotstuff messages
heifner Aug 28, 2023
dba1f3a
GH-1541 Add thread safety to chain_pacemaker access of chain state
heifner Aug 28, 2023
55936b1
GH-1519 Rename method to be more clear
heifner Aug 28, 2023
79bdc04
GH-1519 Rename method to be more clear
heifner Aug 28, 2023
cb8bc49
GH-1541 minor cleanup
heifner Aug 28, 2023
a7fc539
GH-1541 minor cleanup
heifner Aug 28, 2023
7f4bcf8
GH-1541 make sure head_block_state is initialized
heifner Aug 28, 2023
5dfa47d
Merge pull request #1559 from AntelopeIO/GH-1519-rm-emit
heifner Aug 28, 2023
7447c15
GH-1541 make sure head_block_state is initialized
heifner Aug 29, 2023
ddb9ac4
Merge pull request #1538 from AntelopeIO/bls_cleanup_test_changes
heifner Aug 29, 2023
4ef68bd
Merge pull request #1560 from AntelopeIO/GH-1547-finalizer-set
heifner Aug 29, 2023
9b6fbdc
Merge pull request #1574 from AntelopeIO/GH-1541-threading-part-2
heifner Aug 29, 2023
255e2b0
Merge remote-tracking branch 'origin/hotstuff_integration' into hotst…
heifner Aug 29, 2023
2a94c27
Merge remote-tracking branch 'origin/hotstuff_integration' into GH-15…
heifner Aug 29, 2023
f8e3dea
Merge pull request #1566 from AntelopeIO/GH-1545-empty-id
heifner Aug 29, 2023
8735839
Merge remote-tracking branch 'origin/hotstuff_integration' into hotst…
heifner Aug 29, 2023
683750a
chain_pacemaker now created in startup.
heifner Aug 29, 2023
36a60e1
Remove unneeded/unused shared versions
heifner Aug 30, 2023
b605ce9
Merge pull request #1561 from AntelopeIO/hotstuff_1511_hostfn
heifner Aug 30, 2023
d82518d
Second pass at recursion removal for `qc_chain::commit()`
greg7mdp Aug 30, 2023
3c30a3e
Fix logic mistake in my previous commit
greg7mdp Aug 30, 2023
1adc205
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Aug 30, 2023
aa4f6e5
Cleanup log messages
greg7mdp Aug 30, 2023
df9afb9
Merge branch 'main' of github.com:AntelopeIO/leap into catchup_with_main
greg7mdp Aug 31, 2023
5b28de5
Watch for infinite loops.
greg7mdp Aug 31, 2023
37b5bb0
Merge pull request #1565 from AntelopeIO/GH-1553-rm-recursion
greg7mdp Aug 31, 2023
0bc06a7
Merge branch 'hotstuff_integration' into catchup_with_main
greg7mdp Aug 31, 2023
fe6fbc3
Changed bls private, public key / signature encoding from base58 to b…
systemzax Aug 31, 2023
361c1b2
Removed unnecessary yield function parameter, corrected semantic inve…
systemzax Aug 31, 2023
18b908c
Merge pull request #1587 from AntelopeIO/bls_base64_encoding
heifner Aug 31, 2023
b5c2ef5
Merge pull request #1582 from AntelopeIO/catchup_with_main
greg7mdp Aug 31, 2023
2c478df
GH-1523 Remove unneeded uniqueness check for description. Add 256 lim…
heifner Aug 31, 2023
c6aa358
GH-1523 Add hs_finalizer_set_extension and refactor to prevent inclus…
heifner Aug 31, 2023
ef8069d
GH-1523 Use 65536 for max_finalizers and 256 for max finalizer descri…
heifner Aug 31, 2023
bbc0493
Minor cleanup
heifner Sep 1, 2023
48a268b
GH-1523 Change contract bls_public_key format to JacobianLE
heifner Sep 1, 2023
f24626a
GH-1523 bls_public_key has explicit constructor
heifner Sep 1, 2023
decb6c2
GH-1523 Minor cleanup
heifner Sep 1, 2023
060b5ba
GH-1523 Minor cleanup
heifner Sep 1, 2023
8fad42e
Merge pull request #1588 from AntelopeIO/GH-1523-finalizer-set-transi…
heifner Sep 1, 2023
07e05f0
GH-1523 WIP: adding proposed finalizer_set to block_header_state and …
heifner Sep 1, 2023
b6e8da9
GH-1523 to/from variant tests
heifner Sep 2, 2023
9ef88bb
GH-1523 Add abi_serializer of hs_finalizer_set_extension
heifner Sep 2, 2023
b034860
add BLS utilities (creating key pair and proof of possession) to leap…
linh2931 Sep 3, 2023
fcded9e
add tests for create key pair
linh2931 Sep 3, 2023
3250a33
handle creating pop from private key in a file
linh2931 Sep 4, 2023
c0ce258
complete tests and minor refactoring
linh2931 Sep 5, 2023
cffb76e
GH-1523 Finish set_finalizers and add unittest
heifner Sep 5, 2023
f39b105
Merge branch 'GH-1523-finalizer-set-transition-2' of https://github.c…
heifner Sep 5, 2023
814df97
incorporate review comments
linh2931 Sep 5, 2023
ab4c1eb
GH-1523 CDT will use Affine little-endian format.
heifner Sep 5, 2023
fb93968
GH-1523 Remove unused spaceship operator not liked by libtester
heifner Sep 5, 2023
26b87e7
GH-1523 Update deep-mind test for new block extension
heifner Sep 5, 2023
b92aa6a
GH-1523 Comment out test until it can be worked under GH-1558
heifner Sep 5, 2023
7780a7f
Merge remote-tracking branch 'origin/hotstuff_integration' into GH-15…
heifner Sep 6, 2023
77a1935
GH-1523 Update test for base64 encoding
heifner Sep 6, 2023
0d58520
change to use raw affine little endian format for POP
linh2931 Sep 6, 2023
4ae53d1
replace std::endl with \n and add -f to create key error text
linh2931 Sep 6, 2023
af5c9fb
use raw Affine little-endian form of g1/g2 for encoding to BLS public…
linh2931 Sep 6, 2023
560b3f7
GH-1523 Update forkdb version since not backward compatible.
heifner Sep 6, 2023
ef2f378
GH-1523 Add option to producer_plugin to specify BLS finalizer keys
heifner Sep 6, 2023
9de9f6a
added set_finalizers to host functions list
dimas1185 Sep 6, 2023
4d01e5f
Update conversion from string to public key and signatur, and update …
linh2931 Sep 6, 2023
64f7f89
Merge pull request #1594 from AntelopeIO/generate_bls_key_pair
linh2931 Sep 6, 2023
d88aa98
Merge branch 'hotstuff_integration' into pk_sig_affine_le_format
linh2931 Sep 6, 2023
d130b47
Merge pull request #1603 from AntelopeIO/set_finalizers_fix
dimas1185 Sep 6, 2023
01f462d
GH-1523 Use alias for bls_key_map_t
heifner Sep 6, 2023
e0a9901
Merge pull request #1600 from AntelopeIO/pk_sig_affine_le_format
linh2931 Sep 6, 2023
2132734
check if public key string and signature string are invlid in conversion
linh2931 Sep 7, 2023
3a4d5ad
GH-1523 Use raw Affine LE form
heifner Sep 7, 2023
7a5714d
GH-1523 Add warning so change is not forgotten
heifner Sep 7, 2023
b695b40
GH-1523 Move warning to source file to avoid warning spam on every file
heifner Sep 7, 2023
d24c1a5
Merge remote-tracking branch 'origin/hotstuff_integration' into GH-15…
heifner Sep 7, 2023
b1bead1
GH-1523 Update test for new base64 form
heifner Sep 7, 2023
61db6ac
Merge pull request #1606 from AntelopeIO/check_key_invalid
linh2931 Sep 7, 2023
a24b4b4
Merge pull request #1598 from AntelopeIO/GH-1523-finalizer-set-transi…
heifner Sep 7, 2023
5ede17a
Merge pull request #1602 from AntelopeIO/GH-1523-finalizer-set-transi…
heifner Sep 7, 2023
c8d9d38
updated qc_chain to use bls_public_key as finalizer id, completed int…
systemzax Sep 10, 2023
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
663 changes: 663 additions & 0 deletions hostuff-pseudo.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_subdirectory( testing )
add_subdirectory( version )
add_subdirectory( state_history )
add_subdirectory( cli11 )
add_subdirectory( hotstuff )

set(USE_EXISTING_SOFTFLOAT ON CACHE BOOL "use pre-exisiting softfloat lib")
set(ENABLE_TOOLS OFF CACHE BOOL "Build tools")
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ add_library( eosio_chain
${CHAIN_WEBASSEMBLY_SOURCES}

authority.cpp
finalizer_set.cpp
trace.cpp
transaction_metadata.cpp
protocol_state_object.cpp
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/asset.hpp>
#include <eosio/chain/exceptions.hpp>
#include <eosio/chain/finalizer_authority.hpp>
#include <fc/io/raw.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/varint.hpp>
Expand Down Expand Up @@ -632,6 +633,14 @@ namespace eosio { namespace chain {
_variant_to_binary(type, var, ds, ctx);
}

void impl::abi_to_variant::add_block_header_finalizer_set_extension( mutable_variant_object& mvo, const flat_multimap<uint16_t, block_header_extension>& header_exts ) {
if (header_exts.count(hs_finalizer_set_extension::extension_id())) {
const auto& finalizer_set_extension =
std::get<hs_finalizer_set_extension>(header_exts.lower_bound(hs_finalizer_set_extension::extension_id())->second);
mvo("proposed_finalizer_set", finalizer_set_extension);
}
}

type_name abi_serializer::get_action_type(name action)const {
auto itr = actions.find(action);
if( itr != actions.end() ) return itr->second;
Expand Down
25 changes: 25 additions & 0 deletions libraries/chain/block_header.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <eosio/chain/block.hpp>
#include <eosio/chain/finalizer_authority.hpp>
#include <eosio/chain/merkle.hpp>
#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
Expand Down Expand Up @@ -64,4 +65,28 @@ namespace eosio { namespace chain {
return results;
}

std::optional<block_header_extension> block_header::extract_header_extension(uint16_t extension_id)const {
using decompose_t = block_header_extension_types::decompose_t;

for( size_t i = 0; i < header_extensions.size(); ++i ) {
const auto& e = header_extensions[i];
auto id = e.first;

if (id != extension_id)
continue;

block_header_extension ext;

auto match = decompose_t::extract<block_header_extension>( id, e.second, ext );
EOS_ASSERT( match, invalid_block_header_extension,
"Block header extension with id type ${id} is not supported",
("id", id)
);

return ext;
}

return {};
}

} }
3 changes: 3 additions & 0 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace eosio { namespace chain {

#warning Add last_proposed_finalizer_set_generation to snapshot_block_header_state_v3, see header file TODO

namespace detail {
bool is_builtin_activated( const protocol_feature_activation_set_ptr& pfa,
const protocol_feature_set& pfs,
Expand Down Expand Up @@ -65,6 +67,7 @@ namespace eosio { namespace chain {

result.valid_block_signing_authority = proauth.authority;
result.producer = proauth.producer_name;
result.last_proposed_finalizer_set_generation = last_proposed_finalizer_set_generation;

result.blockroot_merkle = blockroot_merkle;
result.blockroot_merkle.append( id );
Expand Down
35 changes: 35 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <eosio/chain/platform_timer.hpp>
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/wasm_interface_collection.hpp>
#include <eosio/chain/finalizer_set.hpp>
#include <eosio/chain/finalizer_authority.hpp>

#include <chainbase/chainbase.hpp>
#include <eosio/vm/allocator.hpp>
Expand Down Expand Up @@ -263,6 +265,8 @@ struct controller_impl {
map< account_name, map<handler_key, apply_handler> > apply_handlers;
unordered_map< builtin_protocol_feature_t, std::function<void(controller_impl&)>, enum_hash<builtin_protocol_feature_t> > protocol_feature_activation_handlers;

// TODO: This probably wants to be something better; store in chainbase and/or block_state
finalizer_set current_finalizer_set;

void pop_block() {
auto prev = fork_db.get_block( head->header.previous );
Expand Down Expand Up @@ -340,6 +344,7 @@ struct controller_impl {
set_activation_handler<builtin_protocol_feature_t::get_block_num>();
set_activation_handler<builtin_protocol_feature_t::crypto_primitives>();
set_activation_handler<builtin_protocol_feature_t::bls_primitives>();
set_activation_handler<builtin_protocol_feature_t::instant_finality>();

self.irreversible_block.connect([this](const block_state_ptr& bsp) {
wasm_if_collect.current_lib(bsp->block_num);
Expand Down Expand Up @@ -1900,6 +1905,18 @@ struct controller_impl {

block_ptr->transactions = std::move( bb._pending_trx_receipts );

if (bb._pending_block_header_state.proposed_finalizer_set) {
// proposed_finalizer_set can't be set until builtin_protocol_feature_t::instant_finality activated
finalizer_set& fin_set = *bb._pending_block_header_state.proposed_finalizer_set;
++bb._pending_block_header_state.last_proposed_finalizer_set_generation;
fin_set.generation = bb._pending_block_header_state.last_proposed_finalizer_set_generation;
emplace_extension(
block_ptr->header_extensions,
hs_finalizer_set_extension::extension_id(),
fc::raw::pack( hs_finalizer_set_extension{ std::move(fin_set) } )
);
}

auto id = block_ptr->calculate_id();

// Update TaPoS table:
Expand Down Expand Up @@ -1973,6 +1990,13 @@ struct controller_impl {
pending->push();
}

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

bb._pending_block_header_state.proposed_finalizer_set.emplace(fin_set);
}

/**
* This method is called from other threads. The controller_impl should outlive those threads.
* However, to avoid race conditions, it means that the behavior of this function should not change
Expand Down Expand Up @@ -3280,6 +3304,10 @@ int64_t controller::set_proposed_producers( vector<producer_authority> producers
return version;
}

void controller::set_proposed_finalizers( const finalizer_set& fin_set ) {
my->set_proposed_finalizers(fin_set);
}

const producer_authority_schedule& controller::active_producers()const {
if( !(my->pending) )
return my->head->active_schedule;
Expand Down Expand Up @@ -3840,6 +3868,13 @@ void controller_impl::on_activation<builtin_protocol_feature_t::bls_primitives>(
} );
}

template<>
void controller_impl::on_activation<builtin_protocol_feature_t::instant_finality>() {
db.modify( db.get<protocol_state_object>(), [&]( auto& ps ) {
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "set_finalizers" );
} );
}

/// End of protocol feature activation handlers

} } /// eosio::chain
21 changes: 21 additions & 0 deletions libraries/chain/finalizer_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <eosio/chain/finalizer_set.hpp>
#include <eosio/chain/finalizer_authority.hpp>
#include <fc/crypto/bls_public_key.hpp>

namespace eosio::chain {

/**
* These definitions are all here to avoid including bls_public_key.hpp which includes <bls12-381/bls12-381.hpp>
* and pulls in bls12-381 types. This keeps bls12-381 out of libtester.
*/

finalizer_set::finalizer_set() = default;
finalizer_set::~finalizer_set() = default;

finalizer_set::finalizer_set(const finalizer_set&) = default;
finalizer_set::finalizer_set(finalizer_set&&) noexcept = default;

finalizer_set& finalizer_set::operator=(const finalizer_set&) = default;
finalizer_set& finalizer_set::operator=(finalizer_set&&) noexcept = default;

} /// eosio::chain
5 changes: 3 additions & 2 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace eosio { namespace chain {

const uint32_t fork_database::magic_number = 0x30510FDB;

const uint32_t fork_database::min_supported_version = 1;
const uint32_t fork_database::max_supported_version = 1;
const uint32_t fork_database::min_supported_version = 2;
const uint32_t fork_database::max_supported_version = 2;

// work around block_state::is_valid being private
inline bool block_state_is_valid( const block_state& bs ) {
Expand All @@ -28,6 +28,7 @@ namespace eosio { namespace chain {
/**
* History:
* Version 1: initial version of the new refactored fork database portable format
* Version 2: New format for block_state for hotstuff/instant-finality
*/

struct by_block_id;
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/abi_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ namespace impl {
out(name, std::move(mvo));
}

static void add_block_header_finalizer_set_extension( mutable_variant_object& mvo, const flat_multimap<uint16_t, block_header_extension>& header_exts );

/**
* overload of to_variant_object for signed_block
*
Expand Down Expand Up @@ -676,6 +678,7 @@ namespace impl {
std::get<producer_schedule_change_extension>(header_exts.lower_bound(producer_schedule_change_extension::extension_id())->second);
mvo("new_producer_schedule", new_producer_schedule);
}
add_block_header_finalizer_set_extension(mvo, header_exts);

mvo("producer_signature", block.producer_signature);
add(mvo, "transactions", block.transactions, resolver, ctx);
Expand Down
6 changes: 5 additions & 1 deletion libraries/chain/include/eosio/chain/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <eosio/chain/block_timestamp.hpp>
#include <eosio/chain/producer_schedule.hpp>
#include <eosio/chain/protocol_feature_activation.hpp>
#include <eosio/chain/finalizer_set.hpp>

#include <optional>
#include <type_traits>

namespace eosio { namespace chain {
Expand All @@ -17,7 +19,8 @@ namespace eosio { namespace chain {

using block_header_extension_types = detail::block_header_extension_types<
protocol_feature_activation,
producer_schedule_change_extension
producer_schedule_change_extension,
hs_finalizer_set_extension
>;

using block_header_extension = block_header_extension_types::block_header_extension_t;
Expand Down Expand Up @@ -68,6 +71,7 @@ namespace eosio { namespace chain {
static uint32_t num_from_id(const block_id_type& id);

flat_multimap<uint16_t, block_header_extension> validate_and_extract_header_extensions()const;
std::optional<block_header_extension> extract_header_extension(uint16_t extension_id)const;
};


Expand Down
5 changes: 4 additions & 1 deletion libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/incremental_merkle.hpp>
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/finalizer_set.hpp>
#include <eosio/chain/chain_snapshot.hpp>
#include <future>

Expand Down Expand Up @@ -53,6 +54,7 @@ namespace detail {
uint32_t dpos_proposed_irreversible_blocknum = 0;
uint32_t dpos_irreversible_blocknum = 0;
producer_authority_schedule active_schedule;
uint32_t last_proposed_finalizer_set_generation = 0; // TODO: Add to snapshot_block_header_state_v3
incremental_merkle blockroot_merkle;
flat_map<account_name,uint32_t> producer_to_last_produced;
flat_map<account_name,uint32_t> producer_to_last_implied_irb;
Expand All @@ -74,6 +76,7 @@ namespace detail {
struct pending_block_header_state : public detail::block_header_state_common {
protocol_feature_activation_set_ptr prev_activated_protocol_features;
detail::schedule_info prev_pending_schedule;
std::optional<finalizer_set> proposed_finalizer_set; // set by set_finalizer host function
bool was_pending_promoted = false;
block_id_type previous;
account_name producer;
Expand Down Expand Up @@ -143,7 +146,6 @@ struct block_header_state : public detail::block_header_state_common {
const vector<digest_type>& )>& validator,
bool skip_validate_signee = false )const;

bool has_pending_producers()const { return pending_schedule.schedule.producers.size(); }
uint32_t calc_dpos_last_irreversible( account_name producer_of_next_block )const;

producer_authority get_scheduled_producer( block_timestamp_type t )const;
Expand All @@ -164,6 +166,7 @@ FC_REFLECT( eosio::chain::detail::block_header_state_common,
(dpos_proposed_irreversible_blocknum)
(dpos_irreversible_blocknum)
(active_schedule)
(last_proposed_finalizer_set_generation)
(blockroot_merkle)
(producer_to_last_produced)
(producer_to_last_implied_irb)
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/eosio/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const static auto reversible_blocks_dir_name = "reversible";

const static auto default_state_dir_name = "state";
const static auto forkdb_filename = "fork_db.dat";
const static auto qcdb_filename = "qc_db.dat";
const static auto default_state_size = 1*1024*1024*1024ll;
const static auto default_state_guard_size = 128*1024*1024ll;

Expand Down Expand Up @@ -129,6 +130,11 @@ const static int max_producers = 125;
const static size_t maximum_tracked_dpos_confirmations = 1024; ///<
static_assert(maximum_tracked_dpos_confirmations >= ((max_producers * 2 / 3) + 1) * producer_repetitions, "Settings never allow for DPOS irreversibility" );

/**
* Maximum number of finalizers in the finalizer set
*/
const static size_t max_finalizers = 64*1024;
const static size_t max_finalizer_description_size = 256;

/**
* The number of blocks produced per round is based upon all producers having a chance
Expand Down
18 changes: 6 additions & 12 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace eosio { namespace vm { class wasm_allocator; }}

namespace eosio { namespace chain {

struct finalizer_set;

class authorization_manager;

namespace resource_limits {
Expand Down Expand Up @@ -166,7 +168,7 @@ namespace eosio { namespace chain {
block_state_ptr finalize_block( block_report& br, const signer_callback_type& signer_callback );
void sign_block( const signer_callback_type& signer_callback );
void commit_block();

// thread-safe
std::future<block_state_ptr> create_block_state_future( const block_id_type& id, const signed_block_ptr& b );
// thread-safe
Expand Down Expand Up @@ -291,6 +293,9 @@ namespace eosio { namespace chain {

int64_t set_proposed_producers( vector<producer_authority> producers );

// called by host function set_finalizers
void set_proposed_finalizers( const finalizer_set& fin_set );

bool light_validation_allowed() const;
bool skip_auth_check()const;
bool skip_trx_checks()const;
Expand Down Expand Up @@ -338,16 +343,6 @@ namespace eosio { namespace chain {
signal<void(std::tuple<const transaction_trace_ptr&, const packed_transaction_ptr&>)> applied_transaction;
signal<void(const int&)> bad_alloc;

/*
signal<void()> pre_apply_block;
signal<void()> post_apply_block;
signal<void()> abort_apply_block;
signal<void(const transaction_metadata_ptr&)> pre_apply_transaction;
signal<void(const transaction_trace_ptr&)> post_apply_transaction;
signal<void(const transaction_trace_ptr&)> pre_apply_action;
signal<void(const transaction_trace_ptr&)> post_apply_action;
*/

const apply_handler* find_apply_handler( account_name contract, scope_name scope, action_name act )const;
wasm_interface_collection& get_wasm_interface();

Expand Down Expand Up @@ -376,7 +371,6 @@ namespace eosio { namespace chain {
chainbase::database& mutable_db()const;

std::unique_ptr<controller_impl> my;

};

} } /// eosio::chain
19 changes: 19 additions & 0 deletions libraries/chain/include/eosio/chain/finalizer_authority.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <fc/crypto/bls_public_key.hpp>
#include <string>

namespace eosio::chain {

struct finalizer_authority {

std::string description;
uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold
fc::crypto::blslib::bls_public_key public_key;

auto operator<=>(const finalizer_authority&) const = default;
};

} /// eosio::chain

FC_REFLECT( eosio::chain::finalizer_authority, (description)(fweight)(public_key) )
Loading