two masternode keys?

freynder

New Member
Dec 5, 2014
30
63
18
Hello,

I'm currently reviewing darkcoin code and was wondering the following:

masternode.h: contains:
CPubKey pubkey;
CPubKey pubkey2;

Why are there 2 public keys? When checking CActiveMasternode::RegisterAsMasterNode I can see that two keypairs are being used to create the initial dsee message:
- one keypair originates from init.cpp: if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, key, pubkey))
- the other one is generated in activemasternode.cpp: if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, key, pubkey))

Both originate from strMasterNodePrivKey so they are basically the same.

I ran some debug code to view pubkey and pubkey2 from all masternodes in the list and they are the same, confirming what was stated above.

Can anyone clarify why 2 keypairs are used and what is their use if they are always the same?

Thank you
 
Last edited by a moderator:
  • Like
Reactions: vertoe

vertoe

Three of Nine
Mar 28, 2014
2,573
1,652
1,283
Unimatrix Zero One
freynder did you check in your debug log which key is used? is it always the same?

I'm also reviewing the darkcoin code right now and there is a lot of "dead weight", so you could try to remove instances of the pubkey1 and see if it works by only using pubkey2. just an idea without having a look at the code.
 

freynder

New Member
Dec 5, 2014
30
63
18
pubkey: the masternodes 1000 DRK address

pubkey2: the pubkey to masternodeprivkey
Are you sure about this? As stated, when you check the code you can see that both of them use the masternode private key. Also confirmed by checking pubkey and pubkey2 for the list of active masternodes.
 

freynder

New Member
Dec 5, 2014
30
63
18
freynder did you check in your debug log which key is used? is it always the same?

I'm also reviewing the darkcoin code right now and there is a lot of "dead weight", so you could try to remove instances of the pubkey1 and see if it works by only using pubkey2. just an idea without having a look at the code.
Since they are the same it will probably work. I'm a bit hesitant to just remove one as I don't know why it was put there in the first place.
 

vertoe

Three of Nine
Mar 28, 2014
2,573
1,652
1,283
Unimatrix Zero One
Since they are the same it will probably work. I'm a bit hesitant to just remove one as I don't know why it was put there in the first place.
Just backup your main wallet and play around. In main.cpp there is stuff like GetNextWorkRequired, GetNextWorkRequired_V1, _V2, _V3 .... :)
The code is growing but really needs more people to clean up and refactor. Go ahead and suggest your changes :)
 
  • Like
Reactions: flare

freynder

New Member
Dec 5, 2014
30
63
18
Just backup your main wallet and play around. In main.cpp there is stuff like GetNextWorkRequired, GetNextWorkRequired_V1, _V2, _V3 .... :)
The code is growing but really needs more people to clean up and refactor. Go ahead and suggest your changes :)
vertoe, I understand what you are saying, and I'm more than willing to help refactor. That is actually what I'm currently trying to do for the masternode start-many part.
The problem here is that both pubkeys are being sent with the dsee message so it's part of the protocol. I would really need to understand why there are 2 and if we need to keep it that way.

Thanks
 
  • Like
Reactions: thelonecrouton

UdjinM6

Official Dash Dev
Core Developer
Dash Core Group
May 20, 2014
3,639
3,537
1,183
Interesting...

That's pubkey for 1000DRK - you'll get it here only if you have 1000 DRK and corresponding privatekey
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L78
That's where you sign dsee message using private key for this pubkey
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L94-L97
This message will contain pubkey2 too which corresponds to masternodeprivkey and is used to start remote masternode initially
https://github.com/darkcoin/darkcoin/blob/master/src/masternode.cpp#L166-L168
And when remote is activated it will use masternodeprivkey to sign dseep messages
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L140-L143
So it works just as flare said.

How do you debug? I don't get same values...

