Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static const std::map<BlockFilterType, std::string> g_filter_types = {
uint64_t GCSFilter::HashToRange(const Element& element) const
{
uint64_t hash = CSipHasher(m_params.m_siphash_k0, m_params.m_siphash_k1)
.Write(element.data(), element.size())
.Write(element)
.Finalize();
return FastRange64(hash, m_F);
}
Expand Down
3 changes: 2 additions & 1 deletion src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CBlock;
class CBlockHeader;
class CScript;
class CTransaction;
class SigningProvider;
class CTxUndo;
class uint256;
struct CMutableTransaction;
Expand Down Expand Up @@ -55,7 +56,7 @@ UniValue ValueFromAmount(const CAmount amount);
std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx);
std::string SighashToStr(unsigned char sighash_type);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false, const SigningProvider* provider = nullptr);
void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);

// evo/core_write.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ std::string EncodeHexTx(const CTransaction& tx)
return HexStr(ssTx);
}

void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address)
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address, const SigningProvider* provider)
{
CTxDestination address;

out.pushKV("asm", ScriptToAsmStr(script));
if (include_address) {
out.pushKV("desc", InferDescriptor(script, DUMMY_SIGNING_PROVIDER)->ToString());
out.pushKV("desc", InferDescriptor(script, provider ? *provider : DUMMY_SIGNING_PROVIDER)->ToString());
}
if (include_hex) {
out.pushKV("hex", HexStr(script));
Expand Down
7 changes: 4 additions & 3 deletions src/crypto/siphash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ CSipHasher& CSipHasher::Write(uint64_t data)
return *this;
}

CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
CSipHasher& CSipHasher::Write(Span<const unsigned char> data)
{
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
uint64_t t = tmp;
uint8_t c = count;

while (size--) {
t |= ((uint64_t)(*(data++))) << (8 * (c % 8));
while (data.size() > 0) {
t |= uint64_t{data.front()} << (8 * (c % 8));
c++;
if ((c & 7) == 0) {
v3 ^= t;
Expand All @@ -61,6 +61,7 @@ CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
v0 ^= t;
t = 0;
}
data = data.subspan(1);
}

v[0] = v0;
Expand Down
3 changes: 2 additions & 1 deletion src/crypto/siphash.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdint.h>

#include <span.h>
#include <uint256.h>

/** SipHash-2-4 */
Expand All @@ -26,7 +27,7 @@ class CSipHasher
*/
CSipHasher& Write(uint64_t data);
/** Hash arbitrary bytes. */
CSipHasher& Write(const unsigned char* data, size_t size);
CSipHasher& Write(Span<const unsigned char> data);
/** Compute the 64-bit SipHash-2-4 of the data written so far. The object remains untouched. */
uint64_t Finalize() const;
};
Expand Down
8 changes: 4 additions & 4 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ struct SaltedHasherImpl<llmq::CQuorumDataRequestKey>
static std::size_t CalcHash(const llmq::CQuorumDataRequestKey& v, uint64_t k0, uint64_t k1)
{
CSipHasher c(k0, k1);
c.Write(reinterpret_cast<const unsigned char*>(&v.proRegTx), sizeof(v.proRegTx));
c.Write(reinterpret_cast<const unsigned char*>(&v.m_we_requested), sizeof(v.m_we_requested));
c.Write(reinterpret_cast<const unsigned char*>(&v.quorumHash), sizeof(v.quorumHash));
c.Write(reinterpret_cast<const unsigned char*>(&v.llmqType), sizeof(v.llmqType));
c.Write(Span{reinterpret_cast<const unsigned char*>(&v.proRegTx), sizeof(v.proRegTx)});
c.Write(Span{reinterpret_cast<const unsigned char*>(&v.m_we_requested), sizeof(v.m_we_requested)});
c.Write(Span{reinterpret_cast<const unsigned char*>(&v.quorumHash), sizeof(v.quorumHash)});
c.Write(Span{reinterpret_cast<const unsigned char*>(&v.llmqType), sizeof(v.llmqType)});
return c.Finalize();
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4267,7 +4267,7 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
auto local_socket_bytes = requestor.addrBind.GetAddrBytes();
uint64_t cache_id = GetDeterministicRandomizer(RANDOMIZER_ID_ADDRCACHE)
.Write(requestor.ConnectedThroughNetwork())
.Write(local_socket_bytes.data(), local_socket_bytes.size())
.Write(local_socket_bytes)
// For outbound connections, the port of the bound address is randomly
// assigned by the OS and would therefore not be useful for seeding.
.Write(requestor.IsInboundConn() ? requestor.addrBind.GetPort() : 0)
Expand Down Expand Up @@ -4974,7 +4974,7 @@ uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& address) const
{
std::vector<unsigned char> vchNetGroup(m_netgroupman.GetGroup(address));

return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup).Finalize();
}

void CConnman::PerformReconnections()
Expand Down
2 changes: 1 addition & 1 deletion src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class CServiceHash
CSipHasher hasher(m_salt_k0, m_salt_k1);
hasher.Write(a.m_net);
hasher.Write(a.port);
hasher.Write(a.m_addr.data(), a.m_addr.size());
hasher.Write(a.m_addr);
return static_cast<size_t>(hasher.Finalize());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class AddrManDeterministic : public AddrMan
hasher.Write(a.source.GetNetwork());
hasher.Write(addr_key.size());
hasher.Write(source_key.size());
hasher.Write(addr_key.data(), addr_key.size());
hasher.Write(source_key.data(), source_key.size());
hasher.Write(addr_key);
hasher.Write(source_key);
return (size_t)hasher.Finalize();
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FUZZ_TARGET(crypto)
(void)sha256.Write(data.data(), data.size());
(void)sha3.Write(data);
(void)sha512.Write(data.data(), data.size());
(void)sip_hasher.Write(data.data(), data.size());
(void)sip_hasher.Write(data);

(void)Hash(data);
(void)Hash160(data);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/golomb_rice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace {
uint64_t HashToRange(const std::vector<uint8_t>& element, const uint64_t f)
{
const uint64_t hash = CSipHasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL)
.Write(element.data(), element.size())
.Write(element)
.Finalize();
return FastRange64(hash, f);
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/hash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ BOOST_AUTO_TEST_CASE(siphash)
CSipHasher hasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x726fdb47dd0e0e31ull);
static const unsigned char t0[1] = {0};
hasher.Write(t0, 1);
hasher.Write(t0);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x74f839c593dc67fdull);
static const unsigned char t1[7] = {1,2,3,4,5,6,7};
hasher.Write(t1, 7);
hasher.Write(t1);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x93f5f5799a932462ull);
hasher.Write(0x0F0E0D0C0B0A0908ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x3f2acc7f57c29bdbull);
static const unsigned char t2[2] = {16,17};
hasher.Write(t2, 2);
hasher.Write(t2);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x4bc1b3f0968dd39cull);
static const unsigned char t3[9] = {18,19,20,21,22,23,24,25,26};
hasher.Write(t3, 9);
hasher.Write(t3);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x2f2e6163076bcfadull);
static const unsigned char t4[5] = {27,28,29,30,31};
hasher.Write(t4, 5);
hasher.Write(t4);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x7127512f72f27cceull);
hasher.Write(0x2726252423222120ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x0e3ea96b5304a7d0ull);
Expand All @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(siphash)
for (uint8_t x=0; x<std::size(siphash_4_2_testvec); ++x)
{
BOOST_CHECK_EQUAL(hasher2.Finalize(), siphash_4_2_testvec[x]);
hasher2.Write(&x, 1);
hasher2.Write(Span{&x, 1});
}
// Check test vectors from spec, eight bytes at a time
CSipHasher hasher3(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
Expand Down Expand Up @@ -139,9 +139,9 @@ BOOST_AUTO_TEST_CASE(siphash)
uint8_t nb[4];
WriteLE32(nb, n);
CSipHasher sip256(k1, k2);
sip256.Write(x.begin(), 32);
sip256.Write(x);
CSipHasher sip288 = sip256;
sip288.Write(nb, 4);
sip288.Write(nb);
BOOST_CHECK_EQUAL(SipHashUint256(k1, k2, x), sip256.Finalize());
BOOST_CHECK_EQUAL(SipHashUint256Extra(k1, k2, x, n), sip288.Finalize());
}
Expand Down
2 changes: 1 addition & 1 deletion src/txrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PriorityComputer {

Priority operator()(const CInv& inv, NodeId peer, bool preferred) const
{
uint64_t low_bits = CSipHasher(m_k0, m_k1).Write(inv.hash.begin(), inv.hash.size()).Write(inv.type).Write(peer).Finalize() >> 1;
uint64_t low_bits = CSipHasher(m_k0, m_k1).Write(inv.hash).Write(inv.type).Write(peer).Finalize() >> 1;
return low_bits | uint64_t{preferred} << 63;
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/bytevectorhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ByteVectorHash::ByteVectorHash() :

size_t ByteVectorHash::operator()(const std::vector<unsigned char>& input) const
{
return CSipHasher(m_k0, m_k1).Write(input.data(), input.size()).Finalize();
return CSipHasher(m_k0, m_k1).Write(input).Finalize();
}
2 changes: 1 addition & 1 deletion src/util/hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ SaltedSipHasher::SaltedSipHasher() : m_k0(GetRand<uint64_t>()), m_k1(GetRand<uin

size_t SaltedSipHasher::operator()(const Span<const unsigned char>& script) const
{
return CSipHasher(m_k0, m_k1).Write(script.data(), script.size()).Finalize();
return CSipHasher(m_k0, m_k1).Write(script).Finalize();
}
15 changes: 0 additions & 15 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from decimal import Decimal

from test_framework.messages import (
COIN,
DEFAULT_ANCESTOR_LIMIT,
DEFAULT_DESCENDANT_LIMIT,
)
Expand All @@ -26,9 +25,6 @@


class MempoolPackagesTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
Expand All @@ -47,10 +43,6 @@ def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
self.wallet.rescan_utxos()

if self.is_specified_wallet_compiled():
self.nodes[0].createwallet("watch_wallet", disable_private_keys=True)
self.nodes[0].importaddress(self.wallet.get_address())

peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs

# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
Expand All @@ -63,13 +55,6 @@ def run_test(self):
ancestor_vsize += t["tx"].get_vsize()
ancestor_fees += t["fee"]
self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=t["hex"])
# Check that listunspent ancestor{count, size, fees} yield the correct results
if self.is_specified_wallet_compiled():
wallet_unspent = self.nodes[0].listunspent(minconf=0)
this_unspent = next(utxo_info for utxo_info in wallet_unspent if utxo_info["txid"] == t["txid"])
assert_equal(this_unspent['ancestorcount'], i + 1)
assert_equal(this_unspent['ancestorsize'], ancestor_vsize)
assert_equal(this_unspent['ancestorfees'], ancestor_fees * COIN)

# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between
Expand Down
33 changes: 33 additions & 0 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

from test_framework.blocktools import COINBASE_MATURITY
from test_framework.descriptors import descsum_create
from test_framework.messages import (
COIN,
DEFAULT_ANCESTOR_LIMIT,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_array_result,
Expand All @@ -19,6 +23,7 @@
find_vout_for_address,
)
from test_framework.wallet_util import test_address
from test_framework.wallet import MiniWallet

NOT_A_NUMBER_OR_STRING = "Amount is not a number or string"
OUT_OF_RANGE = "Amount out of range"
Expand Down Expand Up @@ -828,6 +833,34 @@ def run_test(self):

zeroconf_wallet.sendtoaddress(zeroconf_wallet.getnewaddress(), Decimal('0.5'))

self.test_chain_listunspent()

def test_chain_listunspent(self):
if not self.options.descriptors:
return
self.wallet = MiniWallet(self.nodes[0])
self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(self.wallet.get_address(), "5")
self.generate(self.wallet, 1, sync_fun=self.no_op)
self.nodes[0].createwallet("watch_wallet", disable_private_keys=True)
watch_wallet = self.nodes[0].get_wallet_rpc("watch_wallet")
watch_wallet.importaddress(self.wallet.get_address())
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
chain = self.wallet.create_self_transfer_chain(chain_length=DEFAULT_ANCESTOR_LIMIT)
ancestor_vsize = 0
ancestor_fees = Decimal(0)

for i, t in enumerate(chain):
ancestor_vsize += t["tx"].get_vsize()
ancestor_fees += t["fee"]
self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=t["hex"])
# Check that listunspent ancestor{count, size, fees} yield the correct results
wallet_unspent = watch_wallet.listunspent(minconf=0)
this_unspent = next(utxo_info for utxo_info in wallet_unspent if utxo_info["txid"] == t["txid"])
assert_equal(this_unspent['ancestorcount'], i + 1)
assert_equal(this_unspent['ancestorsize'], ancestor_vsize)
assert_equal(this_unspent['ancestorfees'], ancestor_fees * COIN)


if __name__ == '__main__':
WalletTest().main()
Loading