Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c9fbf7f
Scraper - implement convergence history
jamescowens Aug 29, 2019
af30b88
Add convergence hints to NN::Superblock
cyrossignol Aug 30, 2019
0b97c7c
Update scraper for superblock by-project convergence hints
cyrossignol Aug 30, 2019
94e1a02
Add tests for superblock convergence hints
cyrossignol Aug 31, 2019
5818098
Merge pull request #29 from cyrossignol/integrated_scraper_2
jamescowens Aug 31, 2019
03984c4
Add forgotten _log
jamescowens Aug 31, 2019
be1fbdc
Superblock validation (project level)
jamescowens Sep 1, 2019
bfbdb3e
Implement serialization for NN::QuorumHash
cyrossignol Jul 21, 2019
5b122e7
Implement NN::Superblock::WellFormed() method
cyrossignol Aug 18, 2019
396e433
Ignore empty strings in Superblock::UnpackLegacy()
cyrossignol Jul 25, 2019
d87cc66
Implement NN::Superblock::GetHash() method
cyrossignol Sep 2, 2019
b2b33ca
Add quorum hash caching to NN::Superblock
cyrossignol Sep 2, 2019
7706019
Update ValidateSuperblock() for WellFored() and GetHash()
cyrossignol Sep 2, 2019
7954734
Merge pull request #30 from cyrossignol/integrated_scraper_2
jamescowens Sep 2, 2019
6cfd6f9
Add random convergence node SB self test.
jamescowens Sep 2, 2019
b781e4e
Cleanup/bugfixes
jamescowens Sep 5, 2019
ac5939a
Fixes confusion between convergence content hash
jamescowens Sep 7, 2019
8b02972
Fix missing assignment to RandomPastSB.m_manifest_content_hint
jamescowens Sep 8, 2019
c5ea4d3
Deal correctly with a rare BeaconList empty issue
jamescowens Sep 16, 2019
79e0b31
Create NN::SuperblockValidator class
cyrossignol Sep 16, 2019
81fc504
Add NN::SuperblockValidator tests to testnewsb RPC
cyrossignol Sep 16, 2019
bee178d
Replace scraper's SB hashing with internal hash management
cyrossignol Sep 2, 2019
f9732f8
Replace Superblock::GetSerializeSize() with WellFormed() for empty ch…
cyrossignol Sep 2, 2019
60c762d
Add serialization for superblock m_manifest_content_hint
cyrossignol Sep 16, 2019
f3ff4e4
Merge branch 'development' into integrated_scraper_2
jamescowens Sep 18, 2019
e6d8ba6
Reorganize scraper_net.h includes for superblock.cpp
cyrossignol Sep 20, 2019
71c6bdc
Add missing doc comments to SuperblockValidator::ProjectResolver fields
cyrossignol Sep 20, 2019
70a9b4c
Merge pull request #31 from cyrossignol/integrated_scraper_2
jamescowens Sep 20, 2019
512a5ff
Manifest age check when requesting parts
jamescowens Sep 21, 2019
daa329a
Backport Bitcoin Banning System
jamescowens Sep 23, 2019
83fa0fe
Add additional details to debug3 LogPrintf for Project Level Convergence
jamescowens Sep 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ endif
.PHONY: FORCE
# gridcoin core #
GRIDCOIN_CORE_H = \
addrman.h \
addrdb.h \
addrman.h \
alert.h \
allocators.h \
attributes.h \
appcache.h \
backup.h \
banman.h \
base58.h \
beacon.h \
bignum.h \
Expand All @@ -76,6 +79,7 @@ GRIDCOIN_CORE_H = \
contract/contract.h \
crypter.h \
db.h \
fs.h \
fwd.h \
global_objects.hpp \
global_objects_noui.hpp \
Expand All @@ -100,9 +104,11 @@ GRIDCOIN_CORE_H = \
pbkdf2.h \
prevector.h \
protocol.h \
reverselock.h \
rpcclient.h \
rpcprotocol.h \
rpcserver.h \
scheduler.h \
scraper_net.h \
scraper/fwd.h \
scraper/http.h \
Expand All @@ -124,11 +130,13 @@ GRIDCOIN_CORE_H = \
walletdb.h \
wallet.h

