Skip to content

Commit a60f729

Browse files
committed
p2p: Drop roles from sendtxrcncl
This feature was currently redundant (although could have provided more flexibility in the future), and already been causing confusion.
1 parent 6772cbf commit a60f729

File tree

7 files changed

+29
-99
lines changed

7 files changed

+29
-99
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,11 +3279,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32793279
// - we are not in -blocksonly mode.
32803280
if (pfrom.m_relays_txs && !m_ignore_incoming_txs) {
32813281
const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId());
3282-
// We suggest our txreconciliation role (initiator/responder) based on
3283-
// the connection direction.
32843282
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL,
3285-
!pfrom.IsInboundConn(),
3286-
pfrom.IsInboundConn(),
32873283
TXRECONCILIATION_VERSION, recon_salt));
32883284
}
32893285
}
@@ -3514,22 +3510,19 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35143510
return;
35153511
}
35163512

3517-
bool is_peer_initiator, is_peer_responder;
3518-
uint32_t peer_txreconcl_version;
3519-
uint64_t remote_salt;
3520-
vRecv >> is_peer_initiator >> is_peer_responder >> peer_txreconcl_version >> remote_salt;
3521-
35223513
if (m_txreconciliation->IsPeerRegistered(pfrom.GetId())) {
35233514
// A peer is already registered, meaning we already received SENDTXRCNCL from them.
35243515
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "txreconciliation protocol violation from peer=%d (sendtxrcncl received from already registered peer); disconnecting\n", pfrom.GetId());
35253516
pfrom.fDisconnect = true;
35263517
return;
35273518
}
35283519

3520+
uint32_t peer_txreconcl_version;
3521+
uint64_t remote_salt;
3522+
vRecv >> peer_txreconcl_version >> remote_salt;
3523+
35293524
const ReconciliationRegisterResult result = m_txreconciliation->RegisterPeer(pfrom.GetId(), pfrom.IsInboundConn(),
3530-
is_peer_initiator, is_peer_responder,
3531-
peer_txreconcl_version,
3532-
remote_salt);
3525+
peer_txreconcl_version, remote_salt);
35333526

35343527
// If it's a protocol violation, disconnect.
35353528
// If the peer was not found (but something unexpected happened) or it was registered,

src/node/txreconciliation.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class TxReconciliationState
3939
* the following commits.
4040
*
4141
* Reconciliation protocol assumes using one role consistently: either a reconciliation
42-
* initiator (requesting sketches), or responder (sending sketches). This defines our role.
42+
* initiator (requesting sketches), or responder (sending sketches). This defines our role,
43+
* based on the direction of the p2p connection.
4344
*
4445
*/
4546
bool m_we_initiate;
@@ -93,9 +94,8 @@ class TxReconciliationTracker::Impl
9394
return local_salt;
9495
}
9596

96-
ReconciliationRegisterResult RegisterPeer(NodeId peer_id, bool is_peer_inbound, bool is_peer_recon_initiator,
97-
bool is_peer_recon_responder, uint32_t peer_recon_version,
98-
uint64_t remote_salt) EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex)
97+
ReconciliationRegisterResult RegisterPeer(NodeId peer_id, bool is_peer_inbound, uint32_t peer_recon_version,
98+
uint64_t remote_salt) EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex)
9999
{
100100
AssertLockNotHeld(m_txreconciliation_mutex);
101101
LOCK(m_txreconciliation_mutex);
@@ -116,24 +116,11 @@ class TxReconciliationTracker::Impl
116116
// v1 is the lowest version, so suggesting something below must be a protocol violation.
117117
if (recon_version < 1) return PROTOCOL_VIOLATION;
118118

119-
// Must match SENDTXRCNCL logic.
120-
const bool they_initiate = is_peer_recon_initiator && is_peer_inbound;
121-
const bool we_initiate = !is_peer_inbound && is_peer_recon_responder;
122-
123-
// If we ever announce support for both requesting and responding, this will need
124-
// tie-breaking. For now, this is mutually exclusive because both are based on the
125-
// inbound flag.
126-
assert(!(they_initiate && we_initiate));
127-
128-
// The peer set both flags to false, we treat it as a protocol violation.
129-
if (!(they_initiate || we_initiate)) return PROTOCOL_VIOLATION;
130-
131-
LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Register peer=%d with the following params: " /* Continued */
132-
"we_initiate=%i, they_initiate=%i.\n",
133-
peer_id, we_initiate, they_initiate);
119+
LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Register peer=%d (inbound=%i)\n",
120+
peer_id, is_peer_inbound);
134121

