Skip to content

Commit

Permalink
feat: mnauth always use basic scheme
Browse files Browse the repository at this point in the history
fixup: drop CChain from mnauth ProcessMessage
feat: let RPC mnauth to generate only BASIC bls messages and fixes for rpc_mnauth.py and p2p_quorum_data.py
refactor: drop unused ConstCBLSPublicKeyVersionWrapper
  • Loading branch information
PastaPastaPasta committed Dec 9, 2024
1 parent 7c00c86 commit 844f242
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 36 deletions.
15 changes: 0 additions & 15 deletions src/bls/bls.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,6 @@ class CBLSPublicKey : public CBLSWrapper<bls::G1Element, BLS_CURVE_PUBKEY_SIZE,

};

class ConstCBLSPublicKeyVersionWrapper {
private:
const CBLSPublicKey& obj;
bool legacy;
public:
ConstCBLSPublicKeyVersionWrapper(const CBLSPublicKey& obj, bool legacy)
: obj(obj)
, legacy(legacy)
{}
template <typename Stream>
inline void Serialize(Stream& s) const {
obj.Serialize(s, legacy);
}
};

class CBLSPublicKeyVersionWrapper {
private:
CBLSPublicKey& obj;
Expand Down
13 changes: 4 additions & 9 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <bls/bls.h>
#include <chain.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <llmq/utils.h>
#include <masternode/meta.h>
Expand All @@ -19,8 +18,7 @@
#include <util/time.h>
#include <validation.h>

void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman,
const CBlockIndex* tip)
void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman)
{
CMNAuth mnauth;
if (mn_activeman.GetProTxHash().IsNull()) {
Expand All @@ -41,9 +39,8 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternode
if (Params().NetworkIDString() != CBaseChainParams::MAIN && gArgs.IsArgSet("-pushversion")) {
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
auto pk = mn_activeman.GetPubKey();
const CBLSPublicKeyVersionWrapper pubKey(pk, !is_basic_scheme_active);
const CBLSPublicKey pubKey(pk);
uint256 signHash = [&]() {
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
return ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn()));
Expand All @@ -61,7 +58,7 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternode
}

PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, ServiceFlags node_services, CConnman& connman, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman,
const CChain& active_chain, const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list,
const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list,
std::string_view msg_type, CDataStream& vRecv)
{
assert(mn_metaman.IsValid());
Expand Down Expand Up @@ -106,9 +103,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, ServiceFlags node_services, CCon
if (Params().NetworkIDString() != CBaseChainParams::MAIN && gArgs.IsArgSet("-pushversion")) {
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
const CBlockIndex* tip = active_chain.Tip();
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
ConstCBLSPublicKeyVersionWrapper pubKey(dmn->pdmnState->pubKeyOperator.Get(), !is_basic_scheme_active);
const CBLSPublicKey pubKey(dmn->pdmnState->pubKeyOperator.Get());
// See comment in PushMNAUTH (fInbound is negated here as we're on the other side of the connection)
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(pubKey, peer.GetSentMNAuthChallenge(), !peer.IsInboundConn()));
Expand Down
5 changes: 2 additions & 3 deletions src/evo/mnauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ class CMNAuth
READWRITE(obj.proRegTxHash, obj.sig);
}

static void PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman,
const CBlockIndex* tip);
static void PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman);

/**
* @pre CMasternodeMetaMan's database must be successfully loaded before
* attempting to call this function regardless of sync state
*/
static PeerMsgRet ProcessMessage(CNode& peer, ServiceFlags node_services, CConnman& connman, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman,
const CChain& active_chain, const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list,
const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list,
std::string_view msg_type, CDataStream& vRecv);
static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman);
};
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3784,7 +3784,7 @@ void PeerManagerImpl::ProcessMessage(
}

if (is_masternode && !pfrom.m_masternode_probe_connection) {
CMNAuth::PushMNAUTH(pfrom, m_connman, *m_mn_activeman, m_chainman.ActiveChain().Tip());
CMNAuth::PushMNAUTH(pfrom, m_connman, *m_mn_activeman);
}

// Tell our peer we prefer to receive headers rather than inv's
Expand Down
6 changes: 1 addition & 5 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <addressindex.h>
#include <chainparams.h>
#include <consensus/consensus.h>
#include <deploymentstatus.h>
#include <evo/mnauth.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
Expand Down Expand Up @@ -633,11 +632,8 @@ static RPCHelpMan mnauth()
throw JSONRPCError(RPC_INVALID_PARAMETER, "proTxHash invalid");
}

ChainstateManager& chainman = EnsureAnyChainman(request.context);

CBLSPublicKey publicKey;
const bool bls_legacy_scheme{!DeploymentActiveAfter(chainman.ActiveChain().Tip(), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
publicKey.SetHexStr(request.params[2].get_str(), bls_legacy_scheme);
publicKey.SetHexStr(request.params[2].get_str(), /*bls_legacy_scheme=*/false);
if (!publicKey.IsValid()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "publicKey invalid");
}
Expand Down
5 changes: 3 additions & 2 deletions test/functional/p2p_quorum_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

# Used to overwrite MNAUTH for mininode connections
fake_mnauth_1 = ["cecf37bf0ec05d2d22cb8227f88074bb882b94cd2081ba318a5a444b1b15b9fd",
"087ba00bf61135f3860c4944a0debabe186ef82628fbe4ceaed1ad51d672c58dde14ea4b321efe0b89257a40322bc972"]
"8e7afdb849e5e2a085b035b62e21c0940c753f2d4501325743894c37162f287bccaffbedd60c36581dabbf127a22e43f"]
fake_mnauth_2 = ["6ad7ed7a2d6c2c1db30fc364114602b36b2730a9aa96d8f11f1871a9cee37378",
"122463411a86362966a5161805f24cf6a0eef08a586b8e00c4f0ad0b084c5bb3f5c9a60ee5ffc78db2313897e3ab2223"]
"ad38860c03c3d1d875771f41b8a9b933415f72929c21a4276c101d8f0268f6fcdfeed46507c16c00e74f26ce1181e69f"]

# Used to distinguish mininode connections
uacomment_m3_1 = "MN3_1"
Expand Down Expand Up @@ -400,6 +400,7 @@ def test_rpc_quorum_getdata_protx_hash():
mn1.node.quorum, "getdata", 0, 100, quorum_hash, 0x03,
"0000000000000000000000000000000000000000000000000000000000000000")

self.activate_v19(expected_activation_height=900)
# Enable DKG and disable ChainLocks
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4070908800)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_mnauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def set_test_params(self):
self.set_dash_test_params(2, 1)

def run_test(self):
self.activate_v19(expected_activation_height=900)

masternode = self.mninfo[0]
masternode.node.add_p2p_connection(P2PInterface())

protx_hash = masternode.proTxHash
#TODO: Fix that with basic BLS
public_key = masternode.pubKeyOperator

# The peerinfo should not yet contain verified_proregtx_hash/verified_pubkey_hash
Expand Down

0 comments on commit 844f242

Please sign in to comment.