2017-05-02 15:25:05 +02:00
|
|
|
/*
|
2017-11-13 23:09:33 +01:00
|
|
|
* This file is part of the Flowee project
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2017 Tom Zander <tom@flowee.org>
|
2017-05-02 15:25:05 +02: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/>.
|
|
|
|
|
*/
|
2017-02-08 17:17:38 +01:00
|
|
|
#ifndef TXORPHANCACHE_H
|
|
|
|
|
#define TXORPHANCACHE_H
|
|
|
|
|
|
|
|
|
|
#include "sync.h"
|
|
|
|
|
#include "primitives/transaction.h"
|
|
|
|
|
|
|
|
|
|
class CTxOrphanCache
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CTxOrphanCache();
|
|
|
|
|
static CTxOrphanCache *instance();
|
|
|
|
|
|
|
|
|
|
struct COrphanTx {
|
|
|
|
|
CTransaction tx;
|
|
|
|
|
int fromPeer;
|
|
|
|
|
uint64_t nEntryTime;
|
2018-01-15 15:26:12 +00:00
|
|
|
uint32_t onResultFlags;
|
2017-02-08 17:17:38 +01:00
|
|
|
};
|
2019-11-21 20:03:26 +01:00
|
|
|
bool addOrphanTx(const CTransaction& tx, int peerId, uint32_t onResultFlags = 0, uint64_t originalEntryTime = 0);
|
2017-02-08 17:17:38 +01:00
|
|
|
|
2019-11-21 20:03:26 +01:00
|
|
|
void eraseOrphansByTime();
|
2017-02-08 17:17:38 +01:00
|
|
|
|
2019-11-21 20:03:26 +01:00
|
|
|
std::uint32_t limitOrphanTxSize();
|
2017-02-08 17:17:38 +01:00
|
|
|
|
|
|
|
|
inline const std::map<uint256, COrphanTx> & mapOrphanTransactions() const {
|
|
|
|
|
return m_mapOrphanTransactions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear();
|
|
|
|
|
static bool value(const uint256 &txid, CTransaction &output);
|
|
|
|
|
static bool contains(const uint256 &txid);
|
|
|
|
|
|
|
|
|
|
std::vector<uint256> fetchTransactionIds() const;
|
|
|
|
|
|
|
|
|
|
void setLimit(std::uint32_t limit);
|
|
|
|
|
|
|
|
|
|
std::vector<COrphanTx> fetchTransactionsByPrev(const uint256 &txid) const;
|
|
|
|
|
|
2019-11-21 20:03:26 +01:00
|
|
|
void eraseOrphans(const std::vector<uint256> &txIds);
|
2017-02-08 17:17:38 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
mutable CCriticalSection m_lock;
|
|
|
|
|
std::map<uint256, COrphanTx> m_mapOrphanTransactions;
|
|
|
|
|
std::map<uint256, std::set<uint256> > m_mapOrphanTransactionsByPrev;
|
|
|
|
|
|
|
|
|
|
static CTxOrphanCache *s_instance;
|
|
|
|
|
|
|
|
|
|
// this one doesn't lock!
|
2019-11-21 20:03:26 +01:00
|
|
|
void eraseOrphanTx(uint256 hash);
|
|
|
|
|
uint32_t limitOrphanTxSize(uint32_t nMaxOrphans);
|
2017-02-08 17:17:38 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::uint32_t m_limit;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TXORPHANCACHE_H
|