Skip to content

Commit

Permalink
Merge #2460: Reorder C{,Mutable}Transaction for better packing
Browse files Browse the repository at this point in the history
c602135 Reorder C{,Mutable}Transaction for better packing (random-zebra)

Pull request description:

  Adapts bitcoin#8330.

  `sizeof(CTransaction)` and `sizeof(CMutableTransaction)` show a reduction of 8 bytes.

ACKs for top commit:
  furszy:
    interesting PR, tested ACK c602135.

Tree-SHA512: d35713d6ad10757fb7477428ef11f14c7dda30312003031ba24271b50556eb6e6b9a0ecc1af2c49b0d916bf8ec4f2c78bc55cf32befb43b12bcbb6c9715dad75
  • Loading branch information
furszy committed Jul 19, 2021
2 parents 3614de6 + c602135 commit a306efd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::string CTxOut::ToString() const
}

CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(CTransaction::TxType::NORMAL), nLockTime(0) {}
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), nType(tx.nType), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload) {}
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload) {}

uint256 CMutableTransaction::GetHash() const
{
Expand All @@ -127,9 +127,9 @@ size_t CTransaction::DynamicMemoryUsage() const
}

/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(TxType::NORMAL), vin(), vout(), nLockTime(0), hash() {}
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), nType(tx.nType), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload), hash(ComputeHash()) {}
CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), nType(tx.nType), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload), hash(ComputeHash()) {}
CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nType(TxType::NORMAL), nLockTime(0), hash() {}
CTransaction::CTransaction(const CMutableTransaction &tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload), hash(ComputeHash()) {}
CTransaction::CTransaction(CMutableTransaction &&tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), sapData(tx.sapData), extraPayload(tx.extraPayload), hash(ComputeHash()) {}

bool CTransaction::HasZerocoinSpendInputs() const
{
Expand Down
8 changes: 4 additions & 4 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ class CTransaction
// actually immutable; deserialization and assignment are implemented,
// and bypass the constness. This is safe, as they update the entire
// structure, including the hash.
const int16_t nVersion;
const int16_t nType;
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
const int16_t nVersion;
const int16_t nType;
const uint32_t nLockTime;
Optional<SaplingTxData> sapData{SaplingTxData()}; // Future: Don't initialize it by default
Optional<std::vector<uint8_t>> extraPayload{nullopt}; // only available for special transaction types
Expand Down Expand Up @@ -403,10 +403,10 @@ class CTransaction
/** A mutable version of CTransaction. */
struct CMutableTransaction
{
int16_t nVersion;
int16_t nType;
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
int16_t nVersion;
int16_t nType;
uint32_t nLockTime;
Optional<SaplingTxData> sapData{SaplingTxData()}; // Future: Don't initialize it by default
Optional<std::vector<uint8_t>> extraPayload{nullopt};
Expand Down

0 comments on commit a306efd

Please sign in to comment.