Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Net plugin optimizations #6464

Merged
merged 27 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d381ec0
Do not broadcast block if peer lib is larger than block number
heifner Nov 28, 2018
e845204
Provide more efficient sha256_less
heifner Nov 29, 2018
2a32ee4
Simply by removing unused large_msg_notify
heifner Nov 30, 2018
0594dd5
Remove unused node_transaction_state.packed_txn
heifner Nov 30, 2018
e44f205
Store serialized transaction as shared_ptr to minimize copies
heifner Nov 30, 2018
28301f2
Not possible for serialized_txn to be empty
heifner Nov 30, 2018
f403da8
Remove find_plugin overhead
heifner Nov 30, 2018
2678b5e
Minimize shared_ptr copies
heifner Dec 1, 2018
ac374bb
Use sha256_less for all sets/maps with ids
heifner Dec 2, 2018
7bcdcbc
Add explicit constructors
heifner Dec 3, 2018
de9742e
Add accept_transaction that takes a packed_transaction_ptr to avoid copy
heifner Dec 3, 2018
7923af9
Pass id and packed_transaction by const& since never moved
heifner Dec 3, 2018
b4ad4a3
Remove copy assignment operator. Remove used std::move.
heifner Dec 3, 2018
cfc3a85
Minimize packed_transaction copies. Store packed_transaction_ptr in t…
heifner Dec 3, 2018
8109f0a
Cache chain_plugin lookup
heifner Dec 3, 2018
a0f7ae0
Update tester for transaction_metadata packed_transaction_ptr
heifner Dec 3, 2018
81502d2
Remove packed_tansaction to net_message copy
heifner Dec 3, 2018
86e581a
Remove unused constructor
heifner Dec 4, 2018
bd3b208
Explicitly disable copy/move construction
heifner Dec 4, 2018
e9e9fe0
Remove inflight update of node_transaction_state as it is not needed
heifner Dec 5, 2018
f3255af
Remove connections for unused signals that only logged
heifner Dec 5, 2018
52a6f19
Fix sync check for lib
heifner Dec 6, 2018
deb8460
Merge remote-tracking branch 'origin/net-plugin-opt' into optimize-ne…
heifner Dec 11, 2018
c9126e4
More descriptive memo to distinguish from other transfers
heifner Dec 11, 2018
ce7d240
Revert "Fix sync check for lib"
heifner Dec 11, 2018
f712780
Peer review changes. Fix move.
heifner Dec 14, 2018
2edbf2f
Remove unused max-implicit-request config
heifner Dec 14, 2018
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
8 changes: 4 additions & 4 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ struct controller_impl {
trx_context.enforce_whiteblacklist = false;
} else {
bool skip_recording = replay_head_time && (time_point(trx->trx.expiration) <= *replay_head_time);
trx_context.init_for_input_trx( trx->packed_trx.get_unprunable_size(),
trx->packed_trx.get_prunable_size(),
trx_context.init_for_input_trx( trx->packed_trx->get_unprunable_size(),
trx->packed_trx->get_prunable_size(),
trx->trx.signatures.size(),
skip_recording);
}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ struct controller_impl {
transaction_receipt::status_enum s = (trx_context.delay == fc::seconds(0))
? transaction_receipt::executed
: transaction_receipt::delayed;
trace->receipt = push_receipt(trx->packed_trx, s, trx_context.billed_cpu_time_us, trace->net_usage);
trace->receipt = push_receipt(*trx->packed_trx, s, trx_context.billed_cpu_time_us, trace->net_usage);
pending->_pending_block_state->trxs.emplace_back(trx);
} else {
transaction_receipt_header r;
Expand Down Expand Up @@ -1203,7 +1203,7 @@ struct controller_impl {
for( const auto& receipt : b->transactions ) {
if( receipt.trx.contains<packed_transaction>()) {
auto& pt = receipt.trx.get<packed_transaction>();
auto mtrx = std::make_shared<transaction_metadata>( pt );
auto mtrx = std::make_shared<transaction_metadata>( std::make_shared<packed_transaction>( pt ) );
if( !self.skip_auth_check() ) {
std::weak_ptr<transaction_metadata> mtrx_wp = mtrx;
mtrx->signing_keys_future = async_thread_pool( [chain_id = this->chain_id, mtrx_wp]() {
Expand Down
11 changes: 6 additions & 5 deletions libraries/chain/include/eosio/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace eosio { namespace chain {
};

transaction_receipt_header():status(hard_fail){}
transaction_receipt_header( status_enum s ):status(s){}
explicit transaction_receipt_header( status_enum s ):status(s){}

friend inline bool operator ==( const transaction_receipt_header& lhs, const transaction_receipt_header& rhs ) {
return std::tie(lhs.status, lhs.cpu_usage_us, lhs.net_usage_words) == std::tie(rhs.status, rhs.cpu_usage_us, rhs.net_usage_words);
}

fc::enum_type<uint8_t,status_enum> status;
uint32_t cpu_usage_us; ///< total billed CPU usage (microseconds)
uint32_t cpu_usage_us = 0; ///< total billed CPU usage (microseconds)
fc::unsigned_int net_usage_words; ///< total billed NET usage, so we can reconstruct resource state when skipping context free data... hard failures...
};

struct transaction_receipt : public transaction_receipt_header {

transaction_receipt():transaction_receipt_header(){}
transaction_receipt( transaction_id_type tid ):transaction_receipt_header(executed),trx(tid){}
transaction_receipt( packed_transaction ptrx ):transaction_receipt_header(executed),trx(ptrx){}
explicit transaction_receipt( const transaction_id_type& tid ):transaction_receipt_header(executed),trx(tid){}
explicit transaction_receipt( const packed_transaction& ptrx ):transaction_receipt_header(executed),trx(ptrx){}

fc::static_variant<transaction_id_type, packed_transaction> trx;

Expand All @@ -59,8 +59,9 @@ namespace eosio { namespace chain {
signed_block( const signed_block& ) = default;
public:
signed_block() = default;
signed_block( const signed_block_header& h ):signed_block_header(h){}
explicit signed_block( const signed_block_header& h ):signed_block_header(h){}
signed_block( signed_block&& ) = default;
signed_block& operator=(const signed_block&) = delete;
signed_block clone() const { return *this; }

vector<transaction_receipt> transactions; /// new or generated transactions
Expand Down
11 changes: 5 additions & 6 deletions libraries/chain/include/eosio/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ namespace eosio { namespace chain {
};

packed_transaction() = default;

explicit packed_transaction(const transaction& t, compression_type _compression = none)
{
set_transaction(t, _compression);
}
packed_transaction(packed_transaction&&) = default;
explicit packed_transaction(const packed_transaction&) = default;
packed_transaction& operator=(const packed_transaction&) = delete;
packed_transaction& operator=(packed_transaction&&) = default;

explicit packed_transaction(const signed_transaction& t, compression_type _compression = none)
:signatures(t.signatures)
Expand All @@ -117,7 +116,7 @@ namespace eosio { namespace chain {
explicit packed_transaction(signed_transaction&& t, compression_type _compression = none)
:signatures(std::move(t.signatures))
{
set_transaction(t, std::move(t.context_free_data), _compression);
set_transaction(t, t.context_free_data, _compression);
arhag marked this conversation as resolved.
Show resolved Hide resolved
}

uint32_t get_unprunable_size()const;
Expand Down
20 changes: 12 additions & 8 deletions libraries/chain/include/eosio/chain/transaction_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ class transaction_metadata {
transaction_id_type id;
transaction_id_type signed_id;
signed_transaction trx;
packed_transaction packed_trx;
packed_transaction_ptr packed_trx;
optional<pair<chain_id_type, flat_set<public_key_type>>> signing_keys;
std::future<pair<chain_id_type,flat_set<public_key_type>>> signing_keys_future;
bool accepted = false;
bool implicit = false;
bool scheduled = false;

transaction_metadata() = delete;
transaction_metadata(const transaction_metadata&) = delete;
transaction_metadata(transaction_metadata&&) = delete;
transaction_metadata operator=(transaction_metadata&) = delete;
transaction_metadata operator=(transaction_metadata&&) = delete;

explicit transaction_metadata( const signed_transaction& t, packed_transaction::compression_type c = packed_transaction::none )
:trx(t),packed_trx(t, c) {
id = trx.id();
:id(t.id()), trx(t), packed_trx(std::make_shared<packed_transaction>(t, c)) {
//raw_packed = fc::raw::pack( static_cast<const transaction&>(trx) );
signed_id = digest_type::hash(packed_trx);
signed_id = digest_type::hash(*packed_trx);
}

explicit transaction_metadata( const packed_transaction& ptrx )
:trx( ptrx.get_signed_transaction() ), packed_trx(ptrx) {
id = trx.id();
explicit transaction_metadata( const packed_transaction_ptr& ptrx )
arhag marked this conversation as resolved.
Show resolved Hide resolved
:id(ptrx->id()), trx( ptrx->get_signed_transaction() ), packed_trx(ptrx) {
//raw_packed = fc::raw::pack( static_cast<const transaction&>(trx) );
signed_id = digest_type::hash(packed_trx);
signed_id = digest_type::hash(*packed_trx);
}

const flat_set<public_key_type>& recover_keys( const chain_id_type& chain_id ) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ namespace eosio { namespace testing {
{ try {
if( !control->pending_block_state() )
_start_block(control->head_block_time() + fc::microseconds(config::block_interval_us));
auto r = control->push_transaction( std::make_shared<transaction_metadata>(trx), deadline, billed_cpu_time_us );
auto r = control->push_transaction( std::make_shared<transaction_metadata>(std::make_shared<packed_transaction>(trx)), deadline, billed_cpu_time_us );
if( r->except_ptr ) std::rethrow_exception( r->except_ptr );
if( r->except ) throw *r->except;
return r;
Expand Down
2 changes: 1 addition & 1 deletion plugins/bnet_plugin/bnet_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ namespace eosio {
return false;


auto ptrx_ptr = std::make_shared<packed_transaction>( start->trx->packed_trx );
auto ptrx_ptr = start->trx->packed_trx;

idx.modify( start, [&]( auto& stat ) {
stat.mark_known_by_peer();
Expand Down
4 changes: 4 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ void chain_plugin::accept_transaction(const chain::packed_transaction& trx, next
my->incoming_transaction_async_method(std::make_shared<packed_transaction>(trx), false, std::forward<decltype(next)>(next));
}

void chain_plugin::accept_transaction(const chain::packed_transaction_ptr& trx, next_function<chain::transaction_trace_ptr> next) {
my->incoming_transaction_async_method(trx, false, std::forward<decltype(next)>(next));
}

bool chain_plugin::block_is_on_preferred_chain(const block_id_type& block_id) {
auto b = chain().fetch_block_by_number( block_header::num_from_id(block_id) );
return b && b->id() == block_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ class chain_plugin : public plugin<chain_plugin> {

void accept_block( const chain::signed_block_ptr& block );
void accept_transaction(const chain::packed_transaction& trx, chain::plugin_interface::next_function<chain::transaction_trace_ptr> next);
void accept_transaction(const chain::packed_transaction_ptr& trx, chain::plugin_interface::next_function<chain::transaction_trace_ptr> next);

bool block_is_on_preferred_chain(const chain::block_id_type& block_id);

Expand Down
13 changes: 6 additions & 7 deletions plugins/history_plugin/history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ namespace eosio {
for (const auto &receipt: blk->transactions) {
if (receipt.trx.contains<packed_transaction>()) {
auto &pt = receipt.trx.get<packed_transaction>();
auto mtrx = transaction_metadata(pt);
if (mtrx.id == result.id) {
if (pt.id() == result.id) {
fc::mutable_variant_object r("receipt", receipt);
r("trx", chain.to_variant_with_abi(mtrx.trx, abi_serializer_max_time));
r("trx", chain.to_variant_with_abi(pt.get_signed_transaction(), abi_serializer_max_time));
result.trx = move(r);
break;
}
Expand All @@ -528,14 +527,14 @@ namespace eosio {
for (const auto& receipt: blk->transactions) {
if (receipt.trx.contains<packed_transaction>()) {
auto& pt = receipt.trx.get<packed_transaction>();
auto mtrx = transaction_metadata(pt);
if( txn_id_matched(mtrx.id) ) {
result.id = mtrx.id;
const auto& id = pt.id();
if( txn_id_matched(id) ) {
result.id = id;
result.last_irreversible_block = chain.last_irreversible_block_num();
result.block_num = *p.block_num_hint;
result.block_time = blk->timestamp;
fc::mutable_variant_object r("receipt", receipt);
r("trx", chain.to_variant_with_abi(mtrx.trx, abi_serializer_max_time));
r("trx", chain.to_variant_with_abi(pt.get_signed_transaction(), abi_serializer_max_time));
result.trx = move(r);
found = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions plugins/net_plugin/include/eosio/net_plugin/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ namespace eosio {
notice_message,
request_message,
sync_request_message,
signed_block, // which = 7
packed_transaction>;
signed_block, // which = 7
packed_transaction>; // which = 8

} // namespace eosio

Expand Down
Loading