135122
const uint256 full_salt{ComputeSalt(*local_salt, remote_salt)};
136-
recon_state->second = TxReconciliationState(we_initiate, full_salt.GetUint64(0), full_salt.GetUint64(1));
123+
recon_state->second = TxReconciliationState(!is_peer_inbound, full_salt.GetUint64(0), full_salt.GetUint64(1));
137124
return SUCCESS;
138125
}
139126

@@ -166,11 +153,9 @@ uint64_t TxReconciliationTracker::PreRegisterPeer(NodeId peer_id)
166153
}
167154

168155
ReconciliationRegisterResult TxReconciliationTracker::RegisterPeer(NodeId peer_id, bool is_peer_inbound,
169-
bool is_peer_recon_initiator, bool is_peer_recon_responder,
170156
uint32_t peer_recon_version, uint64_t remote_salt)
171157
{
172-
return m_impl->RegisterPeer(peer_id, is_peer_inbound, is_peer_recon_initiator, is_peer_recon_responder,
173-
peer_recon_version, remote_salt);
158+
return m_impl->RegisterPeer(peer_id, is_peer_inbound, peer_recon_version, remote_salt);
174159
}
175160

176161
void TxReconciliationTracker::ForgetPeer(NodeId peer_id)

src/node/txreconciliation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class TxReconciliationTracker
7272
* Step 0. Once the peer agreed to reconcile txs with us, generate the state required to track
7373
* ongoing reconciliations. Must be called only after pre-registering the peer and only once.
7474
*/
75-
ReconciliationRegisterResult RegisterPeer(NodeId peer_id, bool is_peer_inbound, bool is_peer_recon_initiator,
76-
bool is_peer_recon_responder, uint32_t peer_recon_version, uint64_t remote_salt);
75+
ReconciliationRegisterResult RegisterPeer(NodeId peer_id, bool is_peer_inbound,
76+
uint32_t peer_recon_version, uint64_t remote_salt);
7777

7878
/**
7979
* Attempts to forget txreconciliation-related state of the peer (if we previously stored any).

src/protocol.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ extern const char* CFCHECKPT;
259259
*/
260260
extern const char* WTXIDRELAY;
261261
/**
262-
* Contains 2 1-byte bools, a 4-byte version number and an 8-byte salt.
263-
* The 2 booleans indicate that a node is willing to participate in transaction
264-
* reconciliation, respectively as an initiator or as a receiver.
262+
* Contains a 4-byte version number and an 8-byte salt.
265263
* The salt is used to compute short txids needed for efficient
266264
* txreconciliation, as described by BIP 330.
267265
*/

src/test/txreconciliation_tests.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,23 @@ BOOST_AUTO_TEST_CASE(RegisterPeerTest)
1818
// Prepare a peer for reconciliation.
1919
tracker.PreRegisterPeer(0);
2020

21-
// Both roles are false, don't register.
22-
BOOST_CHECK(tracker.RegisterPeer(/*peer_id=*/0, /*is_peer_inbound=*/true,
23-
/*is_peer_recon_initiator=*/false,
24-
/*is_peer_recon_responder=*/false,
25-
/*peer_recon_version=*/1, salt) ==
26-
ReconciliationRegisterResult::PROTOCOL_VIOLATION);
27-
28-
// Invalid roles for the given connection direction.
29-
BOOST_CHECK(tracker.RegisterPeer(0, true, false, true, 1, salt) == ReconciliationRegisterResult::PROTOCOL_VIOLATION);
30-
BOOST_CHECK(tracker.RegisterPeer(0, false, true, false, 1, salt) == ReconciliationRegisterResult::PROTOCOL_VIOLATION);
31-
3221
// Invalid version.
33-
BOOST_CHECK(tracker.RegisterPeer(0, true, true, false, 0, salt) == ReconciliationRegisterResult::PROTOCOL_VIOLATION);
22+
BOOST_CHECK(tracker.RegisterPeer(/*peer_id=*/0, /*is_peer_inbound=*/true,
23+
/*peer_recon_version=*/0, salt) == ReconciliationRegisterResult::PROTOCOL_VIOLATION);
3424

3525
// Valid registration.
3626
BOOST_REQUIRE(!tracker.IsPeerRegistered(0));
37-
BOOST_REQUIRE(tracker.RegisterPeer(0, true, true, false, 1, salt) == ReconciliationRegisterResult::SUCCESS);
27+
BOOST_REQUIRE(tracker.RegisterPeer(0, true, 1, salt) == ReconciliationRegisterResult::SUCCESS);
3828
BOOST_CHECK(tracker.IsPeerRegistered(0));
3929

