Browse Source

Merge branch 'duke' into dev

pull/97/head
Duke Leto 4 years ago
parent
commit
448b72f270
  1. 2
      src/init.cpp
  2. 13
      src/wallet/asyncrpcoperation_saplingconsolidation.cpp
  3. 31
      src/wallet/rpcwallet.cpp
  4. 126
      src/wallet/wallet.cpp
  5. 2
      src/wallet/wallet.h

2
src/init.cpp

@ -1936,7 +1936,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
pwalletMain->GenerateNewSeed();
}
//Set Sapling Consolidation
//Set Sapling Consolidation
pwalletMain->fSaplingConsolidationEnabled = GetBoolArg("-consolidation", false);
fConsolidationTxFee = GetArg("-consolidationtxfee", DEFAULT_CONSOLIDATION_FEE);
fConsolidationMapUsed = !mapMultiArgs["-consolidatesaplingaddress"].empty();

13
src/wallet/asyncrpcoperation_saplingconsolidation.cpp

@ -209,10 +209,15 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
break;
}
pwalletMain->CommitConsolidationTx(tx);
LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n", getId(), tx.GetHash().ToString());
amountConsolidated += amountToSend - fConsolidationTxFee;
consolidationTxIds.push_back(tx.GetHash().ToString());
if(pwalletMain->CommitConsolidationTx(tx)) {
LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n", getId(), tx.GetHash().ToString());
amountConsolidated += amountToSend - fConsolidationTxFee;
consolidationTxIds.push_back(tx.GetHash().ToString());
} else {
LogPrint("zrpcunsafe", "%s: Consolidation transaction FAILED in CommitTransaction, txid=%s\n", getId(), tx.GetHash().ToString());
setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds);
return false;
}
}
}

31
src/wallet/rpcwallet.cpp

