提交 8c453896 编写于 作者: B Bart Wyatt

Remove the redundant signature recovery and block digest when applying trusted/pre-validated blocks

上级 ce16a4b4
......@@ -177,6 +177,7 @@ namespace eosio { namespace chain {
result.header.producer_signature = h.producer_signature;
result.id = result.header.id();
// ASSUMPTION FROM controller_impl::apply_block = all untrusted blocks will have their signatures pre-validated here
if( !trust ) {
EOS_ASSERT( result.block_signing_key == result.signee(), wrong_signing_key, "block not signed by expected key",
("result.block_signing_key", result.block_signing_key)("signee", result.signee() ) );
......@@ -225,12 +226,10 @@ namespace eosio { namespace chain {
return digest_type::hash( std::make_pair(header_bmroot, pending_schedule_hash) );
}
void block_header_state::sign( const std::function<signature_type(const digest_type&)>& signer, bool trust ) {
void block_header_state::sign( const std::function<signature_type(const digest_type&)>& signer ) {
auto d = sig_digest();
header.producer_signature = signer( d );
if( !trust ) {
EOS_ASSERT( block_signing_key == fc::crypto::public_key( header.producer_signature, d ), wrong_signing_key, "block is signed with unexpected key" );
}
EOS_ASSERT( block_signing_key == fc::crypto::public_key( header.producer_signature, d ), wrong_signing_key, "block is signed with unexpected key" );
}
public_key_type block_header_state::signee()const {
......
......@@ -828,10 +828,10 @@ struct controller_impl {
void sign_block( const std::function<signature_type( const digest_type& )>& signer_callback, bool trust ) {
void sign_block( const std::function<signature_type( const digest_type& )>& signer_callback ) {
auto p = pending->_pending_block_state;
p->sign( signer_callback, false); //trust );
p->sign( signer_callback );
static_cast<signed_block_header&>(*p->block) = p->header;
} /// sign_block
......@@ -877,7 +877,12 @@ struct controller_impl {
}
finalize_block();
sign_block( [&]( const auto& ){ return b->producer_signature; }, false ); //trust );
// we can always trust this signature because,
// - prior to apply_block, we call fork_db.add which does a signature check IFF the block is untrusted
// - OTHERWISE the block is trusted and therefore we trust that the signature is valid
// Also, as ::sign_block does not lazily calculate the digest of the block, we can just short-circuit to save cycles
pending->_pending_block_state->header.producer_signature = b->producer_signature;
// this is implied by the signature passing
//FC_ASSERT( b->id() == pending->_pending_block_state->block->id(),
......@@ -1274,7 +1279,7 @@ void controller::finalize_block() {
}
void controller::sign_block( const std::function<signature_type( const digest_type& )>& signer_callback ) {
my->sign_block( signer_callback, false /* don't trust */);
my->sign_block( signer_callback );
}
void controller::commit_block() {
......
......@@ -49,7 +49,7 @@ struct block_header_state {
producer_key get_scheduled_producer( block_timestamp_type t )const;
const block_id_type& prev()const { return header.previous; }
digest_type sig_digest()const;
void sign( const std::function<signature_type(const digest_type&)>& signer, bool trust = false );
void sign( const std::function<signature_type(const digest_type&)>& signer );
public_key_type signee()const;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册