4030
// Reconciliation version is higher than ours, should be able to register.
4131
BOOST_REQUIRE(!tracker.IsPeerRegistered(1));
4232
tracker.PreRegisterPeer(1);
43-
BOOST_REQUIRE(tracker.RegisterPeer(1, true, true, false, 2, salt) == ReconciliationRegisterResult::SUCCESS);
33+
BOOST_REQUIRE(tracker.RegisterPeer(1, true, 2, salt) == ReconciliationRegisterResult::SUCCESS);
4434
BOOST_CHECK(tracker.IsPeerRegistered(1));
4535

4636
// Do not register if there were no pre-registration for the peer.
47-
BOOST_REQUIRE(tracker.RegisterPeer(100, true, true, false, 1, salt) == ReconciliationRegisterResult::NOT_FOUND);
37+
BOOST_REQUIRE(tracker.RegisterPeer(100, true, 1, salt) == ReconciliationRegisterResult::NOT_FOUND);
4838
BOOST_CHECK(!tracker.IsPeerRegistered(100));
4939
}
5040

@@ -56,12 +46,12 @@ BOOST_AUTO_TEST_CASE(ForgetPeerTest)
5646
// Removing peer after pre-registring works and does not let to register the peer.
5747
tracker.PreRegisterPeer(peer_id0);
5848
tracker.ForgetPeer(peer_id0);
59-
BOOST_CHECK(tracker.RegisterPeer(peer_id0, true, true, false, 1, 1) == ReconciliationRegisterResult::NOT_FOUND);
49+
BOOST_CHECK(tracker.RegisterPeer(peer_id0, true, 1, 1) == ReconciliationRegisterResult::NOT_FOUND);
6050

6151
// Removing peer after it is registered works.
6252
tracker.PreRegisterPeer(peer_id0);
6353
BOOST_REQUIRE(!tracker.IsPeerRegistered(peer_id0));
64-
BOOST_REQUIRE(tracker.RegisterPeer(peer_id0, true, true, false, 1, 1) == ReconciliationRegisterResult::SUCCESS);
54+
BOOST_REQUIRE(tracker.RegisterPeer(peer_id0, true, 1, 1) == ReconciliationRegisterResult::SUCCESS);
6555
BOOST_CHECK(tracker.IsPeerRegistered(peer_id0));
6656
tracker.ForgetPeer(peer_id0);
6757
BOOST_CHECK(!tracker.IsPeerRegistered(peer_id0));
@@ -76,7 +66,7 @@ BOOST_AUTO_TEST_CASE(IsPeerRegisteredTest)
7666
tracker.PreRegisterPeer(peer_id0);
7767
BOOST_REQUIRE(!tracker.IsPeerRegistered(peer_id0));
7868

79-
BOOST_REQUIRE(tracker.RegisterPeer(peer_id0, true, true, false, 1, 1) == ReconciliationRegisterResult::SUCCESS);
69+
BOOST_REQUIRE(tracker.RegisterPeer(peer_id0, true, 1, 1) == ReconciliationRegisterResult::SUCCESS);
8070
BOOST_CHECK(tracker.IsPeerRegistered(peer_id0));
8171

8272
tracker.ForgetPeer(peer_id0);

test/functional/p2p_sendtxrcncl.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ def on_message(self, message):
5454
super().on_message(message)
5555
self.messages.append(message)
5656

57-
def create_sendtxrcncl_msg(initiator=True):
57+
def create_sendtxrcncl_msg():
5858
sendtxrcncl_msg = msg_sendtxrcncl()
59-
sendtxrcncl_msg.initiator = initiator
60-
sendtxrcncl_msg.responder = not initiator
6159
sendtxrcncl_msg.version = 1
6260
sendtxrcncl_msg.salt = 2
6361
return sendtxrcncl_msg
@@ -71,8 +69,6 @@ def run_test(self):
7169
self.log.info('SENDTXRCNCL sent to an inbound')
7270
peer = self.nodes[0].add_p2p_connection(SendTxrcnclReceiver(), send_version=True, wait_for_verack=True)
7371
assert peer.sendtxrcncl_msg_received
74-
assert not peer.sendtxrcncl_msg_received.initiator
75-
assert peer.sendtxrcncl_msg_received.responder
7672
assert_equal(peer.sendtxrcncl_msg_received.version, 1)
7773
self.nodes[0].disconnect_p2ps()
7874

@@ -117,22 +113,6 @@ def run_test(self):
117113
peer.send_message(create_sendtxrcncl_msg())
118114
peer.wait_for_disconnect()
119115

