p2pool/src/merge_mining_client_tari.h

121 lines
3.2 KiB
C
Raw Normal View History

2024-02-06 16:20:58 +00:00
/*
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
* Copyright (c) 2021-2024 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 "tcp_server.h"
#include "Tari/proto.h"
2024-02-06 16:20:58 +00:00
namespace p2pool {
class p2pool;
class MergeMiningClientTari : public IMergeMiningClient, public nocopy_nomove
{
public:
MergeMiningClientTari(p2pool* pool, std::string host, const std::string& wallet);
2024-02-24 23:48:51 +00:00
~MergeMiningClientTari() override;
2024-02-06 16:20:58 +00:00
bool get_params(ChainParameters& out_params) const override;
void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof, uint32_t merkle_proof_path) override;
2024-02-06 16:20:58 +00:00
static constexpr char TARI_PREFIX[] = "tari://";
private:
2024-02-17 22:42:40 +00:00
mutable uv_rwlock_t m_chainParamsLock;
ChainParameters m_chainParams;
2024-04-30 21:15:34 +00:00
tari::rpc::Block m_tariBlock;
std::string m_auxWallet;
p2pool* m_pool;
2024-05-10 18:01:10 +00:00
struct TariJobParams
{
uint64_t height;
uint64_t diff;
uint64_t reward;
uint64_t fees;
FORCEINLINE bool operator!=(const TariJobParams& job) const {
static_assert(sizeof(TariJobParams) == sizeof(uint64_t) * 4, "Invalid TariJobParams size");
return memcmp(this, &job, sizeof(TariJobParams)) != 0;
}
};
TariJobParams m_tariJobParams;
private:
static constexpr uint64_t BUF_SIZE = 16384;
struct TariClient;
struct TariServer : public TCPServer
2024-02-06 16:20:58 +00:00
{
explicit TariServer(const std::string& socks5Proxy);
~TariServer() {}
2024-02-06 16:20:58 +00:00
[[nodiscard]] bool start();
[[nodiscard]] bool connect_upstream(TariClient* downstream);
2024-02-06 16:20:58 +00:00
void on_shutdown() override;
[[nodiscard]] const char* get_log_category() const override;
bool m_TariNodeIsV6;
std::string m_TariNodeHost;
int m_TariNodePort;
int m_internalPort;
2024-02-06 16:20:58 +00:00
} *m_server;
const std::string m_hostStr;
tari::rpc::BaseNode::Stub* m_TariNode;
struct TariClient : public TCPServer::Client
2024-02-06 16:20:58 +00:00
{
TariClient();
2024-04-25 13:13:50 +00:00
~TariClient() override {}
2024-02-06 16:20:58 +00:00
static Client* allocate() { return new TariClient(); }
virtual size_t size() const override { return sizeof(TariClient); }
2024-02-06 16:20:58 +00:00
void reset() override;
[[nodiscard]] bool on_connect() override;
[[nodiscard]] bool on_read(char* data, uint32_t size) override;
char m_buf[BUF_SIZE];
2024-02-17 22:42:40 +00:00
std::vector<uint8_t> m_pendingData;
2024-02-06 16:20:58 +00:00
bool is_paired() const { return m_pairedClient && (m_pairedClient->m_resetCounter == m_pairedClientSavedResetCounter); }
2024-02-06 16:20:58 +00:00
TariClient* m_pairedClient;
uint32_t m_pairedClientSavedResetCounter;
};
2024-02-17 22:42:40 +00:00
uv_thread_t m_worker;
uv_mutex_t m_workerLock;
uv_cond_t m_workerCond;
std::atomic<uint32_t> m_workerStop;
static void run_wrapper(void* arg);
void run();
2024-02-06 16:20:58 +00:00
};
} // namespace p2pool