Skip to content

Commit e2f0938

Browse files
committed
Allow just refreshing ping in mn broadcast.
broadcaststartmasternode has a feature to refresh the ping's timestamp if an explicit signature is passed. This extends that feature to allow passing "update_ping" in place of the signature, in which case the signature contained in the mnb will be kept but the ping will still be refreshed. Not passing a second argument at all is still a way to just broadcast the message as-is.
1 parent a683949 commit e2f0938

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

divi/src/MasternodeModule.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,15 @@ MasternodeStartResult StartMasternode(std::string alias, bool deferRelay)
318318
return result;
319319
}
320320

321-
bool RelayMasternodeBroadcast(std::string hexData, std::string signature)
321+
bool RelayMasternodeBroadcast(const std::string& hexData, const std::string& signature, const bool updatePing)
322322
{
323323
CMasternodeBroadcast mnb = readFromHex<CMasternodeBroadcast>(hexData);
324+
324325
if(!signature.empty())
325-
{
326326
mnb.signature = ParseHex(signature);
327+
328+
if (updatePing)
329+
{
327330
if(activeMasternode.IsOurBroadcast(mnb,true))
328331
{
329332
if(activeMasternode.UpdatePing(mnb.lastPing))

divi/src/MasternodeModule.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ bool ShareMasternodeBroadcastWithPeer(CNode* peer,const uint256& inventoryHash);
2626
bool ShareMasternodePingWithPeer(CNode* peer,const uint256& inventoryHash);
2727
void ForceMasternodeResync();
2828
const CMasternodeSync& GetMasternodeSync();
29-
bool RelayMasternodeBroadcast(std::string hexData,std::string signature = "");
29+
/** Relays a broadcast given in serialised form as hex string. If the signature
30+
* is present, then it will replace the signature in the broadcast. If
31+
* updatePing is true, then the masternode ping is re-signed freshly. */
32+
bool RelayMasternodeBroadcast(const std::string& hexData, const std::string& signature, bool updatePing);
3033
struct MasternodeStartResult
3134
{
3235
bool status;
@@ -104,4 +107,4 @@ bool LoadMasternodeDataFromDisk(UIMessenger& uiMessenger,std::string pathToDataD
104107
void DumpMasternodeDataToDisk();
105108
CMasternodePayments& GetMasternodePayments();
106109
bool InitializeMasternodeIfRequested(const Settings& settings, bool transactionIndexEnabled, std::string& errorMessage);
107-
#endif //MASTERNODE_MODULE_H
110+
#endif //MASTERNODE_MODULE_H

divi/src/rpcmasternode.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,17 @@ Value broadcaststartmasternode(const Array& params, bool fHelp)
449449
"\nResult:\n"
450450
"\"status\" (string) status of broadcast\n");
451451

452+
bool updatePing = false;
453+
std::string signature;
454+
if(params.size()==2)
455+
{
456+
if (params[1].get_str() != "update_ping")
457+
signature = params[1].get_str();
458+
updatePing = true;
459+
}
460+
452461
Object result;
453-
if(RelayMasternodeBroadcast(params[0].get_str(), (params.size()==2)? params[1].get_str():"" ))
462+
if(RelayMasternodeBroadcast(params[0].get_str(), signature, updatePing))
454463
{
455464
result.push_back(Pair("status", "success"));
456465
}

0 commit comments

Comments
 (0)