diff --git a/src/common.h b/src/common.h index 73700e0..8bf011b 100644 --- a/src/common.h +++ b/src/common.h @@ -210,6 +210,22 @@ struct alignas(uint64_t) hash FORCEINLINE uint64_t* u64() { return reinterpret_cast(h); } FORCEINLINE const uint64_t* u64() const { return reinterpret_cast(h); } + template + FORCEINLINE constexpr uint64_t u64() const + { + if constexpr ((index < 0) || (index >= HASH_SIZE / sizeof(uint64_t))) { + return 0; + } + + uint64_t k = 0; + + for (size_t i = 0; i < sizeof(uint64_t); ++i) { + k |= static_cast(h[index * sizeof(uint64_t) + i]) << (i * sizeof(uint64_t)); + } + + return k; + } + friend std::ostream& operator<<(std::ostream& s, const hash& d); friend std::istream& operator>>(std::istream& s, hash& d); }; diff --git a/src/keccak_constexpr.h b/src/keccak_constexpr.h index 620134a..20989fa 100644 --- a/src/keccak_constexpr.h +++ b/src/keccak_constexpr.h @@ -28,7 +28,7 @@ static FORCEINLINE constexpr uint64_t rotl64(uint64_t x) { return (x << y) | (x template static FORCEINLINE constexpr void keccakf(std::array& st) { - constexpr uint64_t keccakf_rndc[24] = + constexpr uint64_t round_constants[24] = { 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, @@ -85,7 +85,7 @@ static FORCEINLINE constexpr void keccakf(std::array& st) } // Iota - st[0] ^= keccakf_rndc[round]; + st[0] ^= round_constants[round]; } } @@ -139,6 +139,6 @@ constexpr hash keccak_0x00 = keccak("\0"); constexpr hash keccak_subaddress_viewpub = keccak("subaddress_viewpub"); constexpr hash keccak_onion_address_v3 = keccak("onion_address_v3"); -static_assert((keccak_0x00.h[0] == 0xBC) && (keccak_0x00.h[1] == 0x36) && (keccak_0x00.h[2] == 0x78) && (keccak_0x00.h[3] == 0x9E), "constexpr keccak code check failed"); +static_assert(keccak_0x00.u64<0>() == 0x14281E7A9E7836BCULL, "constexpr keccak code check failed"); } // namespace p2pool diff --git a/src/merge_mining_client_tari.cpp b/src/merge_mining_client_tari.cpp index 05e23ff..4ac0b7b 100644 --- a/src/merge_mining_client_tari.cpp +++ b/src/merge_mining_client_tari.cpp @@ -997,6 +997,10 @@ bool MergeMiningClientTari::TariClient::on_connect() // Check if the incoming connection (downstream) has already sent something that needs to be relayed TariClient* downstream = m_pairedClient; + if (!downstream) { + return false; + } + const std::vector& v = downstream->m_pendingData; if (!v.empty()) {