I tried this (modify corresponding lines https://github.com/darkcoin/darkcoin/blob/master/src/rpcdarksend.cpp#L148-L155 )
Code:
            } else if (strCommand == "pubkey") {
                CScript pubkey;
                pubkey.SetDestination(mn.pubkey.GetID());
                CTxDestination address1;
                ExtractDestination(pubkey, address1);
                CBitcoinAddress address2(address1);

                CScript pubkey2;
                pubkey2.SetDestination(mn.pubkey2.GetID());
                CTxDestination address3;
                ExtractDestination(pubkey2, address3);
                CBitcoinAddress address4(address3);

                std::ostringstream oss;
                oss<<address2.ToString()<<" "<<address4.ToString();

                obj.push_back(Pair(mn.addr.ToString().c_str(), oss.str()));
output is like that
Code:
....
....
    "211.99.224.171:9999" : "XxQWzd53FShsxzVWjK4DK1zEXuZVyRwct3 XxHLGi8RX35S7EnxMLj2NeF5bTRYnCJnPx",
    "54.72.18.3:9999" : "XdDq5hZtsxGkWn5dRrK5G5UbYXfjsvNvVs XhWpjNmHQutfzWpzZ6KPkxV3HnLBHNvwGt",
    "95.85.32.155:9999" : "XxPVVDgCtQ2gU7UmHhUh6pNhZoCx6uFAw9 Xnp1oKoMHvunsmTMKWcHm5VZ4genk1zCSc",
    "54.165.115.235:9999" : "Xi9BboM55iDdwfYifDPta3KpcSDJWAfP4d XhBWD1X4PMomP2Eyq6nDaEKVw6Y2zbP4GL",
    "108.61.201.201:9999" : "XtnuWsW6f87yfcB9vj9Dw46LsV3hbNSm7V XcZ3eELtXzWEMoLE4fFuLtKcXh2UDkTg3U",
    "93.127.247.110:9999" : "XsjLSjFKWbpz97svPUpgEs5pSXmubW747i Xpqg9Lzo3r3e9m5LnEsHY2cUEu5muGcXb1",
    "95.85.21.42:9999" : "XbLQ2WUzo1rZ2cM9gQ76GzXFb9tPRUj4qZ XmvfhnM5QgAYY3ng3zxrcAYuPECjjGoQZR",
    "104.156.245.190:9999" : "XcxdmKBG2n3uEwASj7fKzuMHGL7PYM9Ln1 XhKxUAHzjRyTsoykgo4j2pRF76J5tjMYb2",
    "80.240.135.83:9999" : "Xw5FPEuCWc9iP2N6e2EBrN6TuiArzEe9S8 Xd2iLuru1Jhpvrm9N8MBN8vrCcmyt6Xs3G",
    "185.7.80.116:9999" : "XuTsRxt2b1jEuNXmAw5vcvLVxy29dvp8NB XmgMV2Enj4gsF5QZZCPujM2Ya58tGkRbG4",
    "178.62.171.16:9999" : "Xm3WuGCndadk9UzjK4DqVFv9wcTiqGTLcH XbaEh4297EfyFYMVHEeAMJE9L11AH37U3t",
    "54.66.252.217:9999" : "XmwkBGbQGNPczgjUXypomPBvDe2F7V6h6U XpGKerUfw1ojaBK12uRkkXRkeCFTGCypCF",
    "108.61.159.45:9999" : "XhmWHov6U6a7kwzqxC6KU2AKDJEqoMTATY Xq7dRBAZU9xsVK6rRvPNyNCaVxSWNo1YHL",
    "93.127.247.102:9999" : "XqZeZzVSZLRRo117jUr6K7vdgQAdvZGcqY XhMQGwSWHSTKwGW59tPeQpZUouRDKaVJ9o",
    "54.66.202.248:9999" : "XbEDaYK62sQrtSffRknZK6pKa2vATXvnkR XtvHxFL6BpVG8e2kZvcrPmNPRTaAATuEr1",
    "84.201.37.182:9999" : "XbkwRPtP8SvYcCfeANuVUijF7HzSm9SjvQ XiNfDbQqRUJYrtLK1eF3MpqhH4Ycpr75vh",
    "178.62.128.50:9999" : "XgMMszurpJgHuNEynpdjL1ByV46Z2iuqPH Xpkf3F16TgEqFmvDmLoTDBH7KUPiZzviXb",
    "178.62.172.188:9999" : "XcRHAyJAVTV8Co3svhrW65EJAq3Bq6BWrq Xv8fNAGmHUccE3prRxmZ1vMfj5F45S8vXZ",
    "178.62.128.51:9999" : "Xvk2BhYBkrej2bgSnXFxJnW2AZrsW4wKKa XxkfUyM5heqwq1SLoUebPhefV4wuFB3TXh",
    "54.189.241.81:9999" : "XxZP74LRx3BakkmHwhhq7iQBDKFXwhKxu9 Xhnz8KuoHXvK3ErP9rvfNLYWeN582h4TxW",
    "108.61.205.109:9999" : "XttdDiPKN5f4ztqGWAfFU7mHWurXe1BgSB XcMBHebAMRa3y11m2tieKGo7ka8Cez2Rqw",
.....
....
 
  • Like
Reactions: vertoe and flare

freynder

New Member
Dec 5, 2014
30
63
18
Interesting...

That's pubkey for 1000DRK - you'll get it here only if you have 1000 DRK and corresponding privatekey
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L78
That's where you sign dsee message using private key for this pubkey
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L94-L97
This message will contain pubkey2 too which corresponds to masternodeprivkey and is used to start remote masternode initially
https://github.com/darkcoin/darkcoin/blob/master/src/masternode.cpp#L166-L168
And when remote is activated it will use masternodeprivkey to sign dseep messages
https://github.com/darkcoin/darkcoin/blob/master/src/activemasternode.cpp#L140-L143
So it works just as flare said.

How do you debug? I don't get same values...

...
Hi UdjinM6,
I just checked again with a clean repository checkout and indeed it works as you are saying. I must have used a bugged instance while doing the refactoring which was very confusing.
Everything you and UdjinM6 stated is indeed correct. I apologize for the confusion.
Thank you
 
  • Like
Reactions: UdjinM6

UdjinM6

Official Dash Dev
Core Developer
Dash Core Group
May 20, 2014
3,639
3,537
1,183
Hi UdjinM6,
I just checked again with a clean repository checkout and indeed it works as you are saying. I must have used a bugged instance while doing the refactoring which was very confusing.
Everything you and UdjinM6 stated is indeed correct. I apologize for the confusion.
Thank you
No problem at all, it makes me really glad when someone is reviewing code and asking smth because it actually helps me to refresh my awareness of how things work too ;)
And as always: the more people look into code and understand it, the better it for Darkcoin and for everyone involved.
So thank you and keep it up! :)
 
Last edited by a moderator: