-
Notifications
You must be signed in to change notification settings - Fork 15
Update to peer_keys_db_t to match changes in eos-system-contracts pr 185 #1316
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
Changes from 20 commits
bc78038
696f02b
dba098c
63731f2
b1e64cc
00b9582
ac600cf
4b9364a
328d2fe
1bd34ed
70edeab
b07e4d5
27075d6
b58e9c1
bce86eb
77c2123
7e70919
8f36e60
bdbe42f
d440317
b3f3693
9c783fd
f694d61
68bc98b
6342b5d
406d928
e80a6e5
ca9c2f1
53770de
a42f0b8
9ca911a
59e9336
de28545
f2e0543
88a9855
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1274,6 +1274,59 @@ struct controller_impl { | |
apply_handlers[receiver][make_pair(contract,action)] = v; | ||
} | ||
|
||
void set_trx_expiration(signed_transaction& trx) { | ||
if (is_builtin_activated(builtin_protocol_feature_t::no_duplicate_deferred_id)) { | ||
trx.expiration = time_point_sec(); | ||
trx.ref_block_num = 0; | ||
trx.ref_block_prefix = 0; | ||
} else { | ||
trx.expiration = time_point_sec{ | ||
pending_block_time() + fc::microseconds(999'999)}; // Round up to nearest second to avoid appearing expired | ||
trx.set_reference_block(chain_head.id()); | ||
} | ||
} | ||
|
||
getpeerkeys_res_t get_top_producer_keys() { | ||
try { | ||
auto get_getpeerkeys_transaction = [&]() { | ||
auto perms = vector<permission_level>{}; | ||
action act(perms, config::system_account_name, "getpeerkeys"_n, {}); | ||
signed_transaction trx; | ||
|
||
trx.actions.emplace_back(std::move(act)); | ||
trx.set_reference_block(chain_head.id()); | ||
set_trx_expiration(trx); | ||
return trx; | ||
}; | ||
|
||
auto metadata = transaction_metadata::create_no_recover_keys( | ||
std::make_shared<packed_transaction>(get_getpeerkeys_transaction()), | ||
transaction_metadata::trx_type::read_only); | ||
|
||
const auto& gpo = db.get<global_property_object>(); | ||
|
||
auto trace = push_transaction(metadata, fc::time_point::maximum(), fc::microseconds::maximum(), | ||
gpo.configuration.min_transaction_cpu_usage, true, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arhag any opinion on if we should set a limit on the read-only trx? Maybe something like 10ms? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if( trace->except_ptr ) | ||
std::rethrow_exception(trace->except_ptr); | ||
if( trace->except) | ||
throw *trace->except; | ||
getpeerkeys_res_t res; | ||
if (!trace->action_traces.empty()) { | ||
const auto& act_trace = trace->action_traces[0]; | ||
const auto& retval = act_trace.return_value; | ||
assert(!retval.empty()); | ||
|
||
fc::datastream<const char*> ds(retval.data(), retval.size()); | ||
fc::raw::unpack(ds, res); | ||
} | ||
|
||
return res; | ||
} | ||
FC_LOG_AND_RETHROW() | ||
} | ||
|
||
controller_impl( const controller::config& cfg, controller& s, protocol_feature_set&& pfs, const chain_id_type& chain_id ) | ||
:rnh(), | ||
self(s), | ||
|
@@ -1322,9 +1375,6 @@ struct controller_impl { | |
const auto& [ block, id] = t; | ||
wasmif.current_lib(block->block_num()); | ||
vote_processor.notify_lib(block->block_num()); | ||
|
||
// update peer public keys from chainbase db | ||
peer_keys_db.update_peer_keys(self, block->block_num()); | ||
}); | ||
|
||
#define SET_APP_HANDLER( receiver, contract, action) \ | ||
|
@@ -2623,14 +2673,7 @@ struct controller_impl { | |
// Deliver onerror action containing the failed deferred transaction directly back to the sender. | ||
etrx.actions.emplace_back( vector<permission_level>{{gtrx.sender, config::active_name}}, | ||
onerror( gtrx.sender_id, gtrx.packed_trx.data(), gtrx.packed_trx.size() ) ); | ||
if( is_builtin_activated( builtin_protocol_feature_t::no_duplicate_deferred_id ) ) { | ||
etrx.expiration = time_point_sec(); | ||
etrx.ref_block_num = 0; | ||
etrx.ref_block_prefix = 0; | ||
} else { | ||
etrx.expiration = time_point_sec{pending_block_time() + fc::microseconds(999'999)}; // Round up to nearest second to avoid appearing expired | ||
etrx.set_reference_block( chain_head.id() ); | ||
} | ||
set_trx_expiration(etrx); | ||
|
||
auto& bb = std::get<building_block>(pending->_block_stage); | ||
|
||
|
@@ -3339,9 +3382,18 @@ struct controller_impl { | |
} | ||
|
||
guard_pending.cancel(); | ||
|
||
return onblock_trace; | ||
} /// start_block | ||
|
||
void run_readonly_transactions() { | ||
// update peer public keys from chainbase db using a readonly trx | ||
auto block_num = chain_head.block_num(); | ||
if (block_num % 120 == 0) { | ||
peer_keys_db.update_peer_keys(get_top_producer_keys()); // update once/minute | ||
heifner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
void assemble_block(bool validating, std::optional<qc_data_t> validating_qc_data, const block_state_ptr& validating_bsp) | ||
{ | ||
EOS_ASSERT( pending, block_validate_exception, "it is not valid to finalize when there is no pending block"); | ||
|
@@ -4788,14 +4840,7 @@ struct controller_impl { | |
|
||
signed_transaction trx; | ||
trx.actions.emplace_back(std::move(on_block_act)); | ||
if( is_builtin_activated( builtin_protocol_feature_t::no_duplicate_deferred_id ) ) { | ||
trx.expiration = time_point_sec(); | ||
trx.ref_block_num = 0; | ||
trx.ref_block_prefix = 0; | ||
} else { | ||
trx.expiration = time_point_sec{pending_block_time() + fc::microseconds(999'999)}; // Round up to nearest second to avoid appearing expired | ||
trx.set_reference_block( chain_head.id() ); | ||
} | ||
set_trx_expiration(trx); | ||
|
||
return trx; | ||
} | ||
|
@@ -5293,6 +5338,10 @@ transaction_trace_ptr controller::start_block( block_timestamp_type when, | |
bs, std::optional<block_id_type>(), deadline ); | ||
} | ||
|
||
void controller::run_readonly_transactions() { | ||
my->run_readonly_transactions(); | ||
} | ||
|
||
void controller::assemble_and_complete_block( const signer_callback_type& signer_callback ) { | ||
validate_db_available_size(); | ||
|
||
|
@@ -5793,8 +5842,12 @@ void controller::set_peer_keys_retrieval_active(bool active) { | |
my->peer_keys_db.set_active(active); | ||
} | ||
|
||
std::optional<public_key_type> controller::get_peer_key(name n) const { | ||
return my->peer_keys_db.get_peer_key(n); | ||
peer_info_t controller::get_peer_info(name n) const { | ||
return my->peer_keys_db.get_peer_info(n); | ||
} | ||
|
||
getpeerkeys_res_t controller::get_top_producer_keys() { | ||
return my->get_top_producer_keys(); | ||
} | ||
|
||
db_read_mode controller::get_read_mode()const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we require tapos & expiration on read only trx? You might be able to skip these couple lines
Either way,
set_trx_expiration()
does aset_reference_block()
anyways so seems at least that line is redundant