Change default anchor depth from 10 confirmations to 3

This commit is contained in:
Kris Nuttycombe 2022-05-06 18:05:39 -06:00
parent 954e2b4aa6
commit 295f7d9f7b
5 changed files with 29 additions and 18 deletions

View File

@ -11,23 +11,20 @@ Option handling
(provided that the wallet is enabled and pruning is disabled, and unless
`-rescan=0` is specified explicitly).
- A new `-anchorconfirmations` argument has been added to allow the user
to specify the number of blocks back from the chain tip that anchors
will be selected from when spending notes. By default, anchors will
now be selected to have 10 confirmations. Values
greater than 100 are not supported.
to specify the number of blocks back from the chain tip that anchors will be
selected from when spending notes. By default, anchors will now be selected
to have 3 confirmations. Values greater than 100 are not supported.
RPC Interface
-------------
- The default `minconf` value for `z_sendmany` is now 10 confirmations instead
of 1. This default corresponds to the number of anchor confirmations
required, which may be configured with the `-anchorconfirmations` argument
when starting the node. If `minconf` is explicitly supplied, it will override
the default value provided by `-anchorconfirmations` if `minconf` specifies
a smaller value than the default (it is not possible to spend notes that
are more recent than the anchor). Selecting `minconf` values less than the default
is not recommended, as it allows the transaction to be distinguished from transactions
using the default for `-anchorconfirmations`.
of 1. If `minconf` and specifies a value less than that provided for
`-anchorconfirmations`, it will also override that value as it is not
possible to spend notes that are more recent than the anchor. Selecting
`minconf` values less than 3 is not recommended, as it allows the transaction
to be distinguished from transactions using the default for
`-anchorconfirmations`.
Build system
------------

View File

@ -688,6 +688,8 @@ impl Wallet {
.collect()
}
/// Returns the note of the Orchard note commitment tree, as of the specified checkpoint
/// depth. A depth of 0 corresponds to the chain tip.
pub fn note_commitment_tree_root(&self, checkpoint_depth: usize) -> Option<MerkleHashOrchard> {
self.witness_tree.root(checkpoint_depth)
}

View File

@ -1397,19 +1397,29 @@ TEST(WalletTests, CachedWitnessesEmptyChain) {
const auto& params = Params().GetConsensus();
wallet.IncrementNoteWitnesses(params, &index, &block, frontiers, true);
// this death will occur because there will not be sufficient Sprout witnesses to reach the
// default anchor depth
EXPECT_DEATH(::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, nAnchorConfirmations, sproutWitnesses, saplingWitnesses),
"GetSproutNoteWitnesses");
for (int i = 1; i <= 8; i++) {
// add another block; we still don't have enough witnesses
{
CBlock another_block;
CBlockIndex another_index(another_block);
another_index.nHeight = i;
another_index.nHeight = 1;
wallet.IncrementNoteWitnesses(params, &another_index, &another_block, frontiers, true);
}
EXPECT_DEATH(::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, nAnchorConfirmations, sproutWitnesses, saplingWitnesses),
"GetSproutNoteWitnesses");
for (int i = 2; i <= 8; i++) {
CBlock another_block;
CBlockIndex another_index(another_block);
another_index.nHeight = i;
wallet.IncrementNoteWitnesses(params, &another_index, &another_block, frontiers, true);
}
CBlock last_block;
CBlockIndex last_index(last_block);
last_index.nHeight = 9;

View File

@ -4878,7 +4878,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
" \"amount\":amount (numeric, required) The numeric amount in " + CURRENCY_UNIT + " is the value\n"
" \"memo\":memo (string, optional) If the address is a zaddr, raw data represented in hexadecimal string format\n"
" }, ... ]\n"
"3. minconf (numeric, optional, default=" + strprintf("%u", nAnchorConfirmations) + ") Only use funds confirmed at least this many times.\n"
"3. minconf (numeric, optional, default=" + strprintf("%u", DEFAULT_NOTE_CONFIRMATIONS) + ") Only use funds confirmed at least this many times.\n"
"4. fee (numeric, optional, default=" + strprintf("%s", FormatMoney(DEFAULT_FEE)) + ") The fee amount to attach to this transaction.\n"
"5. privacyPolicy (string, optional, default=\"LegacyCompat\") Policy for what information leakage is acceptable.\n"
" One of the following strings:\n"
@ -5090,7 +5090,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
}
// Minimum confirmations
int nMinDepth = nAnchorConfirmations;
int nMinDepth = DEFAULT_NOTE_CONFIRMATIONS;
if (params.size() > 2) {
nMinDepth = params[2].get_int();
}
@ -5829,7 +5829,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
useAnySprout || useAnySapling ?
std::nullopt :
std::optional(NoteFilter::ForPaymentAddresses(zaddrs));
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, orchardEntries, noteFilter, nAnchorConfirmations);
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, orchardEntries, noteFilter, DEFAULT_NOTE_CONFIRMATIONS);
// If Sapling is not active, do not allow sending from a sapling addresses.
if (!saplingActive && saplingEntries.size() > 0) {

View File

@ -79,7 +79,9 @@ static const unsigned int WITNESS_CACHE_SIZE = MAX_REORG_LENGTH + 1;
//! Amount of entropy used in generation of the mnemonic seed, in bytes.
static const size_t WALLET_MNEMONIC_ENTROPY_LENGTH = 32;
//! -anchorconfirmations default
static const unsigned int DEFAULT_ANCHOR_CONFIRMATIONS = 10;
static const unsigned int DEFAULT_ANCHOR_CONFIRMATIONS = 3;
// Default minimum number of confirmations for note selection
static const unsigned int DEFAULT_NOTE_CONFIRMATIONS = 10;
extern const char * DEFAULT_WALLET_DAT;