From 88cf43523e3fdc20cff19de113df321d4a8c5b0e Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 12 Apr 2017 09:15:57 -0500 Subject: [PATCH] Progress #5: Hash IDs for generated transactions As discussed on #5, use hashes as the generated_transaction_id_type instead of serial numbers. --- libraries/app/application.cpp | 2 ++ .../chain/include/eos/chain/protocol/types.hpp | 3 +-- libraries/chain/protocol/block.cpp | 13 ++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index c13eae4e41f..b4d95de4584 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -539,6 +539,8 @@ namespace detail { for (const auto& cycle : blk_msg.block.cycles) for (const auto& thread : cycle) for (const auto& transaction : thread.input_transactions) + // In theory, we can ignore generated transactions here, since they don't ever go bare over the + // network. Is this true?... if (transaction.which() == decay_t::tag::value) { eos::net::trx_message transaction_message(transaction.get()); contained_transaction_message_ids.push_back(eos::net::message(transaction_message).id()); diff --git a/libraries/chain/include/eos/chain/protocol/types.hpp b/libraries/chain/include/eos/chain/protocol/types.hpp index 8425736608b..54dd6d48811 100644 --- a/libraries/chain/include/eos/chain/protocol/types.hpp +++ b/libraries/chain/include/eos/chain/protocol/types.hpp @@ -123,13 +123,12 @@ namespace eos { namespace chain { using account_id_type = chainbase::oid; using producer_id_type = chainbase::oid; - using generated_transaction_id_type = uint32_t; using block_id_type = fc::ripemd160; using checksum_type = fc::ripemd160; using transaction_id_type = fc::ripemd160; using digest_type = fc::sha256; + using generated_transaction_id_type = fc::sha256; using signature_type = fc::ecc::compact_signature; - using share_type = safe; using weight_type = uint16_t; struct public_key_type diff --git a/libraries/chain/protocol/block.cpp b/libraries/chain/protocol/block.cpp index d783ef73809..eca99ccf056 100644 --- a/libraries/chain/protocol/block.cpp +++ b/libraries/chain/protocol/block.cpp @@ -91,9 +91,16 @@ namespace eos { namespace chain { vector ids; std::transform(input_transactions.begin(), input_transactions.end(), std::back_inserter(ids), [](const input_transaction& trx) { - if (trx.which() == input_transaction::tag::value) - return trx.get().merkle_digest(); -#warning How do I get the digest from a generated_transaction_id_type?... + struct { + using result_type = digest_type; + result_type operator() (const signed_transaction& t) { + return t.merkle_digest(); + } + result_type operator() (const generated_transaction_id_type& id) { + return id; + } + } digester; + return trx.visit(digester); }); std::transform(output_transactions.begin(), output_transactions.end(), std::back_inserter(ids), std::bind(&generated_transaction::merkle_digest, std::placeholders::_1));