Skip to content

Commit

Permalink
No longer extract public keys before pushing a trx
Browse files Browse the repository at this point in the history
and removed unused new added constructor and _get_signature_keys() function from signed_transaction struct
  • Loading branch information
abitmore authored and gladcow committed Sep 20, 2019
1 parent 2dfb67e commit 106824c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 47 deletions.
20 changes: 5 additions & 15 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,9 @@ namespace graphene { namespace app {
void network_broadcast_api::broadcast_transaction(const signed_transaction& trx)
{
trx.validate();

auto& chain_db = *_app.chain_database();
chain_db.check_tansaction_for_duplicated_operations(trx);
trx.get_signature_keys( chain_db.get_chain_id() ); // Extract public keys from signatures
chain_db.push_transaction( trx );

if( _app.p2p_node() != nullptr )
_app.p2p_node()->broadcast_transaction(trx);
_app.chain_database()->check_tansaction_for_duplicated_operations(trx);
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
}

fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
Expand All @@ -201,13 +196,8 @@ namespace graphene { namespace app {
{
trx.validate();
_callbacks[trx.id()] = cb;

auto& chain_db = *_app.chain_database();
trx.get_signature_keys( chain_db.get_chain_id() ); // Extract public keys from signatures
chain_db.push_transaction( trx );

if( _app.p2p_node() != nullptr )
_app.p2p_node()->broadcast_transaction(trx);
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
}

network_node_api::network_node_api( application& a ) : _app( a )
Expand Down
3 changes: 0 additions & 3 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,6 @@ namespace detail {
}
}

transaction_message.trx.get_signature_keys( get_chain_id() ); // Extract public keys from signatures

_chain_db->push_transaction( transaction_message.trx );
return result;
} catch ( const graphene::chain::unlinkable_block_exception& e ) {
// translate to a graphene::net exception
Expand Down
11 changes: 0 additions & 11 deletions libraries/chain/include/graphene/chain/protocol/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ namespace graphene { namespace chain {
signed_transaction( const transaction& trx = transaction() )
: transaction(trx){}

/** Extract public keys from signatures when initializing with another signed transaction and a chain ID */
signed_transaction( const signed_transaction& trx, const chain_id_type& chain_id )
: signed_transaction(trx)
{
signees = _get_signature_keys( chain_id );
}

/** signs and appends to signatures */
const signature_type& sign( const private_key_type& key, const chain_id_type& chain_id );

Expand Down Expand Up @@ -196,10 +189,6 @@ namespace graphene { namespace chain {

/// Removes all signatures and signees
void clear_signatures() { signatures.clear(); signees.clear(); }

private:
/// To be used by constructor and get_signature_keys() function
flat_set<public_key_type> _get_signature_keys( const chain_id_type& chain_id )const;
};

void verify_authority( const vector<operation>& ops, const flat_set<public_key_type>& sigs,
Expand Down
28 changes: 11 additions & 17 deletions libraries/chain/protocol/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,32 +299,26 @@ void verify_authority( const vector<operation>& ops, const flat_set<public_key_t


const flat_set<public_key_type>& signed_transaction::get_signature_keys( const chain_id_type& chain_id )const
{
{ try {
// Strictly we should check whether the given chain ID is same as the one used to initialize the `signees` field.
// However, we don't pass in another chain ID so far, for better performance, we skip the check.
if( signees.empty() && !signatures.empty() )
{
signees = _get_signature_keys( chain_id );
auto d = sig_digest( chain_id );
flat_set<public_key_type> result;
for( const auto& sig : signatures )
{
GRAPHENE_ASSERT(
result.insert( fc::ecc::public_key(sig,d) ).second,
tx_duplicate_sig,
"Duplicate Signature detected" );
}
signees = std::move( result );
}
return signees;
}

flat_set<public_key_type> signed_transaction::_get_signature_keys( const chain_id_type& chain_id )const
{ try {
auto d = sig_digest( chain_id );
flat_set<public_key_type> result;
for( const auto& sig : signatures )
{
GRAPHENE_ASSERT(
result.insert( fc::ecc::public_key(sig,d) ).second,
tx_duplicate_sig,
"Duplicate Signature detected" );
}
return result;
} FC_CAPTURE_AND_RETHROW() }



set<public_key_type> signed_transaction::get_required_signatures(
const chain_id_type& chain_id,
const flat_set<public_key_type>& available_keys,
Expand Down
Binary file modified programs/build_helpers/cat-parts
Binary file not shown.
1 change: 0 additions & 1 deletion tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,6 @@ bool _push_block( database& db, const signed_block& b, uint32_t skip_flags /* =

processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags /* = 0 */ )
{ try {
tx.get_signature_keys( db.get_chain_id() ); // Extract public keys from signatures
auto pt = db.push_transaction( tx, skip_flags );
database_fixture::verify_asset_supplies(db);
return pt;
Expand Down

0 comments on commit 106824c

Please sign in to comment.