Skip to content

Commit

Permalink
Merge branch 'auxpow'
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Aug 9, 2021
2 parents c1625db + 2252cda commit 83baa3b
Show file tree
Hide file tree
Showing 136 changed files with 2,827 additions and 1,439 deletions.
4 changes: 1 addition & 3 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,7 @@ RECURSIVE = YES

EXCLUDE = src/crc32c \
src/leveldb \
src/json \
src/test \
src/qt/test
src/json

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
2 changes: 1 addition & 1 deletion doc/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Subdirectory | File(s) | Description
`indexes/coinstats/db/` | LevelDB database | Coinstats index; *optional*, used if `-coinstatsindex=1`
`wallets/` | | [Contains wallets](#multi-wallet-environment); can be specified by `-walletdir` option; if `wallets/` subdirectory does not exist, wallets reside in the [data directory](#data-directory-location)
`./` | `anchors.dat` | Anchor IP address database, created on shutdown and deleted at startup. Anchors are last known outgoing block-relay-only peers that are tried to re-connect to on startup
`./` | `banlist.dat` | Stores the addresses/subnets of banned nodes (deprecated). `bitcoind` or `bitcoin-qt` no longer save the banlist to this file, but read it on startup if `banlist.json` is not present.
`./` | `banlist.json` | Stores the addresses/subnets of banned nodes.
`./` | `bitcoin.conf` | User-defined [configuration settings](bitcoin-conf.md) for `bitcoind` or `bitcoin-qt`. File is not written to by the software and must be created manually. Path can be specified by `-conf` option
`./` | `bitcoind.pid` | Stores the process ID (PID) of `bitcoind` or `bitcoin-qt` while running; created at start and deleted on shutdown; can be specified by `-pid` option
Expand Down Expand Up @@ -114,6 +113,7 @@ These subdirectories and files are no longer used by Bitcoin Core:

Path | Description | Repository notes
---------------|-------------|-----------------
`banlist.dat` | Stores the addresses/subnets of banned nodes; superseded by `banlist.json` in 22.0 and completely ignored in 23.0 | [PR #20966](https://github.com/bitcoin/bitcoin/pull/20966), [PR #22570](https://github.com/bitcoin/bitcoin/pull/22570)
`blktree/` | Blockchain index; replaced by `blocks/index/` in [0.8.0](https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.8.0.md#improvements) | [PR #2231](https://github.com/bitcoin/bitcoin/pull/2231), [`8fdc94cc`](https://github.com/bitcoin/bitcoin/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
`coins/` | Unspent transaction output database; replaced by `chainstate/` in 0.8.0 | [PR #2231](https://github.com/bitcoin/bitcoin/pull/2231), [`8fdc94cc`](https://github.com/bitcoin/bitcoin/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
`blkindex.dat` | Blockchain index BDB database; replaced by {`chainstate/`, `blocks/index/`, `blocks/revNNNNN.dat`<sup>[\[2\]](#note2)</sup>} in 0.8.0 | [PR #1677](https://github.com/bitcoin/bitcoin/pull/1677)
Expand Down
12 changes: 10 additions & 2 deletions doc/i2p.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ information in the debug log about your I2P configuration and connections. Run
`bitcoin-cli help logging` for more information.

It is possible to restrict outgoing connections in the usual way with
`onlynet=i2p`. I2P support was added to Bitcoin Core in version 22.0 (mid 2021)
`onlynet=i2p`. I2P support was added to Bitcoin Core in version 22.0 (mid-2021)
and there may be fewer I2P peers than Tor or IP ones. Therefore, using
`onlynet=i2p` alone (without other `onlynet=`) may make a node more susceptible
to [Sybil attacks](https://en.bitcoin.it/wiki/Weaknesses#Sybil_attack). Use
`bitcoin-cli -addrinfo` to see the number of I2P addresses known to your node.

## I2P related information in Bitcoin Core
Another consideration with `onlynet=i2p` is that the initial blocks download
phase when syncing up a new node can be very slow. This phase can be sped up by
using other networks, for instance `onlynet=onion`, at the same time.

In general, a node can be run with both onion and I2P hidden services (or
any/all of IPv4/IPv6/onion/I2P), which can provide a potential fallback if one
of the networks has issues.

## I2P-related information in Bitcoin Core

There are several ways to see your I2P address in Bitcoin Core:
- in the debug log (grep for `AddLocal`, the I2P address ends in `.b32.i2p`)
Expand Down
14 changes: 14 additions & 0 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Notable changes
P2P and network changes
-----------------------

- A bitcoind node will no longer rumour addresses to inbound peers by default.
They will become eligible for address gossip after sending an ADDR, ADDRV2,
or GETADDR message. (#21528)

Updated RPCs
------------

Expand All @@ -66,6 +70,16 @@ New RPCs
Build System
------------

Files
-----

* On startup, the list of banned hosts and networks (via `setban` RPC) in
`banlist.dat` is ignored and only `banlist.json` is considered. Bitcoin Core
version 22.x is the only version that can read `banlist.dat` and also write
it to `banlist.json`. If `banlist.json` already exists, version 22.x will not
try to translate the `banlist.dat` into json. After an upgrade, `listbanned`
can be used to double check the parsed entries. (#22570)

New settings
------------

Expand Down
13 changes: 6 additions & 7 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,16 @@ bool CBanDB::Write(const banmap_t& banSet)
return false;
}

bool CBanDB::Read(banmap_t& banSet, bool& dirty)
bool CBanDB::Read(banmap_t& banSet)
{
// If the JSON banlist does not exist, then try to read the non-upgraded banlist.dat.
if (fs::exists(m_banlist_dat)) {
LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.\n", m_banlist_dat);
}
// If the JSON banlist does not exist, then recreate it
if (!fs::exists(m_banlist_json)) {
// If this succeeds then we need to flush to disk in order to create the JSON banlist.
dirty = true;
return DeserializeFileDB(m_banlist_dat, banSet, CLIENT_VERSION);
return false;
}

dirty = false;

std::map<std::string, util::SettingsValue> settings;
std::vector<std::string> errors;

Expand Down
6 changes: 2 additions & 4 deletions src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CAddrDB
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
};

/** Access to the banlist databases (banlist.json and banlist.dat) */
/** Access to the banlist database (banlist.json) */
class CBanDB
{
private:
Expand All @@ -95,11 +95,9 @@ class CBanDB
* Read the banlist from disk.
* @param[out] banSet The loaded list. Set if `true` is returned, otherwise it is left
* in an undefined state.
* @param[out] dirty Indicates whether the loaded list needs flushing to disk. Set if
* `true` is returned, otherwise it is left in an undefined state.
* @return true on success
*/
bool Read(banmap_t& banSet, bool& dirty);
bool Read(banmap_t& banSet);
};

/**
Expand Down
81 changes: 27 additions & 54 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,6 @@ double CAddrInfo::GetChance(int64_t nNow) const
return fChance;
}

void CAddrMan::RemoveInvalid()
{
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; ++bucket) {
for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
const auto id = vvNew[bucket][i];
if (id != -1 && !mapInfo[id].IsValid()) {
ClearNew(bucket, i);
}
}
}

for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; ++bucket) {
for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
const auto id = vvTried[bucket][i];
if (id == -1) {
continue;
}
const auto& addr_info = mapInfo[id];
if (addr_info.IsValid()) {
continue;
}
vvTried[bucket][i] = -1;
--nTried;
SwapRandom(addr_info.nRandomPos, vRandom.size() - 1);
vRandom.pop_back();
mapAddr.erase(addr_info);
mapInfo.erase(id);
m_tried_collisions.erase(id);
}
}
}

CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
{
AssertLockHeld(cs);
Expand Down Expand Up @@ -138,7 +106,7 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
return &mapInfo[nId];
}

void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2) const
{
AssertLockHeld(cs);

Expand All @@ -150,11 +118,13 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
int nId1 = vRandom[nRndPos1];
int nId2 = vRandom[nRndPos2];

assert(mapInfo.count(nId1) == 1);
assert(mapInfo.count(nId2) == 1);
const auto it_1{mapInfo.find(nId1)};
const auto it_2{mapInfo.find(nId2)};
assert(it_1 != mapInfo.end());
assert(it_2 != mapInfo.end());

mapInfo[nId1].nRandomPos = nRndPos2;
mapInfo[nId2].nRandomPos = nRndPos1;
it_1->second.nRandomPos = nRndPos2;
it_2->second.nRandomPos = nRndPos1;

vRandom[nRndPos1] = nId2;
vRandom[nRndPos2] = nId1;
Expand Down Expand Up @@ -410,7 +380,7 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
}
}

CAddrInfo CAddrMan::Select_(bool newOnly)
CAddrInfo CAddrMan::Select_(bool newOnly) const
{
AssertLockHeld(cs);

Expand All @@ -433,8 +403,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
const auto it_found{mapInfo.find(nId)};
assert(it_found != mapInfo.end());
const CAddrInfo& info{it_found->second};
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
Expand All @@ -450,8 +421,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
const auto it_found{mapInfo.find(nId)};
assert(it_found != mapInfo.end());
const CAddrInfo& info{it_found->second};
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
Expand Down Expand Up @@ -503,15 +475,15 @@ int CAddrMan::Check_()

for (int n = 0; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) {
for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) {
if (vvTried[n][i] != -1) {
if (!setTried.count(vvTried[n][i]))
return -11;
if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey, m_asmap) != n)
return -17;
if (mapInfo[vvTried[n][i]].GetBucketPosition(nKey, false, n) != i)
return -18;
setTried.erase(vvTried[n][i]);
}
if (vvTried[n][i] != -1) {
if (!setTried.count(vvTried[n][i]))
return -11;
if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey, m_asmap) != n)
return -17;
if (mapInfo[vvTried[n][i]].GetBucketPosition(nKey, false, n) != i)
return -18;
setTried.erase(vvTried[n][i]);
}
}
}

Expand Down Expand Up @@ -539,7 +511,7 @@ int CAddrMan::Check_()
}
#endif

void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const
{
AssertLockHeld(cs);

Expand All @@ -559,9 +531,10 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size

int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
SwapRandom(n, nRndPos);
assert(mapInfo.count(vRandom[n]) == 1);
const auto it{mapInfo.find(vRandom[n])};
assert(it != mapInfo.end());

const CAddrInfo& ai = mapInfo[vRandom[n]];
const CAddrInfo& ai{it->second};

// Filter by network (optional)
if (network != std::nullopt && ai.GetNetClass() != network) continue;
Expand Down
Loading

0 comments on commit 83baa3b

Please sign in to comment.