refactor: Use uint64_t over size_t for serialized-size values
The values are small enough to fit in size_t, but to avoid having to think about it, just use uint64_t consistently for all architectures. On 64-bit systems, this refactor is a no-op. On 32-bit systems, it could avoid bugs in the theoretical and unexpected case where a 32-bit size_t is too small and overflows.
This commit is contained in:
9 files changed
+13
-13
No files matched your search
+2
-2
@@ -349,8 +349,8 @@ void CCoinsViewCache::SanityCheck() const
|
|||||||
assert(recomputed_usage == cachedCoinsUsage);
|
assert(recomputed_usage == cachedCoinsUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
|
static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT{WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut())};
|
||||||
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
|
static const uint64_t MAX_OUTPUTS_PER_BLOCK{MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT};
|
||||||
|
|
||||||
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
|
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -202,9 +202,9 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter&
|
|||||||
{
|
{
|
||||||
assert(filter.GetFilterType() == GetFilterType());
|
assert(filter.GetFilterType() == GetFilterType());
|
||||||
|
|
||||||
size_t data_size =
|
uint64_t data_size{
|
||||||
GetSerializeSize(filter.GetBlockHash()) +
|
GetSerializeSize(filter.GetBlockHash()) +
|
||||||
GetSerializeSize(filter.GetEncodedFilter());
|
GetSerializeSize(filter.GetEncodedFilter())};
|
||||||
|
|
||||||
// If writing the filter would overflow the file, flush and move to the next one.
|
// If writing the filter would overflow the file, flush and move to the next one.
|
||||||
if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) {
|
if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
|
|||||||
if (txout.scriptPubKey.IsUnspendable())
|
if (txout.scriptPubKey.IsUnspendable())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t nSize = GetSerializeSize(txout);
|
uint64_t nSize{GetSerializeSize(txout)};
|
||||||
int witnessversion = 0;
|
int witnessversion = 0;
|
||||||
std::vector<unsigned char> witnessprogram;
|
std::vector<unsigned char> witnessprogram;
|
||||||
|
|
||||||
|
|||||||
@@ -2033,7 +2033,7 @@ static RPCHelpMan getblockstats()
|
|||||||
for (const CTxOut& out : tx->vout) {
|
for (const CTxOut& out : tx->vout) {
|
||||||
tx_total_out += out.nValue;
|
tx_total_out += out.nValue;
|
||||||
|
|
||||||
size_t out_size = GetSerializeSize(out) + PER_UTXO_OVERHEAD;
|
uint64_t out_size{GetSerializeSize(out) + PER_UTXO_OVERHEAD};
|
||||||
utxo_size_inc += out_size;
|
utxo_size_inc += out_size;
|
||||||
|
|
||||||
// The Genesis block and the repeated BIP30 block coinbases don't change the UTXO
|
// The Genesis block and the repeated BIP30 block coinbases don't change the UTXO
|
||||||
@@ -2085,7 +2085,7 @@ static RPCHelpMan getblockstats()
|
|||||||
const CTxOut& prevoutput = coin.out;
|
const CTxOut& prevoutput = coin.out;
|
||||||
|
|
||||||
tx_total_in += prevoutput.nValue;
|
tx_total_in += prevoutput.nValue;
|
||||||
size_t prevout_size = GetSerializeSize(prevoutput) + PER_UTXO_OVERHEAD;
|
uint64_t prevout_size{GetSerializeSize(prevoutput) + PER_UTXO_OVERHEAD};
|
||||||
utxo_size_inc -= prevout_size;
|
utxo_size_inc -= prevout_size;
|
||||||
utxo_size_inc_actual -= prevout_size;
|
utxo_size_inc_actual -= prevout_size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ BOOST_AUTO_TEST_CASE(flatfile_open)
|
|||||||
std::string line2("Digital signatures provide part of the solution, but the main benefits are "
|
std::string line2("Digital signatures provide part of the solution, but the main benefits are "
|
||||||
"lost if a trusted third party is still required to prevent double-spending.");
|
"lost if a trusted third party is still required to prevent double-spending.");
|
||||||
|
|
||||||
size_t pos1 = 0;
|
uint64_t pos1{0};
|
||||||
size_t pos2 = pos1 + GetSerializeSize(line1);
|
uint64_t pos2{pos1 + GetSerializeSize(line1)};
|
||||||
|
|
||||||
// Write first line to file.
|
// Write first line to file.
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1120,7 +1120,7 @@ void TestNode(const MsCtx script_ctx, const NodeRef& node, FuzzedDataProvider& p
|
|||||||
assert(mal_success);
|
assert(mal_success);
|
||||||
assert(stack_nonmal == stack_mal);
|
assert(stack_nonmal == stack_mal);
|
||||||
// Compute witness size (excluding script push, control block, and witness count encoding).
|
// Compute witness size (excluding script push, control block, and witness count encoding).
|
||||||
const size_t wit_size = GetSerializeSize(stack_nonmal) - GetSizeOfCompactSize(stack_nonmal.size());
|
const uint64_t wit_size{GetSerializeSize(stack_nonmal) - GetSizeOfCompactSize(stack_nonmal.size())};
|
||||||
assert(wit_size <= *node->GetWitnessSize());
|
assert(wit_size <= *node->GetWitnessSize());
|
||||||
|
|
||||||
// Test non-malleable satisfaction.
|
// Test non-malleable satisfaction.
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||||||
tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 0 fee
|
tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 0 fee
|
||||||
Txid hashFreeTx = tx.GetHash();
|
Txid hashFreeTx = tx.GetHash();
|
||||||
AddToMempool(tx_mempool, entry.Fee(0).FromTx(tx));
|
AddToMempool(tx_mempool, entry.Fee(0).FromTx(tx));
|
||||||
size_t freeTxSize = ::GetSerializeSize(TX_WITH_WITNESS(tx));
|
uint64_t freeTxSize{::GetSerializeSize(TX_WITH_WITNESS(tx))};
|
||||||
|
|
||||||
// Calculate a fee on child transaction that will put the package just
|
// Calculate a fee on child transaction that will put the package just
|
||||||
// below the block min tx fee (assuming 1 child tx of the same size).
|
// below the block min tx fee (assuming 1 child tx of the same size).
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ void TestSatisfy(const KeyConverter& converter, const std::string& testcase, con
|
|||||||
CScriptWitness witness_nonmal;
|
CScriptWitness witness_nonmal;
|
||||||
const bool nonmal_success = node->Satisfy(satisfier, witness_nonmal.stack, true) == miniscript::Availability::YES;
|
const bool nonmal_success = node->Satisfy(satisfier, witness_nonmal.stack, true) == miniscript::Availability::YES;
|
||||||
// Compute witness size (excluding script push, control block, and witness count encoding).
|
// Compute witness size (excluding script push, control block, and witness count encoding).
|
||||||
const size_t wit_size = GetSerializeSize(witness_nonmal.stack) - GetSizeOfCompactSize(witness_nonmal.stack.size());
|
const uint64_t wit_size{GetSerializeSize(witness_nonmal.stack) - GetSizeOfCompactSize(witness_nonmal.stack.size())};
|
||||||
SatisfactionToWitness(converter.MsContext(), witness_nonmal, script, builder);
|
SatisfactionToWitness(converter.MsContext(), witness_nonmal, script, builder);
|
||||||
|
|
||||||
if (nonmal_success) {
|
if (nonmal_success) {
|
||||||
|
|||||||
@@ -1034,7 +1034,7 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetSerializeSizeForRecipient(const CRecipient& recipient)
|
uint64_t GetSerializeSizeForRecipient(const CRecipient& recipient)
|
||||||
{
|
{
|
||||||
return ::GetSerializeSize(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)));
|
return ::GetSerializeSize(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user