aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorGleb Naumenko <naumenko.gs@gmail.com>2022-11-14 11:37:28 +0200
committerGleb Naumenko <naumenko.gs@gmail.com>2022-11-14 11:37:28 +0200
commitbc84e24a4f0736919ea4a76f7d45085587625aba (patch)
tree6c76f7863275491bf8ab758222df8f194b1838d2 /src/node
parenta60f729e293dcd11ca077b7c1c72b06119437faa (diff)
downloadbitcoin-bc84e24a4f0736919ea4a76f7d45085587625aba.tar.xz
p2p, refactor: Switch to enum class for ReconciliationRegisterResult
While doing this, add a new value: ALREADY_REGISTERED.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/txreconciliation.cpp18
-rw-r--r--src/node/txreconciliation.h9
2 files changed, 15 insertions, 12 deletions
diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp
index 3552cfd8f2..7b50b41dc7 100644
--- a/src/node/txreconciliation.cpp
+++ b/src/node/txreconciliation.cpp
@@ -101,11 +101,13 @@ public:
LOCK(m_txreconciliation_mutex);
auto recon_state = m_states.find(peer_id);
- // A peer should be in the pre-registered state to proceed here.
- if (recon_state == m_states.end()) return NOT_FOUND;
- uint64_t* local_salt = std::get_if<uint64_t>(&recon_state->second);
- // A peer is already registered. This should be checked by the caller.
- Assume(local_salt);
+ if (recon_state == m_states.end()) return ReconciliationRegisterResult::NOT_FOUND;
+
+ if (std::holds_alternative<TxReconciliationState>(recon_state->second)) {
+ return ReconciliationRegisterResult::ALREADY_REGISTERED;
+ }
+
+ uint64_t local_salt = *std::get_if<uint64_t>(&recon_state->second);
// If the peer supports the version which is lower than ours, we downgrade to the version
// it supports. For now, this only guarantees that nodes with future reconciliation
@@ -114,14 +116,14 @@ public:
// satisfactory (e.g. too low).
const uint32_t recon_version{std::min(peer_recon_version, m_recon_version)};
// v1 is the lowest version, so suggesting something below must be a protocol violation.
- if (recon_version < 1) return PROTOCOL_VIOLATION;
+ if (recon_version < 1) return ReconciliationRegisterResult::PROTOCOL_VIOLATION;
LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Register peer=%d (inbound=%i)\n",
peer_id, is_peer_inbound);
- const uint256 full_salt{ComputeSalt(*local_salt, remote_salt)};
+ const uint256 full_salt{ComputeSalt(local_salt, remote_salt)};
recon_state->second = TxReconciliationState(!is_peer_inbound, full_salt.GetUint64(0), full_salt.GetUint64(1));
- return SUCCESS;
+ return ReconciliationRegisterResult::SUCCESS;
}
void ForgetPeer(NodeId peer_id) EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex)
diff --git a/src/node/txreconciliation.h b/src/node/txreconciliation.h
index caaf1777e9..4591dd5df7 100644
--- a/src/node/txreconciliation.h
+++ b/src/node/txreconciliation.h
@@ -16,10 +16,11 @@ static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
/** Supported transaction reconciliation protocol version */
static constexpr uint32_t TXRECONCILIATION_VERSION{1};
-enum ReconciliationRegisterResult {
- NOT_FOUND = 0,
- SUCCESS = 1,
- PROTOCOL_VIOLATION = 2,
+enum class ReconciliationRegisterResult {
+ NOT_FOUND,
+ SUCCESS,
+ ALREADY_REGISTERED,
+ PROTOCOL_VIOLATION,
};
/**