Problem: P2Pool nodes starting at different times or experiencing network issues would create independent genesis blocks, resulting in incompatible chains. Nodes would ban each other for invalid blocks that were actually valid on a different chain. Cache resume after restart frequently failed due to genesis mismatch between nodes. Solution: Oldest compatible genesis wins protocol that coordinates genesis selection across peers before mining begins. New P2P message GENESIS_INFO exchanges: - Genesis block hash - Genesis timestamp - Genesis mainchain height - Protocol version Startup behavior: - Wait up to 90 seconds for peer genesis info (with progress logging) - Adopt oldest genesis from compatible peers - Only create own genesis if no peers respond Late joiner reconciliation: - Running nodes that receive older genesis from new peer will purge their sidechain and re-sync to the older chain - Cache files deleted on purge to prevent reload of stale blocks Protocol versioning: - PROTOCOL_VERSION constant at top of side_chain.h - Increment only on consensus-breaking changes - Version mismatch logs warning, prevents genesis adoption Tiebreaker: When timestamps match, lexicographically lower hash wins.
72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
/*
|
|
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
|
* Copyright (c) 2021-2025 SChernykh <https://github.com/SChernykh>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "uv_util.h"
|
|
|
|
namespace p2pool {
|
|
|
|
class Wallet
|
|
{
|
|
public:
|
|
static constexpr int ADDRESS_LENGTH = 97;
|
|
|
|
explicit Wallet(const char* address);
|
|
|
|
Wallet(const Wallet& w);
|
|
Wallet& operator=(const Wallet& w);
|
|
|
|
[[nodiscard]] FORCEINLINE bool valid() const { return m_type != NetworkType::Invalid; }
|
|
|
|
[[nodiscard]] bool decode(const char* address);
|
|
[[nodiscard]] bool assign(const hash& spend_pub_key, const hash& view_pub_key, NetworkType type, bool subaddress);
|
|
|
|
void encode(char (&buf)[ADDRESS_LENGTH]) const;
|
|
|
|
[[nodiscard]] FORCEINLINE std::string encode() const
|
|
{
|
|
char buf[ADDRESS_LENGTH];
|
|
encode(buf);
|
|
return std::string(buf, buf + ADDRESS_LENGTH);
|
|
}
|
|
|
|
[[nodiscard]] bool get_eph_public_key(const hash& txkey_sec, size_t output_index, hash& eph_public_key, uint8_t& view_tag, const uint8_t* expected_view_tag = nullptr) const;
|
|
[[nodiscard]] bool get_eph_public_key_carrot(const hash& tx_key_seed, uint64_t height, size_t output_index, uint64_t amount, hash& eph_public_key, uint8_t& view_tag) const;
|
|
|
|
FORCEINLINE bool operator<(const Wallet& w) const { return (m_spendPublicKey < w.m_spendPublicKey) || ((m_spendPublicKey == w.m_spendPublicKey) && (m_viewPublicKey < w.m_viewPublicKey)); }
|
|
FORCEINLINE bool operator==(const Wallet& w) const { return (m_spendPublicKey == w.m_spendPublicKey) && (m_viewPublicKey == w.m_viewPublicKey); }
|
|
|
|
[[nodiscard]] FORCEINLINE uint64_t prefix() const { return m_prefix; }
|
|
[[nodiscard]] FORCEINLINE const hash& spend_public_key() const { return m_spendPublicKey; }
|
|
[[nodiscard]] FORCEINLINE const hash& view_public_key() const { return m_viewPublicKey; }
|
|
[[nodiscard]] FORCEINLINE uint32_t checksum() const { return m_checksum; }
|
|
[[nodiscard]] FORCEINLINE NetworkType type() const { return m_type; }
|
|
[[nodiscard]] FORCEINLINE bool is_subaddress() const { return m_subaddress; }
|
|
[[nodiscard]] bool torsion_check() const;
|
|
|
|
private:
|
|
uint64_t m_prefix;
|
|
hash m_spendPublicKey;
|
|
hash m_viewPublicKey;
|
|
uint32_t m_checksum;
|
|
NetworkType m_type;
|
|
bool m_subaddress;
|
|
};
|
|
|
|
} // namespace p2pool
|