Skip to content

Commit 6a33d4f

Browse files
committed
[Policy] Set DEFAULT_SHIELDEDTXFEE_K to 100 (from 1000)
Thus reduce default min fee for shielded txes by 10x
1 parent 9d95c16 commit 6a33d4f

File tree

9 files changed

+37
-38
lines changed

9 files changed

+37
-38
lines changed

src/policy/policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee)
4747

4848
CAmount GetShieldedDustThreshold(const CFeeRate& dustRelayFee)
4949
{
50-
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (1000) for now
50+
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (100) for now
5151
return 3 * K * dustRelayFee.GetFee(SPENDDESCRIPTION_SIZE +
5252
CTXOUT_REGULAR_SIZE +
5353
BINDINGSIG_SIZE);

src/test/librust/sapling_wallet_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
565565
BOOST_CHECK_EQUAL(tx2.vin.size(), 0);
566566
BOOST_CHECK_EQUAL(tx2.vout.size(), 0);
567567
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedSpend.size(), 1);
568-
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedOutput.size(), 1); // 0.025 dust change added to the fee
569-
BOOST_CHECK_EQUAL(tx2.sapData->valueBalance, 12500000); // 0.025 dust change added to the fee
568+
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedOutput.size(), 2);
569+
BOOST_CHECK_EQUAL(tx2.sapData->valueBalance, 10000000);
570570

571571
CWalletTx wtx2 {&wallet, tx2};
572572

@@ -1115,8 +1115,8 @@ BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty) {
11151115
BOOST_CHECK_EQUAL(tx2.vin.size(), 0);
11161116
BOOST_CHECK_EQUAL(tx2.vout.size(), 0);
11171117
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedSpend.size(), 1);
1118-
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedOutput.size(), 1); // 0.05 dust change added to the fee
1119-
BOOST_CHECK_EQUAL(tx2.sapData->valueBalance, 15000000); // 0.05 dust change added to the fee
1118+
BOOST_CHECK_EQUAL(tx2.sapData->vShieldedOutput.size(), 2);
1119+
BOOST_CHECK_EQUAL(tx2.sapData->valueBalance, 10000000);
11201120

11211121
CWalletTx wtx2 {&wallet, tx2};
11221122

