From f5ecb3831f2db8980e45e5d13c1281c74b6daee9 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 16 Jan 2024 12:55:03 -0500 Subject: [PATCH 1/3] add QC to block extension --- libraries/chain/block_state.cpp | 6 +++++- libraries/chain/controller.cpp | 7 ++++++- libraries/chain/include/eosio/chain/block_state.hpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index b750e68292..c945d2cfe7 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -12,13 +12,17 @@ block_state::block_state(const block_header_state& prev, signed_block_ptr b, con {} block_state::block_state(const block_header_state& bhs, deque&& trx_metas, - deque&& trx_receipts) + deque&& trx_receipts, std::optional qc) : block_header_state(bhs) , block(std::make_shared(signed_block_header{bhs.header})) // [greg todo] do we need signatures? , pub_keys_recovered(true) // probably not needed , cached_trxs(std::move(trx_metas)) { block->transactions = std::move(trx_receipts); + + if( qc ) { + emplace_extension(block->block_extensions, quorum_certificate_extension::extension_id(), fc::raw::pack( qc )); + } } // Used for transition from dpos to instant-finality diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 38294a630a..81c4257b4e 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -548,8 +548,13 @@ struct assembled_block { return completed_block{std::move(bsp)}; }, [&](assembled_block_if& ab) { + std::optional qc; + if( ab.qc && ab.bhs.is_needed(*ab.qc ) ) { + qc = *ab.qc; + } + auto bsp = std::make_shared(ab.bhs, std::move(ab.trx_metas), - std::move(ab.trx_receipts)); + std::move(ab.trx_receipts), qc); return completed_block{std::move(bsp)}; }}, v); diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index ff48e4fb5e..f264d7fd6b 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -48,7 +48,7 @@ struct block_state : public block_header_state { // block_header_state provi const validator_t& validator, bool skip_validate_signee); block_state(const block_header_state& bhs, deque&& trx_metas, - deque&& trx_receipts); + deque&& trx_receipts, std::optional qc); explicit block_state(const block_state_legacy& bsp); }; From 7e15a9c807e01ec9955c11ddea45956a96cb1852 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 16 Jan 2024 14:42:56 -0500 Subject: [PATCH 2/3] do is_needed check in block_state constructor to avoid a copying of qc --- libraries/chain/block_state.cpp | 6 +++--- libraries/chain/controller.cpp | 7 +------ libraries/chain/include/eosio/chain/block_state.hpp | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index c945d2cfe7..5926cac479 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -12,7 +12,7 @@ block_state::block_state(const block_header_state& prev, signed_block_ptr b, con {} block_state::block_state(const block_header_state& bhs, deque&& trx_metas, - deque&& trx_receipts, std::optional qc) + deque&& trx_receipts, const std::optional& qc) : block_header_state(bhs) , block(std::make_shared(signed_block_header{bhs.header})) // [greg todo] do we need signatures? , pub_keys_recovered(true) // probably not needed @@ -20,8 +20,8 @@ block_state::block_state(const block_header_state& bhs, dequetransactions = std::move(trx_receipts); - if( qc ) { - emplace_extension(block->block_extensions, quorum_certificate_extension::extension_id(), fc::raw::pack( qc )); + if( qc && bhs.is_needed(*qc) ) { + emplace_extension(block->block_extensions, quorum_certificate_extension::extension_id(), fc::raw::pack( *qc )); } } diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 81c4257b4e..6f973e00a2 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -548,13 +548,8 @@ struct assembled_block { return completed_block{std::move(bsp)}; }, [&](assembled_block_if& ab) { - std::optional qc; - if( ab.qc && ab.bhs.is_needed(*ab.qc ) ) { - qc = *ab.qc; - } - auto bsp = std::make_shared(ab.bhs, std::move(ab.trx_metas), - std::move(ab.trx_receipts), qc); + std::move(ab.trx_receipts), std::move(ab.qc)); return completed_block{std::move(bsp)}; }}, v); diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index f264d7fd6b..152356f1cc 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -48,7 +48,7 @@ struct block_state : public block_header_state { // block_header_state provi const validator_t& validator, bool skip_validate_signee); block_state(const block_header_state& bhs, deque&& trx_metas, - deque&& trx_receipts, std::optional qc); + deque&& trx_receipts, const std::optional& qc); explicit block_state(const block_state_legacy& bsp); }; From 06da8afc700f3d66f78094e8bcd8c41c66b68f6e Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 16 Jan 2024 15:12:28 -0500 Subject: [PATCH 3/3] remove std::move for ab.qc --- libraries/chain/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6f973e00a2..2ac7acb64c 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -549,7 +549,7 @@ struct assembled_block { }, [&](assembled_block_if& ab) { auto bsp = std::make_shared(ab.bhs, std::move(ab.trx_metas), - std::move(ab.trx_receipts), std::move(ab.qc)); + std::move(ab.trx_receipts), ab.qc); return completed_block{std::move(bsp)}; }}, v);