1
0
Fork 0
forked from lthn/blockchain

changed currency_protocol_handler for onboard transactions

This commit is contained in:
cryptozoidberg 2019-11-16 21:25:48 +01:00
parent 57e0aa063d
commit 6019ffccf8
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 17 additions and 91 deletions

View file

@ -3,7 +3,6 @@ if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD)
endif()
###########
# using shared PCH -- this is unusual case for MSVC... so mystery, such hack, many wow. See also: https://stackoverflow.com/questions/645747/sharing-precompiled-headers-between-projects-in-visual-studio/4170902#4170902
# define USE_PCH to YES for using precomiled headers

View file

@ -6,6 +6,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <unordered_map>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>

View file

@ -2426,7 +2426,10 @@ namespace currency
return true;
return false;
}
size_t get_max_block_size()
{
return CURRENCY_MAX_BLOCK_SIZE;
}
//-----------------------------------------------------------------------------------------------
uint64_t get_base_block_reward(bool is_pos, const boost::multiprecision::uint128_t& already_generated_coins, uint64_t height)
{

View file

@ -91,89 +91,4 @@ namespace currency
return true;
}
//---------------------------------------------------------------
bool get_transaction_hash(const transaction& t, crypto::hash& res)
{
uint64_t blob_size = 0;
return get_object_hash(static_cast<const transaction_prefix&>(t), res, blob_size);
}
//---------------------------------------------------------------
bool get_transaction_hash(const transaction& t, crypto::hash& res, uint64_t& blob_size)
{
blob_size = 0;
bool r = get_object_hash(static_cast<const transaction_prefix&>(t), res, blob_size);
blob_size = get_object_blobsize(t, blob_size);
return r;
}
//---------------------------------------------------------------
size_t get_object_blobsize(const transaction& t)
{
size_t tx_blob_size = get_object_blobsize(static_cast<const transaction_prefix&>(t));
return get_object_blobsize(t, tx_blob_size);
}
//---------------------------------------------------------------
size_t get_objects_blobsize(const std::list<transaction>& ls)
{
size_t total = 0;
for (const auto& tx : ls)
{
total += get_object_blobsize(tx);
}
return total;
}
//---------------------------------------------------------------
size_t get_object_blobsize(const transaction& t, uint64_t prefix_blob_size)
{
size_t tx_blob_size = prefix_blob_size;
if (is_coinbase(t))
return tx_blob_size;
// for purged tx, with empty signatures and attachments, this function should return the blob size
// which the tx would have if the signatures and attachments were correctly filled with actual data
// 1. signatures
bool separately_signed_tx = get_tx_flags(t) & TX_FLAG_SIGNATURE_MODE_SEPARATE;
tx_blob_size += tools::get_varint_packed_size(t.vin.size()); // size of transaction::signatures (equals to total inputs count)
for (size_t i = 0; i != t.vin.size(); i++)
{
size_t sig_count = get_input_expected_signatures_count(t.vin[i]);
if (separately_signed_tx && i == t.vin.size() - 1)
++sig_count; // count in one more signature for the last input in a complete separately signed tx
tx_blob_size += tools::get_varint_packed_size(sig_count); // size of transaction::signatures[i]
tx_blob_size += sizeof(crypto::signature) * sig_count; // size of signatures' data itself
}
// 2. attachments (try to find extra_attachment_info in tx prefix and count it in if succeed)
extra_attachment_info eai = AUTO_VAL_INIT(eai);
bool got_eai = false;
if (separately_signed_tx)
{
// for separately-signed tx, try to obtain extra_attachment_info from the last input's etc_details
const std::vector<txin_etc_details_v>* p_etc_details = get_input_etc_details(t.vin.back());
got_eai = p_etc_details != nullptr && get_type_in_variant_container(*p_etc_details, eai);
}
if (!got_eai)
got_eai = get_type_in_variant_container(t.extra, eai); // then from the extra
if (got_eai)
tx_blob_size += eai.sz; // sz is a size of whole serialized attachment blob, including attachments vector size
else
tx_blob_size += tools::get_varint_packed_size(static_cast<size_t>(0)); // no extra_attachment_info found - just add zero vector's size, 'cause it's serialized anyway
return tx_blob_size;
}
//---------------------------------------------------------------
blobdata tx_to_blob(const transaction& tx)
{
return t_serializable_object_to_blob(tx);
}
//---------------------------------------------------------------
bool tx_to_blob(const transaction& tx, blobdata& b_blob)
{
return t_serializable_object_to_blob(tx, b_blob);
}
}

View file

@ -305,14 +305,22 @@ namespace currency
//now actually process block
for(auto tx_blob_it = arg.b.txs.begin(); tx_blob_it!=arg.b.txs.end();tx_blob_it++)
{
currency::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
m_core.handle_incoming_tx(*tx_blob_it, tvc, true);
if(tvc.m_verification_failed)
if (tx_blob_it->size() > CURRENCY_MAX_TRANSACTION_BLOB_SIZE)
{
LOG_PRINT_L0("Block verification failed: transaction verification failed, dropping connection");
LOG_ERROR("WRONG TRANSACTION BLOB, too big size " << tx_blob_it->size() << ", rejected");
m_p2p->drop_connection(context);
return 1;
}
crypto::hash tx_hash = null_hash;
transaction tx;
if (!parse_and_validate_tx_from_blob(*tx_blob_it, tx, tx_hash))
{
LOG_ERROR("WRONG TRANSACTION BLOB, Failed to parse, rejected");
m_p2p->drop_connection(context);
return 1;
}
bvc.m_onboard_transactions[tx_hash] = tx;
}
m_core.pause_mine();