@ -79,6 +79,8 @@ int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only
CBlockIndex *komodo_getblockindex(uint256 hash);
extern string randomSietchZaddr();
extern CAmount fConsolidationTxFee;
extern bool fZindex;
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
@ -3479,6 +3481,34 @@ UniValue z_listreceivedaddress(const UniValue& params, bool fHelp,const CPubKey&
return ret;
}
UniValue z_getinfo(const UniValue& params, bool fHelp,const CPubKey&)
{
if (fHelp || params.size() > 0) {
throw runtime_error(
"z_getinfo\n"
"\nReturns various information about shielded operations, such as sapling consolidation details.\n"
);
}
UniValue result(UniValue::VOBJ);
result.push_back(Pair("zindex",(bool)fZindex));
result.push_back(Pair("consolidation",(bool)pwalletMain->fSaplingConsolidationEnabled ));
result.push_back(Pair("consolidationtxfee",(int)fConsolidationTxFee));
result.push_back(Pair("deletetx",(bool)fTxDeleteEnabled));
result.push_back(Pair("delete_interval",(int)fDeleteInterval));
result.push_back(Pair("keeptxnum",(int)fKeepLastNTransactions));
result.push_back(Pair("keeptxfornblocks",(int)fDeleteTransactionsAfterNBlocks));
std::set<libzcash::SaplingPaymentAddress> saplingzaddrs = {};
pwalletMain->GetSaplingPaymentAddresses(saplingzaddrs);
result.push_back(Pair("num_sapling_zaddrs",(int)saplingzaddrs.size()));
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::vector<AsyncRPCOperationId> ids = q->getAllOperationIds();
result.push_back(Pair("num_op_ids",(int)ids.size()));
return result;
}
UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&)
{
if (!EnsureWalletIsAvailable(fHelp))
@ -8326,6 +8356,7 @@ static const CRPCCommand commands[] =
{ "wallet", "z_exportwallet", &z_exportwallet, true },
{ "wallet", "z_importwallet", &z_importwallet, true },
{ "wallet", "z_viewtransaction", &z_viewtransaction, true },
{ "wallet", "z_getinfo", &z_getinfo, true },
{ "wallet", "z_listsentbyaddress", &z_listsentbyaddress, true },
{ "wallet", "z_listreceivedbyaddress", &z_listreceivedbyaddress, true },
// TODO: rearrange into another category

126
src/wallet/wallet.cpp

@ -637,10 +637,10 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
}
}
void CWallet::CommitConsolidationTx(const CTransaction& tx) {
bool CWallet::CommitConsolidationTx(const CTransaction& tx) {
CWalletTx wtx(this, tx);
CReserveKey reservekey(pwalletMain);
CommitTransaction(wtx, reservekey);
return CommitTransaction(wtx, reservekey);
}
void CWallet::SetBestChain(const CBlockLocator& loc)
@ -1173,96 +1173,6 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO
auto wtxHash = wtxItem.second.GetHash();
int wtxHeight = mapBlockIndex[wtxItem.second.hashBlock]->GetHeight();
for (mapSproutNoteData_t::value_type& item : wtxItem.second.mapSproutNoteData) {
auto op = item.first;
auto* nd = &(item.second);
CBlockIndex* pblockindex;
uint256 blockRoot;
uint256 witnessRoot;
if (!nd->nullifier)
::ClearSingleNoteWitnessCache(nd);
if (!nd->witnesses.empty() && nd->witnessHeight > 0) {
//Skip all functions for validated witness while witness only = true
if (nd->witnessRootValidated && witnessOnly)
continue;
//Skip Validation when witness root has been validated
if (nd->witnessRootValidated) {
nMinimumHeight = SproutWitnessMinimumHeight(*item.second.nullifier, nd->witnessHeight, nMinimumHeight);
continue;
}
//Skip Validation when witness height is greater that block height
if (nd->witnessHeight > pindex->GetHeight() - 1) {
nMinimumHeight = SproutWitnessMinimumHeight(*item.second.nullifier, nd->witnessHeight, nMinimumHeight);
continue;
}
//Validate the witness at the witness height
witnessRoot = nd->witnesses.front().root();
pblockindex = chainActive[nd->witnessHeight];
blockRoot = pblockindex->hashFinalSproutRoot;
if (witnessRoot == blockRoot) {
nd->witnessRootValidated = true;
nMinimumHeight = SproutWitnessMinimumHeight(*item.second.nullifier, nd->witnessHeight, nMinimumHeight);
continue;
}
}
//Clear witness Cache for all other scenarios
pblockindex = chainActive[wtxHeight];
::ClearSingleNoteWitnessCache(nd);
LogPrintf("Setting Inital Sprout Witness for tx %s, %i of %i\n", wtxHash.ToString(), nWitnessTxIncrement, nWitnessTotalTxCount);
SproutMerkleTree sproutTree;
blockRoot = pblockindex->pprev->hashFinalSproutRoot;
pcoinsTip->GetSproutAnchorAt(blockRoot, sproutTree);
//Cycle through blocks and transactions building sprout tree until the commitment needed is reached
const CBlock* pblock;
CBlock block;
ReadBlockFromDisk(block, pblockindex, 1);
pblock = &block;
for (const CTransaction& tx : block.vtx) {
auto hash = tx.GetHash();
for (size_t i = 0; i < tx.vjoinsplit.size(); i++) {
const JSDescription& jsdesc = tx.vjoinsplit[i];
for (uint8_t j = 0; j < jsdesc.commitments.size(); j++) {
const uint256& note_commitment = jsdesc.commitments[j];
// Increment existing witness until the end of the block
if (!nd->witnesses.empty()) {
nd->witnesses.front().append(note_commitment);
}
//Only needed for intial witness
if (nd->witnesses.empty()) {
sproutTree.append(note_commitment);
// If this is our note, witness it
if (hash == wtxHash) {
JSOutPoint outPoint {hash, i, j};
if (op == outPoint) {
nd->witnesses.push_front(sproutTree.witness());
}
}
}
}
}
}
nd->witnessHeight = pblockindex->GetHeight();
UpdateSproutNullifierNoteMapWithTx(wtxItem.second);
nMinimumHeight = SproutWitnessMinimumHeight(*item.second.nullifier, nd->witnessHeight, nMinimumHeight);
}
for (mapSaplingNoteData_t::value_type& item : wtxItem.second.mapSaplingNoteData) {
auto op = item.first;
@ -1307,7 +1217,7 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO
pblockindex = chainActive[wtxHeight];
::ClearSingleNoteWitnessCache(nd);
LogPrintf("Setting Inital Sapling Witness for tx %s, %i of %i\n", wtxHash.ToString(), nWitnessTxIncrement, nWitnessTotalTxCount);
LogPrintf("Setting Initial Sapling Witness for tx %s, %i of %i\n", wtxHash.ToString(), nWitnessTxIncrement, nWitnessTotalTxCount);
SaplingMerkleTree saplingTree;
blockRoot = pblockindex->pprev->hashFinalSaplingRoot;
@ -1396,31 +1306,6 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly)
if (wtxItem.second.GetDepthInMainChain() > 0) {
//Sprout
for (mapSproutNoteData_t::value_type& item : wtxItem.second.mapSproutNoteData) {
auto* nd = &(item.second);
if (nd->nullifier && nd->witnessHeight == pblockindex->GetHeight() - 1
&& GetSproutSpendDepth(*item.second.nullifier) <= WITNESS_CACHE_SIZE) {
nd->witnesses.push_front(nd->witnesses.front());
while (nd->witnesses.size() > WITNESS_CACHE_SIZE) {
nd->witnesses.pop_back();
}
for (const CTransaction& tx : block.vtx) {
for (size_t i = 0; i < tx.vjoinsplit.size(); i++) {
const JSDescription& jsdesc = tx.vjoinsplit[i];
for (uint8_t j = 0; j < jsdesc.commitments.size(); j++) {
const uint256& note_commitment = jsdesc.commitments[j];
nd->witnesses.front().append(note_commitment);
}
}
}
nd->witnessHeight = pblockindex->GetHeight();
}
}
//Sapling
for (mapSaplingNoteData_t::value_type& item : wtxItem.second.mapSaplingNoteData) {
auto* nd = &(item.second);
@ -1639,11 +1524,6 @@ void CWallet::UpdateNullifierNoteMapWithTx(const CWalletTx& wtx)
{
{
LOCK(cs_wallet);
for (const mapSproutNoteData_t::value_type& item : wtx.mapSproutNoteData) {
if (item.second.nullifier) {
mapSproutNullifiersToNotes[*item.second.nullifier] = item.first;
}
}
for (const mapSaplingNoteData_t::value_type& item : wtx.mapSaplingNoteData) {
if (item.second.nullifier) {

2
src/wallet/wallet.h

@ -1258,7 +1258,7 @@ public:
const CBlock *pblock,
boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added);
void RunSaplingConsolidation(int blockHeight);
void CommitConsolidationTx(const CTransaction& tx);
bool CommitConsolidationTx(const CTransaction& tx);
/** Saves witness caches and best block locator to disk. */
void SetBestChain(const CBlockLocator& loc);
std::set<std::pair<libzcash::PaymentAddress, uint256>> GetNullifiersForAddresses(const std::set<libzcash::PaymentAddress> & addresses);

Loading…
Cancel
Save