src/test/librust/transaction_builder_tests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(SaplingToSapling) {
6363
auto pa = sk.default_address();
6464

6565
// Create a Sapling-only transaction
66-
// --- 0.4 shielded-PIV in, 0.25 shielded-PIV out, 0.1 shielded-PIV fee, 0.05 shielded-PIV change (added to fee)
66+
// --- 0.4 shielded-PIV in, 0.299 shielded-PIV out, 0.1 shielded-PIV fee, 0.001 shielded-PIV change (added to fee)
6767
auto testNote = GetTestSaplingNote(pa, 40000000);
6868
auto builder = TransactionBuilder(consensusParams, 2);
6969
builder.AddSaplingSpend(expsk, testNote.note, testNote.tree.root(), testNote.tree.witness());
@@ -73,16 +73,15 @@ BOOST_AUTO_TEST_CASE(SaplingToSapling) {
7373
// TODO: the following check can be split out in to another test
7474
BOOST_CHECK_THROW(builder.AddSaplingSpend(expsk, testNote.note, uint256(), testNote.tree.witness()), std::runtime_error);
7575

76-
builder.AddSaplingOutput(fvk.ovk, pa, 25000000, {});
76+
builder.AddSaplingOutput(fvk.ovk, pa, 29900000, {});
7777
auto tx = builder.Build().GetTxOrThrow();
7878

7979
BOOST_CHECK_EQUAL(tx.vin.size(), 0);
8080
BOOST_CHECK_EQUAL(tx.vout.size(), 0);
8181
BOOST_CHECK_EQUAL(tx.sapData->vShieldedSpend.size(), 1);
82-
8382
// since the change is below the dust threshold, it is added to the fee
8483
BOOST_CHECK_EQUAL(tx.sapData->vShieldedOutput.size(), 1);
85-
BOOST_CHECK_EQUAL(tx.sapData->valueBalance, 15000000);
84+
BOOST_CHECK_EQUAL(tx.sapData->valueBalance, 10100000);
8685

8786
CValidationState state;
8887
BOOST_CHECK(SaplingValidation::ContextualCheckTransaction(tx, state, Params(), 3, true, false));

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ CAmount GetMinRelayFee(unsigned int nBytes, bool fAllowFree)
292292
CAmount GetShieldedTxMinFee(const CTransaction& tx)
293293
{
294294
assert (tx.IsShieldedTx());
295-
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (1000) for now
295+
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (100) for now
296296
CAmount nMinFee = ::minRelayTxFee.GetFee(tx.GetTotalSize()) * K;
297297
if (!Params().GetConsensus().MoneyRange(nMinFee))
298298
nMinFee = Params().GetConsensus().nMaxMoneyOut;

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
111111
* Blocks, whitelisted receivers, and a random 25% of transactions bypass this. */
112112
static const unsigned int AVG_INVENTORY_BROADCAST_INTERVAL = 5;
113113
/** Default multiplier used in the computation for shielded txes min fee */
114-
static const unsigned int DEFAULT_SHIELDEDTXFEE_K = 1000;
114+
static const unsigned int DEFAULT_SHIELDEDTXFEE_K = 100;
115115

116116
/** Enable bloom filter */
117117
static const bool DEFAULT_PEERBLOOMFILTERS = true;

test/functional/sapling_mempool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run_test(self):
2525
alice = self.nodes[1]
2626

2727
# Fixed fee
28-
fee = 1
28+
fee = 0.05
2929

3030
self.log.info("Mining 120 blocks...")
3131
miner.generate(120)
@@ -49,7 +49,7 @@ def run_test(self):
4949
# Alice creates and sends tx_B, unshielding the same note to tadd_B
5050
self.log.info("Alice creating and sending tx_B...")
5151
tadd_B = alice.getnewaddress()
52-
txid_B = alice.shieldsendmany(alice_zaddr, [{"address": tadd_B, "amount": Decimal('9.00')}], 1, fee)
52+
txid_B = alice.shieldsendmany(alice_zaddr, [{"address": tadd_B, "amount": Decimal('9.95')}], 1, fee)
5353

5454
# Miner receives tx_B and accepts it in the mempool
5555
assert (txid_B in alice.getrawmempool())

test/functional/sapling_supply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def generate_and_sync(self, count):
2424

2525
def check_shield_supply(self, z_supply):
2626
self.log.info("Checking supply...")
27-
assert_equal(self.nodes[0].getsupplyinfo()['shieldsupply'], z_supply)
27+
assert_equal(self.nodes[0].getsupplyinfo()['shieldsupply'], Decimal("%.8f" % z_supply))
2828
self.log.info("OK. Shield supply is %.8f" % z_supply)
2929

3030
def run_test(self):
31-
fee = 1
31+
fee = 0.05
3232
# First mine 101 blocks to mature one utxo
3333
self.log.info("Generating 101 blocks...")
3434
self.generate_and_sync(101)

test/functional/sapling_wallet.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run_test(self):
8383
self.log.info("Good. Not accepted in the mempool.")
8484

8585
# Fixed fee
86-
fee = 1
86+
fee = 0.05
8787

8888
# Node 0 shields some funds
8989
# taddr -> Sapling
@@ -209,11 +209,11 @@ def run_test(self):
209209
self.sync_all()
210210

211211
# Verify balance
212-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('3')) # 30 received - (20 sent + 3 fee) - 4 sent
213-
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('20')) # 20 received
214-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr2), Decimal('2')) # 10 received - 10 sent + 2 change
212+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('4.9')) # 30 received - (20 sent + 0.15 fee) - 4.95 sent
213+
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('20')) # 20 received
214+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr2), Decimal('3.9')) # 10 received - 10 sent + 3.9 change
215215
assert_equal(self.nodes[1].getreceivedbyaddress(taddr1), Decimal('0'))
216-
assert_equal(self.nodes[0].getshieldbalance(), Decimal('5'))
216+
assert_equal(self.nodes[0].getshieldbalance(), Decimal('8.8'))
217217
self.log.info("Balances check out")
218218

