Files

82 lines
2.7 KiB
C++
Raw Permalink Normal View History

2019-09-02 23:28:14 +02:00
/*
* This file is part of the Flowee project
2024-09-04 21:53:53 +02:00
* Copyright (c) 2019-2024 Tom Zander <tom@flowee.org>
2019-09-02 23:28:14 +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/>.
*/
#ifndef DOUBLESPENDPROOFSTORAGE_H
#define DOUBLESPENDPROOFSTORAGE_H
#include "DoubleSpendProof.h"
#include "bloom.h"
#include <boost/unordered_map.hpp>
#include <map>
2026-05-07 21:10:10 +02:00
#include <deque>
2019-09-02 23:28:14 +02:00
#include <mutex>
class COutPoint;
typedef int NodeId;
2019-09-02 23:28:14 +02:00
class DoubleSpendProofStorage
{
public:
DoubleSpendProofStorage();
/// returns a double spend proof based on proof-id
DoubleSpendProof proof(int proof) const;
/// adds a proof, returns an internal proof-id that proof is known under.
2020-09-29 17:01:52 +02:00
/// notice that if the proof (by hash) was known, we return -1 instead.
2019-09-02 23:28:14 +02:00
int add(const DoubleSpendProof &proof);
/// remove by proof-id
void remove(int proof);
2020-09-29 20:08:55 +02:00
/// add()s and additionally registers the proof as an orphan.
/// Orphans expire after secondsToKeepOrphans() elapses. They may
/// be claimed using 'claimOrphan()'.
void addOrphan(const DoubleSpendProof &proof, NodeId peerId);
2020-01-12 17:03:13 +01:00
/// Returns all (not yet verified) orphans matching prevOut.
2024-09-04 21:53:53 +02:00
/// Each item is a pair of a proofId and the nodeId that sent the proof to us.
2020-08-01 15:29:47 +02:00
std::list<std::pair<int, int> > findOrphans(const COutPoint &prevOut) const;
2019-09-02 23:28:14 +02:00
2020-09-29 20:08:55 +02:00
/// Flags the proof associated with hash as not an orphan, and thus
/// not subject to automatic expiry.
2020-01-13 11:27:47 +01:00
void claimOrphan(int proofId);
2020-09-29 20:08:55 +02:00
/// Lookup a double-spend proof by id.
2019-09-02 23:28:14 +02:00
DoubleSpendProof lookup(const uint256 &proofId) const;
bool exists(const uint256 &proofId) const;
// called every minute
void periodicCleanup();
bool isRecentlyRejectedProof(const uint256 &proofHash) const;
void markProofRejected(const uint256 &proofHash);
void newBlockFound();
private:
std::map<int, DoubleSpendProof> m_proofs;
int m_nextId = 1;
std::map<int, std::pair<NodeId, int64_t> > m_orphans;
2019-09-02 23:28:14 +02:00
typedef boost::unordered_map<uint256, int, HashShortener> LookupTable;
LookupTable m_dspIdLookupTable;
std::map<uint64_t, std::deque<int> > m_prevTxIdLookupTable;
mutable std::recursive_mutex m_lock;
CRollingBloomFilter m_recentRejects;
};
#endif