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

Commit

Permalink
Merge pull request #6464 from EOSIO/optimize-net-plugin
Browse files Browse the repository at this point in the history
Net plugin optimizations
  • Loading branch information
heifner authored Dec 14, 2018
2 parents 8e0dbf4 + 2edbf2f commit 45cd568
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 501 deletions.
3 changes: 0 additions & 3 deletions Docker/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ network-version-match = 0
# number of blocks to retrieve in a chunk from any individual peer during synchronization (eosio::net_plugin)
sync-fetch-span = 100

# maximum sizes of transaction or block messages that are sent without first sending a notice (eosio::net_plugin)
max-implicit-request = 1500

# Enable block production, even if the chain is stale. (eosio::producer_plugin)
enable-stale-production = false

Expand Down
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);
}

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 )
: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

0 comments on commit 45cd568

Please sign in to comment.