Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Context {
* expected to do this yourself.
*/
public Context() {
this(DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE, true, false);
this(DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE_RATE, true, false);
}

/**
Expand Down
16 changes: 12 additions & 4 deletions core/src/main/java/org/bitcoinj/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,28 @@ private static int sortableBlockHeight(Transaction tx) {
public static final int MAX_STANDARD_TX_SIZE = 100_000;

/**
* If feePerKb is lower than this, Bitcoin Core will treat it as if there were no fee.
* If fee rate is lower than this, Bitcoin Core will treat it as if there were no fee.
*/
public static final Coin REFERENCE_DEFAULT_MIN_TX_FEE = Coin.valueOf(1_000); // 0.01 mBTC
public static final Coin REFERENCE_DEFAULT_MIN_TX_FEE_RATE = Coin.valueOf(100); // per vkB

/** @deprecated use {@link #REFERENCE_DEFAULT_MIN_TX_FEE_RATE} */
@Deprecated
public static final Coin REFERENCE_DEFAULT_MIN_TX_FEE = REFERENCE_DEFAULT_MIN_TX_FEE_RATE;

/**
* Minimum feerate for defining dust, in sats per kB.
*/
public static final Coin DUST_RELAY_TX_FEE_RATE = Coin.valueOf(3_000); // per kB

/**
* If using this feePerKb, transactions will get confirmed within the next couple of blocks.
* If using this fee rate, transactions will get confirmed within the next couple of blocks.
* This should be adjusted from time to time. Last adjustment: February 2017.
*/
public static final Coin DEFAULT_TX_FEE = Coin.valueOf(100_000); // 1 mBTC
public static final Coin DEFAULT_TX_FEE_RATE = Coin.valueOf(100_000); // per vkB

/** @deprecated use {@link #DEFAULT_TX_FEE_RATE} */
@Deprecated
public static final Coin DEFAULT_TX_FEE = DEFAULT_TX_FEE_RATE;

/**
* The scale factor for Witness data in Segregated Witness transactions.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/wallet/SendRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setFeePerVkb(Coin feePerVkb) {
*
* <p>Note that this does not enforce certain fee rules that only apply to transactions which are larger than
* 26,000 bytes. If you get a transaction which is that large, you should set a feePerKb of at least
* {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}.</p>
* {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE_RATE}.</p>
*/
public boolean ensureMinRequiredFee = Context.get().isEnsureMinRequiredFee();

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/bitcoinj/wallet/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4552,7 +4552,7 @@ public void signTransaction(SendRequest req) throws BadWalletEncryptionKeyExcept

/**
* Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size.
* If ensureMinRequiredFee is true, feePerKb is set to at least {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE}.
* If ensureMinRequiredFee is true, feePerKb is set to at least {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE_RATE}.
* @return true if output is not dust
*/
private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb,
Expand Down Expand Up @@ -5345,8 +5345,8 @@ private void addSuppliedInputs(Transaction tx, List<TransactionInput> originalIn
}

private Coin estimateFees(Transaction tx, CoinSelection coinSelection, Coin requestedFeePerKb, boolean ensureMinRequiredFee) {
Coin feePerKb = (ensureMinRequiredFee && requestedFeePerKb.isLessThan(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE))
? Transaction.REFERENCE_DEFAULT_MIN_TX_FEE
Coin feePerKb = (ensureMinRequiredFee && requestedFeePerKb.isLessThan(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE_RATE))
? Transaction.REFERENCE_DEFAULT_MIN_TX_FEE_RATE
: requestedFeePerKb;
int vSize = tx.getVsize() + estimateVirtualBytesForSigning(coinSelection.outputs());
return feePerKb.multiply(vSize).divide(1000);
Expand Down Expand Up @@ -5653,7 +5653,7 @@ private Transaction rekeyOneBatch(Instant time, @Nullable AesKey aesKey, List<Tr
}
// When not signing, don't waste addresses.
rekeyTx.addOutput(toMove.totalValue(), sign ? freshReceiveAddress() : currentReceiveAddress());
if (!adjustOutputDownwardsForFee(rekeyTx, toMove, Transaction.DEFAULT_TX_FEE, true)) {
if (!adjustOutputDownwardsForFee(rekeyTx, toMove, Transaction.DEFAULT_TX_FEE_RATE, true)) {
log.error("Failed to adjust rekey tx for fees.");
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/org/bitcoinj/core/ParseByteCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.bitcoinj.core;

import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.ScriptType;
import org.bitcoinj.base.internal.TimeUtils;
import org.bitcoinj.base.internal.ByteUtils;
Expand Down Expand Up @@ -71,7 +72,7 @@ private void resetBlockStore() {
@Before
public void setUp() throws Exception {
TimeUtils.setMockClock(); // Use mock clock
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
Wallet wallet = Wallet.createDeterministic(BitcoinNetwork.TESTNET, ScriptType.P2PKH);
wallet.freshReceiveKey();

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/bitcoinj/core/TransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public void optInFullRBF() {
*/
@Test
public void testHashForSignatureThreadSafety() throws Exception {
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
Block genesis = TESTNET.getGenesisBlock();
Block block1 = TestBlocks.createNextBlock(genesis, ECKey.random().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET),
genesis.transaction(0).getOutput(0).getOutPointFor());
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/org/bitcoinj/store/SPVBlockStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.bitcoinj.store;

import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.Difficulty;
import org.bitcoinj.base.ScriptType;
import org.bitcoinj.base.Address;
Expand All @@ -31,7 +32,6 @@
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.base.Sha256Hash;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.params.TestNet3Params;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void setup() throws Exception {

@Test
public void basics() throws Exception {
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile);

Address to = ECKey.random().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
Expand Down Expand Up @@ -125,7 +125,7 @@ public void twoStores_sequentially_butMismatchingCapacity() throws Exception {

@Test
public void twoStores_sequentially_grow() throws Exception {
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
Address to = ECKey.random().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile, 10, true);
final StoredBlock block0 = store.getChainHead();
Expand Down Expand Up @@ -178,7 +178,7 @@ public void performanceTest() throws BlockStoreException {

@Test
public void clear() throws Exception {
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile);

// Build a new block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void testSequenceNumber() throws Exception {
@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
// Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
BlockChain chain = new BlockChain(BitcoinNetwork.TESTNET, myWallet, new MemoryBlockStore(TESTNET.getGenesisBlock()));

final ArrayList<Transaction> txns = new ArrayList<>(2);
Expand Down Expand Up @@ -377,7 +377,7 @@ public void roundtripVersionTwoTransaction() throws Exception {
@Test
public void coinbaseTxns() throws Exception {
// Covers issue 420 where the outpoint index of a coinbase tx input was being mis-serialized.
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
Block b = TestBlocks.createNextBlockWithCoinbase(TESTNET.getGenesisBlock(), Block.BLOCK_VERSION_GENESIS, myKey.getPubKey(), FIFTY_COINS, Block.BLOCK_HEIGHT_GENESIS);
Transaction coinbase = b.transaction(0);
assertTrue(coinbase.isCoinBase());
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/org/bitcoinj/utils/VersionTallyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package org.bitcoinj.utils;

import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.internal.TimeUtils;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void testVersionCounts() {

@Test
public void testInitialize() throws BlockStoreException {
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
Context.propagate(new Context(100, Coin.ZERO, false, true));
final BlockStore blockStore = new MemoryBlockStore(TESTNET.getGenesisBlock());
final BlockChain chain = new BlockChain(BitcoinNetwork.TESTNET, blockStore);

Expand Down
Loading
Loading