Files
thehub/libs/server/thinblock.h
T

145 lines
4.7 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2015 G. Andrew Stone
* Copyright (C) 2016 The Bitcoin Unlimited developers
2021-06-20 22:44:44 +02:00
* Copyright (C) 2016 Tom Zander <tom@flowee.org>
2017-11-09 19:34:51 +01:00
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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/>.
*/
2016-01-15 21:37:25 -08:00
2018-01-16 10:47:52 +00:00
#ifndef FLOWEE_THINBLOCK_H
#define FLOWEE_THINBLOCK_H
2016-01-15 21:37:25 -08:00
#include "serialize.h"
#include "uint256.h"
#include "primitives/MutableBlock.h"
2016-01-15 21:37:25 -08:00
#include "bloom.h"
#include "net.h"
#include "util.h"
2016-01-15 21:37:25 -08:00
#include <vector>
2021-11-02 09:36:09 +01:00
class MutableBlock;
class CNode;
2016-01-15 21:37:25 -08:00
class CXThinBlock
{
public:
BlockHeaderFields header;
2016-01-15 21:37:25 -08:00
std::vector<uint64_t> vTxHashes; // List of all transactions id's in the block
std::vector<CTransaction> vMissingTx; // vector of transactions that did not match the bloom filter
2016-01-15 21:37:25 -08:00
bool collision;
public:
2021-11-02 09:36:09 +01:00
CXThinBlock(const MutableBlock& block, CBloomFilter* filter = 0); // Use the filter to determine which txns the client has
2017-01-31 10:03:43 +01:00
CXThinBlock();
2016-01-15 21:37:25 -08:00
2016-07-08 16:05:57 +02:00
ADD_SERIALIZE_METHODS
2016-01-15 21:37:25 -08:00
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(header);
READWRITE(vTxHashes);
READWRITE(vMissingTx);
2016-01-15 21:37:25 -08:00
}
2017-02-08 17:28:21 +01:00
2021-11-02 09:28:35 +01:00
inline CInv GetInv() { return CInv(MSG_BLOCK, header.createHash()); }
2017-02-08 17:28:21 +01:00
bool process(CNode* pfrom);
2016-01-15 21:37:25 -08:00
};
// This class is used for retrieving a list of still missing transactions after receiving a "thinblock" message.
// The CXThinBlockTx when recieved can be used to fill in the missing transactions after which it is sent
// back to the requestor. This class uses a 64bit hash as opposed to the normal 256bit hash.
class CXThinBlockTx
{
public:
/** Public only for unit testing */
uint256 blockhash;
std::vector<CTransaction> vMissingTx; // map of missing transactions
2016-01-15 21:37:25 -08:00
public:
CXThinBlockTx(uint256 blockHash, std::vector<CTransaction>& vTx);
2016-01-15 21:37:25 -08:00
CXThinBlockTx() {}
2016-07-08 16:05:57 +02:00
ADD_SERIALIZE_METHODS
2016-01-15 21:37:25 -08:00
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(blockhash);
READWRITE(vMissingTx);
}
};
2016-07-06 20:16:18 +02:00
// This class is used for retrieving a list of still missing transactions after receiving a "thinblock" message.
// The CXThinBlockTx when recieved can be used to fill in the missing transactions after which it is sent
// back to the requestor. This class uses a 64bit hash as opposed to the normal 256bit hash.
class CXRequestThinBlockTx
{
public:
/** Public only for unit testing */
uint256 blockhash;
std::set<uint64_t> setCheapHashesToRequest; // map of missing transactions
public:
CXRequestThinBlockTx(uint256 blockHash, std::set<uint64_t>& setHashesToRequest);
CXRequestThinBlockTx() {}
2016-07-08 16:05:57 +02:00
ADD_SERIALIZE_METHODS
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(blockhash);
READWRITE(setCheapHashesToRequest);
2016-01-15 21:37:25 -08:00
}
};
bool HaveThinblockNodes();
bool CheckThinblockTimer(const uint256 &hash);
2017-02-08 17:28:21 +01:00
inline bool IsThinBlocksEnabled() {
return GetBoolArg("-use-thinblocks", false);
}
bool IsChainNearlySyncd();
CBloomFilter createSeededBloomFilter(const std::vector<uint256>& vOrphanHashes);
void LoadFilter(CNode *pfrom, CBloomFilter *filter);
2021-11-02 09:36:09 +01:00
void HandleBlockMessage(CNode *pfrom, const std::string &strCommand, const MutableBlock &block, const CInv &inv);
2017-02-08 17:28:21 +01:00
// TODO namespace the new methods?
2018-11-21 12:26:17 +01:00
// Checks to see if the node is configured in flowee.conf to be an expedited block source and if so, request them.
2017-02-08 17:28:21 +01:00
void CheckAndRequestExpeditedBlocks(CNode* pfrom);
void SendExpeditedBlock(CXThinBlock& thinBlock, unsigned char hops, const CNode* skip = nullptr);
2021-11-02 09:36:09 +01:00
void SendExpeditedBlock(const MutableBlock& block, const CNode* skip = nullptr);
2017-02-08 17:28:21 +01:00
void HandleExpeditedRequest(CDataStream& vRecv, CNode* pfrom);
bool IsRecentlyExpeditedAndStore(const uint256& hash);
// process incoming unsolicited block
void HandleExpeditedBlock(CDataStream& vRecv,CNode* pfrom);
extern CCriticalSection cs_xval;
enum {
EXPEDITED_STOP = 1,
EXPEDITED_BLOCKS = 2,
EXPEDITED_TXNS = 4,
};
enum {
EXPEDITED_MSG_HEADER = 1,
EXPEDITED_MSG_XTHIN = 2,
};
#endif