120-
self.log.info('SENDTXRCNCL with initiator=responder=0 triggers a disconnect')
121-
sendtxrcncl_no_role = create_sendtxrcncl_msg()
122-
sendtxrcncl_no_role.initiator = False
123-
sendtxrcncl_no_role.responder = False
124-
peer = self.nodes[0].add_p2p_connection(PeerNoVerack(), send_version=True, wait_for_verack=False)
125-
with self.nodes[0].assert_debug_log(["txreconciliation protocol violation"]):
126-
peer.send_message(sendtxrcncl_no_role)
127-
peer.wait_for_disconnect()
128-
129-
self.log.info('SENDTXRCNCL with initiator=0 and responder=1 from inbound triggers a disconnect')
130-
sendtxrcncl_wrong_role = create_sendtxrcncl_msg(initiator=False)
131-
peer = self.nodes[0].add_p2p_connection(PeerNoVerack(), send_version=True, wait_for_verack=False)
132-
with self.nodes[0].assert_debug_log(["txreconciliation protocol violation"]):
133-
peer.send_message(sendtxrcncl_wrong_role)
134-
peer.wait_for_disconnect()
135-
136116
self.log.info('SENDTXRCNCL with version=0 triggers a disconnect')
137117
sendtxrcncl_low_version = create_sendtxrcncl_msg()
138118
sendtxrcncl_low_version.version = 0
@@ -158,8 +138,6 @@ def run_test(self):
158138
peer = self.nodes[0].add_outbound_p2p_connection(
159139
SendTxrcnclReceiver(), wait_for_verack=True, p2p_idx=0, connection_type="outbound-full-relay")
160140
assert peer.sendtxrcncl_msg_received
161-
assert peer.sendtxrcncl_msg_received.initiator
162-
assert not peer.sendtxrcncl_msg_received.responder
163141
assert_equal(peer.sendtxrcncl_msg_received.version, 1)
164142
self.nodes[0].disconnect_p2ps()
165143

@@ -178,15 +156,7 @@ def run_test(self):
178156
peer = self.nodes[0].add_outbound_p2p_connection(
179157
PeerNoVerack(), wait_for_verack=False, p2p_idx=0, connection_type="block-relay-only")
180158
with self.nodes[0].assert_debug_log(["we indicated no tx relay; disconnecting"]):
181-
peer.send_message(create_sendtxrcncl_msg(initiator=False))
182-
peer.wait_for_disconnect()
183-
184-
self.log.info('SENDTXRCNCL with initiator=1 and responder=0 from outbound triggers a disconnect')
185-
sendtxrcncl_wrong_role = create_sendtxrcncl_msg(initiator=True)
186-
peer = self.nodes[0].add_outbound_p2p_connection(
187-
PeerNoVerack(), wait_for_verack=False, p2p_idx=0, connection_type="outbound-full-relay")
188-
with self.nodes[0].assert_debug_log(["txreconciliation protocol violation"]):
189-
peer.send_message(sendtxrcncl_wrong_role)
159+
peer.send_message(create_sendtxrcncl_msg())
190160
peer.wait_for_disconnect()
191161

192162
self.log.info('SENDTXRCNCL not sent if -txreconciliation flag is not set')

test/functional/test_framework/messages.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,29 +1840,23 @@ def __repr__(self):
18401840
self.filter_type, self.stop_hash)
18411841

18421842
class msg_sendtxrcncl:
1843-
__slots__ = ("initiator", "responder", "version", "salt")
1843+
__slots__ = ("version", "salt")
18441844
msgtype = b"sendtxrcncl"
18451845

18461846
def __init__(self):
1847-
self.initiator = False
1848-
self.responder = False
18491847
self.version = 0
18501848
self.salt = 0
18511849

18521850
def deserialize(self, f):
1853-
self.initiator = struct.unpack("<?", f.read(1))[0]
1854-
self.responder = struct.unpack("<?", f.read(1))[0]
18551851
self.version = struct.unpack("<I", f.read(4))[0]
18561852
self.salt = struct.unpack("<Q", f.read(8))[0]
18571853

18581854
def serialize(self):
18591855
r = b""
1860-
r += struct.pack("<?", self.initiator)
1861-
r += struct.pack("<?", self.responder)
18621856
r += struct.pack("<I", self.version)
18631857
r += struct.pack("<Q", self.salt)
18641858
return r
18651859

18661860
def __repr__(self):
1867-
return "msg_sendtxrcncl(initiator=%i, responder=%i, version=%lu, salt=%lu)" %\
1868-
(self.initiator, self.responder, self.version, self.salt)
1861+
return "msg_sendtxrcncl(version=%lu, salt=%lu)" %\
1862+
(self.version, self.salt)

0 commit comments

Comments
 (0)