Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/5.0' into GH-1683-stable…
Browse files Browse the repository at this point in the history
…-id-5.0
  • Loading branch information
heifner committed Oct 11, 2023
2 parents 50ca986 + 3231de1 commit c5fc681
Show file tree
Hide file tree
Showing 29 changed files with 1,767 additions and 442 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set( CXX_STANDARD_REQUIRED ON)
set(VERSION_MAJOR 5)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION_SUFFIX rc1)
set(VERSION_SUFFIX rc2)

if(VERSION_SUFFIX)
set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_SUFFIX}")
Expand Down
8 changes: 6 additions & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,12 +1595,14 @@ struct controller_impl {
trx->packed_trx()->get_prunable_size() );
}

trx_context.delay = fc::seconds(trn.delay_sec);

if( check_auth ) {
authorization.check_authorization(
trn.actions,
trx->recovered_keys(),
{},
fc::seconds(trn.delay_sec),
trx_context.delay,
[&trx_context](){ trx_context.checktime(); },
false,
trx->is_dry_run()
Expand All @@ -1613,7 +1615,9 @@ struct controller_impl {

trx->billed_cpu_time_us = trx_context.billed_cpu_time_us;
if (!trx->implicit() && !trx->is_read_only()) {
transaction_receipt::status_enum s = transaction_receipt::executed;
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);
std::get<building_block>(pending->_block_stage)._pending_trx_metas.emplace_back(trx);
} else {
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ namespace eosio { namespace chain {
private:
friend class apply_context;
friend class transaction_context;
friend void modify_gto_for_canceldelay_test(controller& control, const transaction_id_type& trx_id); // canceldelay_test in delay_tests.cpp need access to mutable_db

chainbase::database& mutable_db()const;

Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/transaction_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace eosio { namespace chain {

void execute_action( uint32_t action_ordinal, uint32_t recurse_depth );

void schedule_transaction();
void record_transaction( const transaction_id_type& id, fc::time_point_sec expire );

void validate_cpu_usage_to_bill( int64_t billed_us, int64_t account_cpu_limit, bool check_minimum, int64_t subjective_billed_us )const;
Expand Down Expand Up @@ -142,6 +143,7 @@ namespace eosio { namespace chain {
/// the maximum number of virtual CPU instructions of the transaction that can be safely billed to the billable accounts
uint64_t initial_max_billable_cpu = 0;

fc::microseconds delay;
bool is_input = false;
bool apply_context_free = true;
bool enforce_whiteblacklist = true;
Expand Down
60 changes: 57 additions & 3 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ namespace eosio { namespace chain {
uint64_t packed_trx_prunable_size )
{
const transaction& trx = packed_trx.get_transaction();
EOS_ASSERT( trx.delay_sec.value == 0, transaction_exception, "transaction cannot be delayed" );
// delayed transactions are not allowed after protocol feature
// DISABLE_DEFERRED_TRXS_STAGE_1 is activated;
// read-only and dry-run transactions are not allowed to be delayed at any time
if( control.is_builtin_activated(builtin_protocol_feature_t::disable_deferred_trxs_stage_1) || is_transient() ) {
EOS_ASSERT( trx.delay_sec.value == 0, transaction_exception, "transaction cannot be delayed" );
}
if( trx.transaction_extensions.size() > 0 ) {
disallow_transaction_extensions( "no transaction extensions supported yet for input transactions" );
}
Expand All @@ -266,6 +271,13 @@ namespace eosio { namespace chain {
uint64_t initial_net_usage = static_cast<uint64_t>(cfg.base_per_transaction_net_usage)
+ packed_trx_unprunable_size + discounted_size_for_pruned_data;

if( trx.delay_sec.value > 0 ) {
// If delayed, also charge ahead of time for the additional net usage needed to retire the delayed transaction
// whether that be by successfully executing, soft failure, hard failure, or expiration.
initial_net_usage += static_cast<uint64_t>(cfg.base_per_transaction_net_usage)
+ static_cast<uint64_t>(config::transaction_id_net_usage);
}

published = control.pending_block_time();
is_input = true;
if (!control.skip_trx_checks()) {
Expand Down Expand Up @@ -309,15 +321,21 @@ namespace eosio { namespace chain {
}
}

for( const auto& act : trx.actions ) {
schedule_action( act, act.account, false, 0, 0 );
if( delay == fc::microseconds() ) {
for( const auto& act : trx.actions ) {
schedule_action( act, act.account, false, 0, 0 );
}
}

auto& action_traces = trace->action_traces;
uint32_t num_original_actions_to_execute = action_traces.size();
for( uint32_t i = 1; i <= num_original_actions_to_execute; ++i ) {
execute_action( i, 0 );
}

if( delay != fc::microseconds() ) {
schedule_transaction();
}
}

void transaction_context::finalize() {
Expand Down Expand Up @@ -715,6 +733,42 @@ namespace eosio { namespace chain {
acontext.exec();
}

void transaction_context::schedule_transaction() {
// Charge ahead of time for the additional net usage needed to retire the delayed transaction
// whether that be by successfully executing, soft failure, hard failure, or expiration.
const transaction& trx = packed_trx.get_transaction();
if( trx.delay_sec.value == 0 ) { // Do not double bill. Only charge if we have not already charged for the delay.
const auto& cfg = control.get_global_properties().configuration;
add_net_usage( static_cast<uint64_t>(cfg.base_per_transaction_net_usage)
+ static_cast<uint64_t>(config::transaction_id_net_usage) ); // Will exit early if net usage cannot be payed.
}

auto first_auth = trx.first_authorizer();

uint32_t trx_size = 0;
const auto& cgto = control.mutable_db().create<generated_transaction_object>( [&]( auto& gto ) {
gto.trx_id = id;
gto.payer = first_auth;
gto.sender = account_name(); /// delayed transactions have no sender
gto.sender_id = transaction_id_to_sender_id( gto.trx_id );
gto.published = control.pending_block_time();
gto.delay_until = gto.published + delay;
gto.expiration = gto.delay_until + fc::seconds(control.get_global_properties().configuration.deferred_trx_expiration_window);
trx_size = gto.set( trx );

if (auto dm_logger = control.get_deep_mind_logger(is_transient())) {
std::string event_id = RAM_EVENT_ID("${id}", ("id", gto.id));

dm_logger->on_create_deferred(deep_mind_handler::operation_qualifier::push, gto, packed_trx);
dm_logger->on_ram_trace(std::move(event_id), "deferred_trx", "push", "deferred_trx_pushed");
}
});

int64_t ram_delta = (config::billable_size_v<generated_transaction_object> + trx_size);
add_ram_usage( cgto.payer, ram_delta );
trace->account_ram_delta = account_delta( cgto.payer, ram_delta );
}

void transaction_context::record_transaction( const transaction_id_type& id, fc::time_point_sec expire ) {
try {
control.mutable_db().create<transaction_object>([&](transaction_object& transaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class bp_connection_manager {
// Only called from connection strand
std::size_t num_established_clients() const {
uint32_t num_clients = 0;
self()->connections.for_each_connection([&num_clients](auto&& conn) {
self()->connections.for_each_connection([&num_clients](const std::shared_ptr<Connection>& conn) {
if (established_client_connection(conn)) {
++num_clients;
}
Expand All @@ -157,7 +157,7 @@ class bp_connection_manager {
// Only called from connection strand
// This should only be called after the first handshake message is received to check if an incoming connection
// has exceeded the pre-configured max_client_count limit.
bool exceeding_connection_limit(Connection* new_connection) const {
bool exceeding_connection_limit(std::shared_ptr<Connection> new_connection) const {
return auto_bp_peering_enabled() && self()->connections.get_max_client_count() != 0 &&
established_client_connection(new_connection) && num_established_clients() > self()->connections.get_max_client_count();
}
Expand All @@ -182,7 +182,7 @@ class bp_connection_manager {

fc_dlog(self()->get_logger(), "pending_downstream_neighbors: ${pending_downstream_neighbors}",
("pending_downstream_neighbors", to_string(pending_downstream_neighbors)));
for (auto neighbor : pending_downstream_neighbors) { self()->connections.connect(config.bp_peer_addresses[neighbor], *self()->p2p_addresses.begin() ); }
for (auto neighbor : pending_downstream_neighbors) { self()->connections.resolve_and_connect(config.bp_peer_addresses[neighbor], self()->get_first_p2p_address() ); }

pending_neighbors = std::move(pending_downstream_neighbors);
finder.add_upstream_neighbors(pending_neighbors);
Expand Down
3 changes: 3 additions & 0 deletions plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ namespace eosio {
std::chrono::nanoseconds last_bytes_received{0};
size_t bytes_sent{0};
std::chrono::nanoseconds last_bytes_sent{0};
size_t block_sync_bytes_received{0};
size_t block_sync_bytes_sent{0};
bool block_sync_throttling{false};
std::chrono::nanoseconds connection_start_time{0};
std::string p2p_address;
std::string unique_conn_node_id;
Expand Down
4 changes: 3 additions & 1 deletion plugins/net_plugin/include/eosio/net_plugin/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ namespace eosio {

// Longest domain name is 253 characters according to wikipedia.
// Addresses include ":port" where max port is 65535, which adds 6 chars.
// Addresses may also include ":bitrate" with suffix and separators, which adds 30 chars,
// for the maximum comma-separated value that fits in a size_t expressed in decimal plus a suffix.
// We also add our own extentions of "[:trx|:blk] - xxxxxxx", which adds 14 chars, total= 273.
// Allow for future extentions as well, hence 384.
constexpr size_t max_p2p_address_length = 253 + 6;
constexpr size_t max_p2p_address_length = 253 + 6 + 30;
constexpr size_t max_handshake_str_length = 384;

struct handshake_message {
Expand Down
Loading

0 comments on commit c5fc681

Please sign in to comment.