219219
# Node 1 sends some shield funds to node 0, as well as unshielding
@@ -230,14 +230,14 @@ def run_test(self):
230230
self.sync_all()
231231

232232
# Verify balance
233-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('11')) # 3 prev balance + 8 received
234-
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('1')) # 20 prev balance - (18 sent + 1 fee)
233+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('12.9')) # 4.9 prev balance + 8 received
234+
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('1.95')) # 20 prev balance - (18 sent + 0.05 fee)
235235
assert_equal(self.nodes[1].getreceivedbyaddress(taddr1), Decimal('10'))
236236
self.log.info("Balances check out")
237237

238238
# Verify existence of Sapling related JSON fields
239239
resp = self.nodes[0].getrawtransaction(mytxid7, 1)
240-
assert_equal(Decimal(resp['valueBalance']), Decimal('11.00')) # 20 shield input - 8 shield spend - 1 change
240+
assert_equal(Decimal(resp['valueBalance']), Decimal('10.05')) # 20 shield input - 8 shield spend - 1.95 change
241241
assert_equal(len(resp['vShieldSpend']), 3)
242242
assert_equal(len(resp['vShieldOutput']), 2)
243243
assert('bindingSig' in resp)
@@ -262,26 +262,26 @@ def run_test(self):
262262
sk0 = self.nodes[0].exportsaplingkey(saplingAddr0)
263263
saplingAddrInfo0 = self.nodes[2].importsaplingkey(sk0, "yes")
264264
assert_equal(saplingAddrInfo0["address"], saplingAddr0)
265-
assert_equal(self.nodes[2].getshieldbalance(saplingAddrInfo0["address"]), Decimal('11'))
265+
assert_equal(self.nodes[2].getshieldbalance(saplingAddrInfo0["address"]), Decimal('12.9'))
266266
sk1 = self.nodes[1].exportsaplingkey(saplingAddr1)
267267
saplingAddrInfo1 = self.nodes[2].importsaplingkey(sk1, "yes")
268268
assert_equal(saplingAddrInfo1["address"], saplingAddr1)
269-
assert_equal(self.nodes[2].getshieldbalance(saplingAddrInfo1["address"]), Decimal('1'))
269+
assert_equal(self.nodes[2].getshieldbalance(saplingAddrInfo1["address"]), Decimal('1.95'))
270270

271271
# Verify importing a viewing key will update the nullifiers and witnesses correctly
272272
self.log.info("Checking exporting/importing a viewing key...")
273273
extfvk0 = self.nodes[0].exportsaplingviewingkey(saplingAddr0)
274274
saplingAddrInfo0 = self.nodes[3].importsaplingviewingkey(extfvk0, "yes")
275275
assert_equal(saplingAddrInfo0["address"], saplingAddr0)
276-
assert_equal(Decimal(self.nodes[3].getshieldbalance(saplingAddrInfo0["address"], 1, True)), Decimal('11'))
276+
assert_equal(Decimal(self.nodes[3].getshieldbalance(saplingAddrInfo0["address"], 1, True)), Decimal('12.9'))
277277
extfvk1 = self.nodes[1].exportsaplingviewingkey(saplingAddr1)
278278
saplingAddrInfo1 = self.nodes[3].importsaplingviewingkey(extfvk1, "yes")
279279
assert_equal(saplingAddrInfo1["address"], saplingAddr1)
280-
assert_equal(self.nodes[3].getshieldbalance(saplingAddrInfo1["address"], 1, True), Decimal('1'))
280+
assert_equal(self.nodes[3].getshieldbalance(saplingAddrInfo1["address"], 1, True), Decimal('1.95'))
281281
# no balance in the wallet
282282
assert_equal(self.nodes[3].getshieldbalance(), Decimal('0'))
283283
# watch only balance
284-
assert_equal(self.nodes[3].getshieldbalance("*", 1, True), Decimal('12.00'))
284+
assert_equal(self.nodes[3].getshieldbalance("*", 1, True), Decimal('14.85'))
285285

