Skip to content

Commit e60157a

Browse files
Merge #6893: refactor: drop dependency of spork on net_processing
f0a2cec refactor: drop dependency of spork on net_processing (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Dependency of Spork on PeerManager (net_processing) is a blocker for kernel / chainstate project. ## What was done? Removed dependency of Spork on PeerManager by moving network code to rpc/node ## How Has This Been Tested? Run test/lint/lint-circular-dependencies.py ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK f0a2cec kwvg: utACK f0a2cec PastaPastaPasta: utACK f0a2cec Tree-SHA512: 1f07fe7af5b76e23c985fd8290521ae4cfbff7c2ba59b7b572748ff4a1561556384c2b0ba596a24304accb63975537e82026d8486793b54f599f75b0dfbc07b4
2 parents f170aed + f0a2cec commit e60157a

File tree

4 files changed

+29
-41
lines changed

4 files changed

+29
-41
lines changed

src/rpc/node.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <interfaces/ipc.h>
2020
#include <key_io.h>
2121
#include <net.h>
22+
#include <net_processing.h>
2223
#include <node/context.h>
2324
#include <rpc/index_util.h>
2425
#include <rpc/server.h>
@@ -220,14 +221,15 @@ static RPCHelpMan sporkupdate()
220221
}
221222

222223
const NodeContext& node = EnsureAnyNodeContext(request.context);
223-
PeerManager& peerman = EnsurePeerman(node);
224224
CHECK_NONFATAL(node.sporkman);
225225

226226
// SPORK VALUE
227227
int64_t nValue = request.params[1].getInt<int64_t>();
228228

229-
// broadcast new spork
230-
if (node.sporkman->UpdateSpork(peerman, nSporkID, nValue)) {
229+
auto inv{node.sporkman->UpdateSpork(nSporkID, nValue)};
230+
if (inv.has_value()) {
231+
PeerManager& peerman = EnsurePeerman(node);
232+
peerman.RelayInv(inv.value());
231233
return "success";
232234
}
233235

src/spork.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <logging.h>
1111
#include <messagesigner.h>
1212
#include <net.h>
13-
#include <net_processing.h>
1413
#include <netmessagemaker.h>
1514
#include <protocol.h>
1615
#include <script/standard.h>
@@ -206,37 +205,36 @@ void CSporkManager::ProcessGetSporks(CNode& peer, CConnman& connman)
206205
}
207206

208207

209-
bool CSporkManager::UpdateSpork(PeerManager& peerman, SporkId nSporkID, SporkValue nValue)
208+
std::optional<CInv> CSporkManager::UpdateSpork(SporkId nSporkID, SporkValue nValue)
210209
{
211210
CSporkMessage spork(nSporkID, nValue, GetAdjustedTime());
212211

213-
{
214-
LOCK(cs);
212+
LOCK(cs);
215213

216-
if (!spork.Sign(sporkPrivKey)) {
217-
LogPrintf("CSporkManager::%s -- ERROR: signing failed for spork %d\n", __func__, nSporkID);
218-
return false;
219-
}
214+
if (!spork.Sign(sporkPrivKey)) {
215+
LogPrintf("CSporkManager::%s -- ERROR: signing failed for spork %d\n", __func__, nSporkID);
216+
return std::nullopt;
217+
}
220218

221-
auto opt_keyIDSigner = spork.GetSignerKeyID();
222-
if (opt_keyIDSigner == std::nullopt || !setSporkPubKeyIDs.count(*opt_keyIDSigner)) {
223-
LogPrintf("CSporkManager::UpdateSpork: failed to find keyid for private key\n");
224-
return false;
225-
}
219+
auto opt_keyIDSigner = spork.GetSignerKeyID();
220+
if (opt_keyIDSigner == std::nullopt || !setSporkPubKeyIDs.count(*opt_keyIDSigner)) {
221+
LogPrintf("CSporkManager::UpdateSpork: failed to find keyid for private key\n");
222+
return std::nullopt;
223+
}
226224

227-
LogPrintf("CSporkManager::%s -- signed %d %s\n", __func__, nSporkID, spork.GetHash().ToString());
225+
LogPrintf("CSporkManager::%s -- signed %d %s\n", __func__, nSporkID, spork.GetHash().ToString());
228226

229-
mapSporksByHash[spork.GetHash()] = spork;
230-
mapSporksActive[nSporkID][*opt_keyIDSigner] = spork;
231-
// Clear cached values on new spork being processed
227+
mapSporksByHash[spork.GetHash()] = spork;
228+
mapSporksActive[nSporkID][*opt_keyIDSigner] = spork;
229+
// Clear cached values on new spork being processed
232230

233-
LOCK(cs_cache);
234-
mapSporksCachedActive.erase(spork.nSporkID);
235-
mapSporksCachedValues.erase(spork.nSporkID);
236-
}
231+
LOCK(cs_cache);
232+
mapSporksCachedActive.erase(spork.nSporkID);
233+
mapSporksCachedValues.erase(spork.nSporkID);
237234

238-
spork.Relay(peerman);
239-
return true;
235+
236+
CInv inv(MSG_SPORK, spork.GetHash());
237+
return inv;
240238
}
241239

242240
bool CSporkManager::IsSporkActive(SporkId nSporkID) const
@@ -460,9 +458,3 @@ std::optional<CKeyID> CSporkMessage::GetSignerKeyID() const
460458

461459
return {pubkeyFromSig.GetID()};
462460
}
463-
464-
void CSporkMessage::Relay(PeerManager& peerman) const
465-
{
466-
CInv inv(MSG_SPORK, GetHash());
467-
peerman.RelayInv(inv);
468-
}

src/spork.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ template<typename T>
2525
class CFlatDB;
2626
class CNode;
2727
class CDataStream;
28-
class PeerManager;
2928

3029
class CSporkMessage;
3130
class CSporkManager;
@@ -151,11 +150,6 @@ class CSporkMessage
151150
* in order to identify which spork key signed this message.
152151
*/
153152
std::optional<CKeyID> GetSignerKeyID() const;
154-
155-
/**
156-
* Relay is used to send this spork message to other peers.
157-
*/
158-
void Relay(PeerManager& peerman) const;
159153
};
160154

161155
class SporkStore
@@ -278,9 +272,10 @@ class CSporkManager : public SporkStore
278272

279273
/**
280274
* UpdateSpork is used by the spork RPC command to set a new spork value, sign
281-
* and broadcast the spork message.
275+
* and return the spork message, ready for network relay.
276+
* It returns nullopt if nothing to relay
282277
*/
283-
bool UpdateSpork(PeerManager& peerman, SporkId nSporkID, SporkValue nValue) EXCLUSIVE_LOCKS_REQUIRED(!cs, !cs_cache);
278+
std::optional<CInv> UpdateSpork(SporkId nSporkID, SporkValue nValue) EXCLUSIVE_LOCKS_REQUIRED(!cs, !cs_cache);
284279

285280
/**
286281
* IsSporkActive returns a bool for time-based sporks, and should be used

test/lint/lint-circular-dependencies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"llmq/signing_shares -> net_processing -> llmq/signing_shares",
6868
"masternode/payments -> validation -> masternode/payments",
6969
"net -> netmessagemaker -> net",
70-
"net_processing -> spork -> net_processing",
7170
"netaddress -> netbase -> netaddress",
7271
"qt/appearancewidget -> qt/guiutil -> qt/appearancewidget",
7372
"qt/bitcoinaddressvalidator -> qt/guiutil -> qt/bitcoinaddressvalidator",

0 commit comments

Comments
 (0)