Clean up some LABS related code, remove un-used/needed stuff.

Adds actual working and feild tested wallet filter. Can set any amount 
of whitelist address's, in conf file or commandline args. 
fix daemon deadlock, when doing z_mergetoaddress and mining at same time 
(needs more testing on staking chains) 
Set z_mergtoaddress to use a 0 expiry height when not doing z-tx's. They 
were failing and peers were getting banned trying to broadcast them.
This commit is contained in:
blackjok3r
2019-04-09 18:53:32 +08:00
parent e101aa3f9b
commit 237f115594
10 changed files with 40 additions and 112 deletions

View File

@@ -38,6 +38,7 @@
#include "crypter.h"
#include "coins.h"
#include "zcash/zip32.h"
#include "cc/CCinclude.h"
#include <assert.h>
@@ -1747,11 +1748,6 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
* pblock is optional, but should be provided if the transaction is known to be in a block.
* If fUpdate is true, existing transactions will be updated.
*/
extern uint8_t NOTARY_PUBKEY33[33];
extern std::string NOTARY_ADDRESS,WHITELIST_ADDRESS;
extern int32_t IS_STAKED_NOTARY;
extern uint64_t MIN_RECV_SATS;
#include "cc/CCinclude.h"
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate)
{
@@ -1777,14 +1773,20 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
char Raddress[64];
pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33);
NotaryAddress.assign(Raddress);
fprintf(stderr, "notary address set to %s\n", NotaryAddress.c_str());
vWhiteListAddress = mapMultiArgs["-whitelistaddress"];
if ( !vWhiteListAddress.empty() )
{
fprintf(stderr, "Activated Wallet Filter \n Notary Address: %s \n Adding whitelist address's:\n", NotaryAddress.c_str());
for ( auto wladdr : vWhiteListAddress )
fprintf(stderr, " %s\n", wladdr.c_str());
}
}
if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0)
{
// wallet filter for notary nodes. Disabled! Can be reenabled or customised for any specific use, pools could also use this to prevent wallet dwy attack.
if ( !tx.IsCoinBase() && !WHITELIST_ADDRESS.empty() && !NotaryAddress.empty() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 )
// wallet filter for notary nodes. Enables by setting -whitelistaddress= as startup param or in conf file (works same as -addnode byut with R-address's)
if ( !tx.IsCoinBase() && !vWhiteListAddress.empty() && !NotaryAddress.empty() )
{
int numvinIsOurs = 0, numvinIsWhiteList = 0; // numvoutIsOurs = 0, int64_t totalvoutvalue = 0;
int numvinIsOurs = 0, numvinIsWhiteList = 0;
for (size_t i = 0; i < tx.vin.size(); i++)
{
uint256 hash; CTransaction txin; CTxDestination address;
@@ -1792,50 +1794,21 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
{
if ( CBitcoinAddress(address).ToString() == NotaryAddress )
numvinIsOurs++;
if ( CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS )
numvinIsWhiteList++;
}
}
// Now we know if it was a tx sent to us, that wasnt from ourself or the whitelist address if set..
if ( numvinIsOurs != 0 )
fprintf(stderr, "We sent from address: %s vins: %d\n",NotaryAddress.c_str(),numvinIsOurs);
if ( numvinIsWhiteList != 0 )
fprintf(stderr, "We received from whitelisted address: %s\n",WHITELIST_ADDRESS.c_str());
// Count vouts, check if OUR notary address is the receiver.
if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 )
{
return false;
/*/ if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions.
if ( 1 ) { //MIN_RECV_SATS == 0 ) {
fprintf(stderr, "This node is on full lock down all txs are ignored! \n");
return false;
}
for (size_t i = 0; i < tx.vout.size() ; i++)
{
CTxDestination address2;
if ( ExtractDestination(tx.vout[i].scriptPubKey, address2))
for ( auto wladdr : vWhiteListAddress )
{
if ( CBitcoinAddress(address2).ToString() == NOTARY_ADDRESS )
if ( CBitcoinAddress(address).ToString() == wladdr )
{
numvoutIsOurs++;
totalvoutvalue += tx.vout[i].nValue;
//fprintf(stderr, "We received from whitelisted address.%s\n", wladdr.c_str());
numvinIsWhiteList++;
}
}
}
// If no vouts are to the notary address we will ignore them.
if ( numvoutIsOurs == 0 ) {
fprintf(stderr, "Received transaction to address other than notary address, ignored! \n");
return false;
}
fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,(int32_t)numvoutIsOurs);
// here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not.
int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs;
if ( avgVoutSize < MIN_RECV_SATS ) {
// average vout size is less than set minimum, default is 1 coin, we will ignore it
fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, (long)avgVoutSize);
return false;
} */
}
// Now we know if it was a tx sent to us, by either a whitelisted address, or ourself.
if ( numvinIsOurs != 0 )
fprintf(stderr, "We sent from address: %s vins: %d\n",NotaryAddress.c_str(),numvinIsOurs);
if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 )
return false;
}
CWalletTx wtx(this,tx);