286286
# Now shield some funds using sendmany
287287
self.log.info("TX11: Shielding coins to multiple destinations with sendmany RPC...")
@@ -318,9 +318,9 @@ def run_test(self):
318318
# Verify balance
319319
self.nodes[2].generate(1)
320320
self.sync_all()
321-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('19')) # 11 prev balance + 8 received
322-
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('2')) # 1 prev balance + 1 received
323-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr2), Decimal('2.5')) # 2 prev balance + 0.5 received
321+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('20.9')) # 12.9 prev balance + 8 received
322+
assert_equal(self.nodes[1].getshieldbalance(saplingAddr1), Decimal('2.95')) # 1.95 prev balance + 1 received
323+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr2), Decimal('4.4')) # 3.9 prev balance + 0.5 received
324324
# Balance of node 0 is: prev_balance - 1 PIV (+fee) sent externally + 250 PIV matured coinbase
325325
assert_equal(self.nodes[0].getbalance(), satoshi_round(prev_balance + Decimal('249') - Decimal(fee)))
326326

@@ -345,7 +345,7 @@ def run_test(self):
345345
# Verify balance
346346
self.nodes[2].generate(1)
347347
self.sync_all()
348-
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('29')) # 19 prev balance + 10 received
348+
assert_equal(self.nodes[0].getshieldbalance(saplingAddr0), Decimal('30.9')) # 20.9 prev balance + 10 received
349349

350350
self.log.info("All good.")
351351

test/functional/sapling_wallet_listreceived.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def run_test(self):
4848
self.nodes[1].shieldsendmany, taddr,
4949
[{'address': shield_addr1, 'amount': 2, 'memo': too_big_memo_str}])
5050
# Fixed fee
51-
fee = 0.5
51+
fee = 0.05
5252

5353
# Send 1 PIV to shield addr1
5454
txid = self.nodes[1].shieldsendmany(taddr, [ # node_1 with 6 PIV sending them all (fee is 0.1 PIV)
@@ -128,9 +128,9 @@ def run_test(self):
128128
# Generate some change by sending part of shield_addr1 to shield_addr2
129129
txidPrev = txid
130130
shield_addr2 = self.nodes[1].getnewshieldaddress()
131-
txid = self.nodes[1].shieldsendmany(shield_addr1, # shield_addr1 has 2 PIV, send 0.6 PIV + 0.5 PIV fee
131+
txid = self.nodes[1].shieldsendmany(shield_addr1, # shield_addr1 has 2 PIV, send 0.6 PIV + 0.05 PIV fee
132132
[{'address': shield_addr2, 'amount': 0.6, "memo": non_ascii_memo_str}],
133-
1, fee) # change 0.9
133+
1, fee) # change 1.35
134134
self.sync_all()
135135
self.generate_and_sync(height+4)
136136

@@ -165,8 +165,8 @@ def run_test(self):
165165
assert_equal(out['address'], shield_addr1)
166166
assert_equal(out['outgoing'], False)
167167
assert_equal(out['memo'], no_memo)
168-
assert_equal(out['value'], Decimal('0.9'))
169-
assert_equal(out['valueSat'], 90000000)
168+
assert_equal(out['value'], Decimal('1.35'))
169+
assert_equal(out['valueSat'], 135000000)
170170
found[1] = True
171171
assert_equal(found, [True] * 2)
172172

@@ -176,7 +176,7 @@ def run_test(self):
176176
assert_true(2 == len(r), "shield_addr1 Should have received 2 notes")
177177

178178
assert_equal(txid, r[0]['txid'])
179-
assert_equal(Decimal('0.9'), r[0]['amount'])
179+
assert_equal(Decimal('1.35'), r[0]['amount'])
180180
assert_true(r[0]['change'], "Note valued at (1.4-fee) should be change")
181181
assert_equal(no_memo, r[0]['memo'])
182182

0 commit comments

Comments
 (0)