GRIDCOIN_CORE_CPP = addrman.cpp \
GRIDCOIN_CORE_CPP = addrdb.cpp \
addrman.cpp \
alert.cpp \
allocators.cpp \
appcache.cpp \
backup.cpp \
banman.cpp \
beacon.cpp \
block.cpp \
boinc.cpp \
Expand All @@ -137,6 +145,7 @@ GRIDCOIN_CORE_CPP = addrman.cpp \
contract/contract.cpp \
crypter.cpp \
db.cpp \
fs.cpp \
gridcoin.cpp \
init.cpp \
kernel.cpp \
Expand Down Expand Up @@ -172,6 +181,7 @@ GRIDCOIN_CORE_CPP = addrman.cpp \
scraper/scraper.cpp \
script.cpp \
scrypt.cpp \
scheduler.cpp \
sync.cpp \
tally.cpp \
txdb-leveldb.cpp \
Expand Down
149 changes: 149 additions & 0 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <addrdb.h>

#include <addrman.h>
// #include <chainparams.h>
// #include <clientversion.h>
#include <hash.h>
// #include <random.h>
// #include <streams.h>
#include <tinyformat.h>
// #include <util/system.h>
// #include "main.h"
#include "util.h"
#include "net.h"
#include "fs.h"

namespace {

template <typename Stream, typename Data>
bool SerializeDB(Stream& stream, const Data& data)
{
// Write and commit header, data
try {
CHashWriter hasher(SER_DISK, CLIENT_VERSION);
stream << FLATDATA(pchMessageStart) << data;
hasher << FLATDATA(pchMessageStart) << data;
stream << hasher.GetHash();
} catch (const std::exception& e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
}

return true;
}

template <typename Data>
bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data)
{
// Generate random temporary filename
unsigned short randv = 0;
RAND_bytes((unsigned char*)&randv, sizeof(randv));
std::string tmpfn = strprintf("%s.%04x", prefix, randv);

// open temp output file, and associate with CAutoFile
fs::path pathTmp = GetDataDir() / tmpfn;
FILE *file = fsbridge::fopen(pathTmp, "wb");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
if (fileout.IsNull())
return error("%s: Failed to open file %s", __func__, pathTmp.string());

// Serialize
if (!SerializeDB(fileout, data)) return false;
if (!FileCommit(fileout.Get()))
return error("%s: Failed to flush file %s", __func__, pathTmp.string());
fileout.fclose();

// replace existing file, if any, with new file
if (!RenameOver(pathTmp, path))
return error("%s: Rename-into-place failed", __func__);

return true;
}

template <typename Stream, typename Data>
bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
{
try {
CHashVerifier<Stream> verifier(&stream);
// de-serialize file header (network specific magic number) and ..
unsigned char pchMsgTmp[4];
verifier >> pchMsgTmp;
// ... verify the network matches ours
if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
return error("%s: Invalid network magic number", __func__);

// de-serialize data
verifier >> data;

// verify checksum
if (fCheckSum) {
uint256 hashTmp;
stream >> hashTmp;
if (hashTmp != verifier.GetHash()) {
return error("%s: Checksum mismatch, data corrupted", __func__);
}
}
}
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}

return true;
}

template <typename Data>
bool DeserializeFileDB(const fs::path& path, Data& data)
{
// open input file, and associate with CAutoFile
FILE *file = fsbridge::fopen(path, "rb");
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
return error("%s: Failed to open file %s", __func__, path.string());

return DeserializeDB(filein, data);
}

}

CBanDB::CBanDB(fs::path ban_list_path) : m_ban_list_path(std::move(ban_list_path))
{
}

bool CBanDB::Write(const banmap_t& banSet)
{
return SerializeFileDB("banlist", m_ban_list_path, banSet);
}

bool CBanDB::Read(banmap_t& banSet)
{
return DeserializeFileDB(m_ban_list_path, banSet);
}

CAddrDB::CAddrDB()
{
pathAddr = GetDataDir() / "peers.dat";
}

