Merge #19569: Enable fetching of orphan parents from wtxid peers

10b7a6d532148f880568c529e61a6d7edc7c91a9 refactor: make txmempool interface use GenTxid (Pieter Wuille)
5c124e17407a5b5824fec062b73a03a1030fa28c refactor: make FindTxForGetData use GenTxid (Pieter Wuille)
a2bfac893549e2d62708d8cda7071b4fe9750a2d refactor: use GenTxid in tx request functions (Pieter Wuille)
e65d115b725640eefb3bfa09786447816f7ca9cc test: request parents of orphan from wtxid relay peer (Anthony Towns)
900d7f6c075fd78e63503f31d267dbc16b3983d9 p2p: enable fetching of orphans from wtxid peers (Pieter Wuille)
9efd86a908cf09d9ddbadd3195f202635117d505 refactor: add GenTxid (=txid or wtxid) type and use it for tx request logic (Pieter Wuille)
d362f19355b36531a4a82094e0259f7f3db500a7 doc: list support for BIP 339 in doc/bips.md (Pieter Wuille)

Pull request description:

  This is based on https://github.com/bitcoin/bitcoin/pull/18044#discussion_r450687076.

  A new type `GenTxid` is added to protocol.h, which represents a tagged txid-or-wtxid. The tx request logic is updated to use these instead of uint256s, permitting per-announcement distinguishing of txid/wtxid (instead of assuming that everything we want to request from a wtxid peer is wtx). Then the restriction of orphan-parent requesting to non-wtxid peers is lifted.

  Also document BIP339 in doc/bips.md.

ACKs for top commit:
  jnewbery:
    Code review ACK 10b7a6d532148f880568c529e61a6d7edc7c91a9
  jonatack:
    ACK 10b7a6d532148f880568c529e61a6d7edc7c91a9
  ajtowns:
    ACK 10b7a6d532148f880568c529e61a6d7edc7c91a9 -- code review. Using gtxid to replace the is_txid_or_wtxid flag for the mempool functions is nice.
  naumenkogs:
    utACK 10b7a6d

Tree-SHA512: d518d13ffd71f8d2b3c175dc905362a7259689e6022a97a0b4f14f1f9fdd87475cf5af70cb12338d1e5d31b52c12e4faaea436114056a2ae9669cb506240758b
This commit is contained in:
fanquake 2020-07-31 19:28:14 +08:00 committed by pasta
parent 9b3d2e0c17
commit 0a27a2af73
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
3 changed files with 11 additions and 9 deletions

View File

@ -41,3 +41,4 @@ Specified versions, PRs are relevant to Bitcoin's core.
- [`BIP 158`](https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki): Compact Block Filters for Light Clients can be indexed as of **v18.0** ([PR #14121](https://github.com/bitcoin/bitcoin/pull/14121)).
* [`BIP 159`](https://github.com/bitcoin/bips/blob/master/bip-0159.mediawiki): The `NODE_NETWORK_LIMITED` service bit is signalled as of **v0.16.0** ([PR 11740](https://github.com/bitcoin/bitcoin/pull/11740)), and such nodes are connected to as of **v0.17.0** ([PR 10387](https://github.com/bitcoin/bitcoin/pull/10387)).
* [`BIP 174`](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki): RPCs to operate on Partially Signed Bitcoin Transactions (PSBT) are present as of **v18.0** ([PR 13557](https://github.com/bitcoin/bitcoin/pull/13557)).
* [`BIP 339`](https://github.com/bitcoin/bips/blob/master/bip-0339.mediawiki): Relay of transactions by wtxid is supported as of **v0.21.0** ([PR 18044](https://github.com/bitcoin/bitcoin/pull/18044)).

View File

@ -501,7 +501,7 @@ private:
void ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing);
/** Relay map */
/** Relay map (txid -> CTransactionRef) */
typedef std::map<uint256, CTransactionRef> MapRelay;
MapRelay mapRelay GUARDED_BY(cs_main);
/** Expiration-time ordered list of (expire time, relay map entry) pairs. */
@ -1043,22 +1043,22 @@ void EraseObjectRequest(NodeId nodeId, const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED
EraseObjectRequest(state, inv);
}
std::chrono::microseconds GetObjectRequestTime(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
std::chrono::microseconds GetObjectRequestTime(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
AssertLockHeld(cs_main);
auto it = g_already_asked_for.find(hash);
auto it = g_already_asked_for.find(inv.hash);
if (it != g_already_asked_for.end()) {
return it->second;
}
return {};
}
void UpdateObjectRequestTime(const uint256& hash, std::chrono::microseconds request_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void UpdateObjectRequestTime(const CInv& inv, std::chrono::microseconds request_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
AssertLockHeld(cs_main);
auto it = g_already_asked_for.find(hash);
auto it = g_already_asked_for.find(inv.hash);
if (it == g_already_asked_for.end()) {
g_already_asked_for.insert(std::make_pair(hash, request_time));
g_already_asked_for.insert(std::make_pair(inv.hash, request_time));
} else {
g_already_asked_for.update(it, request_time);
}
@ -1097,7 +1097,7 @@ std::chrono::microseconds CalculateObjectGetDataTime(const CInv& inv, std::chron
{
AssertLockHeld(cs_main);
std::chrono::microseconds process_time;
const auto last_request_time = GetObjectRequestTime(inv.hash);
const auto last_request_time = GetObjectRequestTime(inv);
// First time requesting this tx
if (last_request_time.count() == 0) {
process_time = current_time;
@ -5231,7 +5231,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
if (!AlreadyHave(inv)) {
// If this object was last requested more than GetObjectInterval ago,
// then request.
const auto last_request_time = GetObjectRequestTime(inv.hash);
const auto last_request_time = GetObjectRequestTime(inv);
if (last_request_time <= current_time - GetObjectInterval(inv.type)) {
LogPrint(BCLog::NET, "Requesting %s peer=%d\n", inv.ToString(), pto->GetId());
vGetData.push_back(inv);
@ -5239,7 +5239,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
vGetData.clear();
}
UpdateObjectRequestTime(inv.hash, current_time);
UpdateObjectRequestTime(inv, current_time);
state.m_object_download.m_object_in_flight.emplace(inv, current_time);
} else {
// This object is in flight from someone else; queue

View File

@ -11,6 +11,7 @@
#define BITCOIN_PROTOCOL_H
#include <netaddress.h>
#include <primitives/transaction.h>
#include <serialize.h>
#include <streams.h>
#include <uint256.h>