bool CAddrDB::Write(const CAddrMan& addr)
{
return SerializeFileDB("peers", pathAddr, addr);
}

bool CAddrDB::Read(CAddrMan& addr)
{
return DeserializeFileDB(pathAddr, addr);
}

bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
{
bool ret = DeserializeDB(ssPeers, addr, false);
if (!ret) {
// Ensure addrman is left in a clean state
addr.Clear();
}
return ret;
}
108 changes: 108 additions & 0 deletions src/addrdb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_ADDRDB_H
#define BITCOIN_ADDRDB_H

#include <fs.h>
#include <serialize.h>

#include <string>
#include <map>

class CSubNet;
class CAddrMan;
class CDataStream;

typedef enum BanReason
{
BanReasonUnknown = 0,
BanReasonNodeMisbehaving = 1,
BanReasonManuallyAdded = 2
} BanReason;

class CBanEntry
{
public:
static const int CURRENT_VERSION=1;
int nVersion;
int64_t nCreateTime;
int64_t nBanUntil;
uint8_t banReason;

CBanEntry()
{
SetNull();
}

explicit CBanEntry(int64_t nCreateTimeIn)
{
SetNull();
nCreateTime = nCreateTimeIn;
}

explicit CBanEntry(int64_t n_create_time_in, BanReason ban_reason_in) : CBanEntry(n_create_time_in)
{
banReason = ban_reason_in;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITEVARIADIC(this->nVersion);
READWRITEVARIADIC(nCreateTime);
READWRITEVARIADIC(nBanUntil);
READWRITEVARIADIC(banReason);
}

void SetNull()
{
nVersion = CBanEntry::CURRENT_VERSION;
nCreateTime = 0;
nBanUntil = 0;
banReason = BanReasonUnknown;
}

std::string banReasonToString() const
{
switch (banReason) {
case BanReasonNodeMisbehaving:
return "node misbehaving";
case BanReasonManuallyAdded:
return "manually added";
default:
return "unknown";
}
}
};

typedef std::map<CSubNet, CBanEntry> banmap_t;

/** Access to the (IP) address database (peers.dat) */
class CAddrDB
{
private:
fs::path pathAddr;
public:
CAddrDB();
bool Write(const CAddrMan& addr);
bool Read(CAddrMan& addr);

static bool Read(CAddrMan& addr, CDataStream& ssPeers);
};

/** Access to the banlist database (banlist.dat) */
class CBanDB
{
private:
const fs::path m_ban_list_path;
public:
explicit CBanDB(fs::path ban_list_path);
bool Write(const banmap_t& banSet);
bool Read(banmap_t& banSet);
};

#endif // BITCOIN_ADDRDB_H
30 changes: 30 additions & 0 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,36 @@ class CAddrMan
Check();
}
}

void Clear()
{
LOCK(cs);
std::vector<int>().swap(vRandom);
RAND_bytes(&nKey[0], 32);
vvTried = std::vector<std::vector<int>>(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0));
vvNew = std::vector<std::set<int>>(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>());
// Will need for Bitcoin rebase
// nKey = insecure_rand.rand256();
//for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
// for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
// vvNew[bucket][entry] = -1;
// }
//}
//for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; bucket++) {
// for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
// vvTried[bucket][entry] = -1;
// }
//}

nIdCount = 0;
nTried = 0;
nNew = 0;
// Will need for Bitcoin rebase
// nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
mapInfo.clear();
mapAddr.clear();
}

};

#endif
22 changes: 22 additions & 0 deletions src/attributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_ATTRIBUTES_H
#define BITCOIN_ATTRIBUTES_H

#if defined(__has_cpp_attribute)
# if __has_cpp_attribute(nodiscard)
# define NODISCARD [[nodiscard]]
# endif
#endif
#ifndef NODISCARD
# if defined(_MSC_VER) && _MSC_VER >= 1700
# define NODISCARD _Check_return_
# else
# define NODISCARD __attribute__((warn_unused_result))
# endif
#endif

#endif // BITCOIN_ATTRIBUTES_H
Loading