mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 07:12:17 +00:00
Remove TransactionConfidence.workDone. It doesn't seem useful and was somehow buggy.
This commit is contained in:
parent
9f8e09c5b4
commit
4834fe6eb6
@ -316,12 +316,6 @@ public class Transaction extends ChildMessage implements Serializable {
|
||||
|
||||
if (bestChain) {
|
||||
TransactionConfidence transactionConfidence = getConfidence();
|
||||
// Reset the work done.
|
||||
try {
|
||||
transactionConfidence.setWorkDone(block.getHeader().getWork());
|
||||
} catch (VerificationException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
}
|
||||
// This sets type to BUILDING and depth to one.
|
||||
transactionConfidence.setAppearedAtChainHeight(block.getHeight());
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ import static com.google.common.base.Preconditions.*;
|
||||
* <p>Alternatively, you may know that the transaction is "dead", that is, one or more of its inputs have
|
||||
* been double spent and will never confirm unless there is another re-org.</p>
|
||||
*
|
||||
* <p>TransactionConfidence is updated via the {@link com.google.bitcoin.core.TransactionConfidence#notifyWorkDone(Block)}
|
||||
* method to ensure the block depth and work done are up to date.</p>
|
||||
* <p>TransactionConfidence is updated via the {@link com.google.bitcoin.core.TransactionConfidence#incrementDepthInBlocks()}
|
||||
* method to ensure the block depth is up to date.</p>
|
||||
* To make a copy that won't be changed, use {@link com.google.bitcoin.core.TransactionConfidence#duplicate()}.
|
||||
*/
|
||||
public class TransactionConfidence implements Serializable {
|
||||
@ -75,8 +75,6 @@ public class TransactionConfidence implements Serializable {
|
||||
|
||||
// The depth of the transaction on the best chain in blocks. An unconfirmed block has depth 0.
|
||||
private int depth;
|
||||
// The cumulative work done for the blocks that bury this transaction.
|
||||
private BigInteger workDone = BigInteger.ZERO;
|
||||
|
||||
/** Describes the state of the transaction in general terms. Properties can be read to learn specifics. */
|
||||
public enum ConfidenceType {
|
||||
@ -255,7 +253,6 @@ public class TransactionConfidence implements Serializable {
|
||||
if (confidenceType == ConfidenceType.PENDING) {
|
||||
depth = 0;
|
||||
appearedAtChainHeight = -1;
|
||||
workDone = BigInteger.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,26 +316,19 @@ public class TransactionConfidence implements Serializable {
|
||||
builder.append("Pending/unconfirmed.");
|
||||
break;
|
||||
case BUILDING:
|
||||
builder.append(String.format("Appeared in best chain at height %d, depth %d, work done %s.",
|
||||
getAppearedAtChainHeight(), getDepthInBlocks(), getWorkDone()));
|
||||
builder.append(String.format("Appeared in best chain at height %d, depth %d.",
|
||||
getAppearedAtChainHeight(), getDepthInBlocks()));
|
||||
break;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the wallet when the tx appears on the best chain and a new block is added to the top.
|
||||
* Updates the internal counter that tracks how deeply buried the block is.
|
||||
* Work is the value of block.getWork().
|
||||
* Called by the wallet when the tx appears on the best chain and a new block is added to the top. Updates the
|
||||
* internal counter that tracks how deeply buried the block is.
|
||||
*/
|
||||
public synchronized boolean notifyWorkDone(Block block) throws VerificationException {
|
||||
if (getConfidenceType() != ConfidenceType.BUILDING)
|
||||
return false; // Should this be an assert?
|
||||
|
||||
public synchronized void incrementDepthInBlocks() {
|
||||
this.depth++;
|
||||
this.workDone = this.workDone.add(block.getWork());
|
||||
checkState(workDone.signum() >= 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,22 +352,6 @@ public class TransactionConfidence implements Serializable {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated amount of work (number of hashes performed) on this transaction. Work done is a measure of
|
||||
* security that is related to depth in blocks, but more predictable: the network will always attempt to produce six
|
||||
* blocks per hour by adjusting the difficulty target. So to know how much real computation effort is needed to
|
||||
* reverse a transaction, counting blocks is not enough. If a transaction has not confirmed, the result is zero.
|
||||
* @return estimated number of hashes needed to reverse the transaction.
|
||||
*/
|
||||
public synchronized BigInteger getWorkDone() {
|
||||
return workDone;
|
||||
}
|
||||
|
||||
public synchronized void setWorkDone(BigInteger workDone) {
|
||||
checkArgument(workDone.signum() >= 0);
|
||||
this.workDone = workDone;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this transaction has been overridden by a double spend (is dead), this call returns the overriding transaction.
|
||||
* Note that this call <b>can return null</b> if you have migrated an old wallet, as pre-Jan 2012 wallets did not
|
||||
|
@ -51,7 +51,6 @@ import org.spongycastle.crypto.params.KeyParameter;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -1657,7 +1656,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
|
||||
if (block != null) {
|
||||
// Mark the tx as appearing in this block so we can find it later after a re-org. This also tells the tx
|
||||
// confidence object about the block and sets its work done/depth appropriately.
|
||||
// confidence object about the block and sets its depth appropriately.
|
||||
tx.setBlockAppearance(block, bestChain, relativityOffset);
|
||||
if (bestChain) {
|
||||
// Don't notify this tx of work done in notifyNewBestBlock which will be called immediately after
|
||||
@ -1739,15 +1738,15 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds());
|
||||
// TODO: Clarify the code below.
|
||||
// Notify all the BUILDING transactions of the new block.
|
||||
// This is so that they can update their work done and depth.
|
||||
// This is so that they can update their depth.
|
||||
Set<Transaction> transactions = getTransactions(true);
|
||||
for (Transaction tx : transactions) {
|
||||
if (ignoreNextNewBlock.contains(tx.getHash())) {
|
||||
// tx was already processed in receive() due to it appearing in this block, so we don't want to
|
||||
// notify the tx confidence of work done twice, it'd result in miscounting.
|
||||
// increment the tx confidence depth twice, it'd result in miscounting.
|
||||
ignoreNextNewBlock.remove(tx.getHash());
|
||||
} else if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
|
||||
tx.getConfidence().notifyWorkDone(block.getHeader());
|
||||
tx.getConfidence().incrementDepthInBlocks();
|
||||
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
||||
}
|
||||
}
|
||||
@ -3583,19 +3582,15 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
// doesn't matter - the miners deleted T1 from their mempool, will resurrect T2 and put that into the
|
||||
// mempool and so T1 is still seen as a losing double spend.
|
||||
|
||||
// The old blocks have contributed to the depth and work done for all the transactions in the
|
||||
// The old blocks have contributed to the depth for all the transactions in the
|
||||
// wallet that are in blocks up to and including the chain split block.
|
||||
// The total depth and work done is calculated here and then subtracted from the appropriate transactions.
|
||||
// The total depth is calculated here and then subtracted from the appropriate transactions.
|
||||
int depthToSubtract = oldBlocks.size();
|
||||
BigInteger workDoneToSubtract = BigInteger.ZERO;
|
||||
for (StoredBlock b : oldBlocks) {
|
||||
workDoneToSubtract = workDoneToSubtract.add(b.getHeader().getWork());
|
||||
}
|
||||
log.info("depthToSubtract = " + depthToSubtract + ", workDoneToSubtract = " + workDoneToSubtract);
|
||||
// Remove depthToSubtract and workDoneToSubtract from all transactions in the wallet except for pending.
|
||||
subtractDepthAndWorkDone(depthToSubtract, workDoneToSubtract, spent.values());
|
||||
subtractDepthAndWorkDone(depthToSubtract, workDoneToSubtract, unspent.values());
|
||||
subtractDepthAndWorkDone(depthToSubtract, workDoneToSubtract, dead.values());
|
||||
log.info("depthToSubtract = " + depthToSubtract);
|
||||
// Remove depthToSubtract from all transactions in the wallet except for pending.
|
||||
subtractDepth(depthToSubtract, spent.values());
|
||||
subtractDepth(depthToSubtract, unspent.values());
|
||||
subtractDepth(depthToSubtract, dead.values());
|
||||
|
||||
// The effective last seen block is now the split point so set the lastSeenBlockHash.
|
||||
setLastBlockSeenHash(splitPoint.getHeader().getHash());
|
||||
@ -3633,14 +3628,12 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the supplied depth and work done from the given transactions.
|
||||
* Subtract the supplied depth from the given transactions.
|
||||
*/
|
||||
private void subtractDepthAndWorkDone(int depthToSubtract, BigInteger workDoneToSubtract,
|
||||
Collection<Transaction> transactions) {
|
||||
private void subtractDepth(int depthToSubtract, Collection<Transaction> transactions) {
|
||||
for (Transaction tx : transactions) {
|
||||
if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
|
||||
tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract);
|
||||
tx.getConfidence().setWorkDone(tx.getConfidence().getWorkDone().subtract(workDoneToSubtract));
|
||||
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
||||
}
|
||||
}
|
||||
|
@ -313,9 +313,6 @@ public class WalletProtobufSerializer {
|
||||
if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
|
||||
confidenceBuilder.setAppearedAtHeight(confidence.getAppearedAtChainHeight());
|
||||
confidenceBuilder.setDepth(confidence.getDepthInBlocks());
|
||||
if (confidence.getWorkDone() != null) {
|
||||
confidenceBuilder.setWorkDone(confidence.getWorkDone().longValue());
|
||||
}
|
||||
}
|
||||
if (confidence.getConfidenceType() == ConfidenceType.DEAD) {
|
||||
// Copy in the overriding transaction, if available.
|
||||
@ -667,13 +664,6 @@ public class WalletProtobufSerializer {
|
||||
}
|
||||
confidence.setDepthInBlocks(confidenceProto.getDepth());
|
||||
}
|
||||
if (confidenceProto.hasWorkDone()) {
|
||||
if (confidence.getConfidenceType() != ConfidenceType.BUILDING) {
|
||||
log.warn("Have workDone but not BUILDING for tx {}", tx.getHashAsString());
|
||||
return;
|
||||
}
|
||||
confidence.setWorkDone(BigInteger.valueOf(confidenceProto.getWorkDone()));
|
||||
}
|
||||
if (confidenceProto.hasOverridingTransaction()) {
|
||||
if (confidence.getConfidenceType() != ConfidenceType.DEAD) {
|
||||
log.warn("Have overridingTransaction but not OVERRIDDEN for tx {}", tx.getHashAsString());
|
||||
|
@ -6112,26 +6112,6 @@ public final class Protos {
|
||||
*/
|
||||
int getDepth();
|
||||
|
||||
// optional int64 work_done = 5;
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasWorkDone();
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
long getWorkDone();
|
||||
|
||||
// repeated .wallet.PeerAddress broadcast_by = 6;
|
||||
/**
|
||||
* <code>repeated .wallet.PeerAddress broadcast_by = 6;</code>
|
||||
@ -6252,15 +6232,10 @@ public final class Protos {
|
||||
depth_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 40: {
|
||||
bitField0_ |= 0x00000010;
|
||||
workDone_ = input.readInt64();
|
||||
break;
|
||||
}
|
||||
case 50: {
|
||||
if (!((mutable_bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
broadcastBy_ = new java.util.ArrayList<org.bitcoinj.wallet.Protos.PeerAddress>();
|
||||
mutable_bitField0_ |= 0x00000020;
|
||||
mutable_bitField0_ |= 0x00000010;
|
||||
}
|
||||
broadcastBy_.add(input.readMessage(org.bitcoinj.wallet.Protos.PeerAddress.PARSER, extensionRegistry));
|
||||
break;
|
||||
@ -6271,7 +6246,7 @@ public final class Protos {
|
||||
if (value == null) {
|
||||
unknownFields.mergeVarintField(7, rawValue);
|
||||
} else {
|
||||
bitField0_ |= 0x00000020;
|
||||
bitField0_ |= 0x00000010;
|
||||
source_ = value;
|
||||
}
|
||||
break;
|
||||
@ -6284,7 +6259,7 @@ public final class Protos {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
broadcastBy_ = java.util.Collections.unmodifiableList(broadcastBy_);
|
||||
}
|
||||
this.unknownFields = unknownFields.build();
|
||||
@ -6681,32 +6656,6 @@ public final class Protos {
|
||||
return depth_;
|
||||
}
|
||||
|
||||
// optional int64 work_done = 5;
|
||||
public static final int WORK_DONE_FIELD_NUMBER = 5;
|
||||
private long workDone_;
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasWorkDone() {
|
||||
return ((bitField0_ & 0x00000010) == 0x00000010);
|
||||
}
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public long getWorkDone() {
|
||||
return workDone_;
|
||||
}
|
||||
|
||||
// repeated .wallet.PeerAddress broadcast_by = 6;
|
||||
public static final int BROADCAST_BY_FIELD_NUMBER = 6;
|
||||
private java.util.List<org.bitcoinj.wallet.Protos.PeerAddress> broadcastBy_;
|
||||
@ -6750,7 +6699,7 @@ public final class Protos {
|
||||
* <code>optional .wallet.TransactionConfidence.Source source = 7;</code>
|
||||
*/
|
||||
public boolean hasSource() {
|
||||
return ((bitField0_ & 0x00000020) == 0x00000020);
|
||||
return ((bitField0_ & 0x00000010) == 0x00000010);
|
||||
}
|
||||
/**
|
||||
* <code>optional .wallet.TransactionConfidence.Source source = 7;</code>
|
||||
@ -6764,7 +6713,6 @@ public final class Protos {
|
||||
appearedAtHeight_ = 0;
|
||||
overridingTransaction_ = com.google.protobuf.ByteString.EMPTY;
|
||||
depth_ = 0;
|
||||
workDone_ = 0L;
|
||||
broadcastBy_ = java.util.Collections.emptyList();
|
||||
source_ = org.bitcoinj.wallet.Protos.TransactionConfidence.Source.SOURCE_UNKNOWN;
|
||||
}
|
||||
@ -6798,13 +6746,10 @@ public final class Protos {
|
||||
if (((bitField0_ & 0x00000008) == 0x00000008)) {
|
||||
output.writeInt32(4, depth_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
output.writeInt64(5, workDone_);
|
||||
}
|
||||
for (int i = 0; i < broadcastBy_.size(); i++) {
|
||||
output.writeMessage(6, broadcastBy_.get(i));
|
||||
}
|
||||
if (((bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
output.writeEnum(7, source_.getNumber());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
@ -6832,15 +6777,11 @@ public final class Protos {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeInt32Size(4, depth_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeInt64Size(5, workDone_);
|
||||
}
|
||||
for (int i = 0; i < broadcastBy_.size(); i++) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(6, broadcastBy_.get(i));
|
||||
}
|
||||
if (((bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeEnumSize(7, source_.getNumber());
|
||||
}
|
||||
@ -6977,16 +6918,14 @@ public final class Protos {
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
depth_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000008);
|
||||
workDone_ = 0L;
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
if (broadcastByBuilder_ == null) {
|
||||
broadcastBy_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
} else {
|
||||
broadcastByBuilder_.clear();
|
||||
}
|
||||
source_ = org.bitcoinj.wallet.Protos.TransactionConfidence.Source.SOURCE_UNKNOWN;
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -7031,21 +6970,17 @@ public final class Protos {
|
||||
to_bitField0_ |= 0x00000008;
|
||||
}
|
||||
result.depth_ = depth_;
|
||||
if (((from_bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
to_bitField0_ |= 0x00000010;
|
||||
}
|
||||
result.workDone_ = workDone_;
|
||||
if (broadcastByBuilder_ == null) {
|
||||
if (((bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
broadcastBy_ = java.util.Collections.unmodifiableList(broadcastBy_);
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
}
|
||||
result.broadcastBy_ = broadcastBy_;
|
||||
} else {
|
||||
result.broadcastBy_ = broadcastByBuilder_.build();
|
||||
}
|
||||
if (((from_bitField0_ & 0x00000040) == 0x00000040)) {
|
||||
to_bitField0_ |= 0x00000020;
|
||||
if (((from_bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
to_bitField0_ |= 0x00000010;
|
||||
}
|
||||
result.source_ = source_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
@ -7076,14 +7011,11 @@ public final class Protos {
|
||||
if (other.hasDepth()) {
|
||||
setDepth(other.getDepth());
|
||||
}
|
||||
if (other.hasWorkDone()) {
|
||||
setWorkDone(other.getWorkDone());
|
||||
}
|
||||
if (broadcastByBuilder_ == null) {
|
||||
if (!other.broadcastBy_.isEmpty()) {
|
||||
if (broadcastBy_.isEmpty()) {
|
||||
broadcastBy_ = other.broadcastBy_;
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
} else {
|
||||
ensureBroadcastByIsMutable();
|
||||
broadcastBy_.addAll(other.broadcastBy_);
|
||||
@ -7096,7 +7028,7 @@ public final class Protos {
|
||||
broadcastByBuilder_.dispose();
|
||||
broadcastByBuilder_ = null;
|
||||
broadcastBy_ = other.broadcastBy_;
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
broadcastByBuilder_ =
|
||||
com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
|
||||
getBroadcastByFieldBuilder() : null;
|
||||
@ -7355,66 +7287,13 @@ public final class Protos {
|
||||
return this;
|
||||
}
|
||||
|
||||
// optional int64 work_done = 5;
|
||||
private long workDone_ ;
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasWorkDone() {
|
||||
return ((bitField0_ & 0x00000010) == 0x00000010);
|
||||
}
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public long getWorkDone() {
|
||||
return workDone_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setWorkDone(long value) {
|
||||
bitField0_ |= 0x00000010;
|
||||
workDone_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int64 work_done = 5;</code>
|
||||
*
|
||||
* <pre>
|
||||
* If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
* all blocks that bury it.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearWorkDone() {
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
workDone_ = 0L;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// repeated .wallet.PeerAddress broadcast_by = 6;
|
||||
private java.util.List<org.bitcoinj.wallet.Protos.PeerAddress> broadcastBy_ =
|
||||
java.util.Collections.emptyList();
|
||||
private void ensureBroadcastByIsMutable() {
|
||||
if (!((bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
if (!((bitField0_ & 0x00000010) == 0x00000010)) {
|
||||
broadcastBy_ = new java.util.ArrayList<org.bitcoinj.wallet.Protos.PeerAddress>(broadcastBy_);
|
||||
bitField0_ |= 0x00000020;
|
||||
bitField0_ |= 0x00000010;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7563,7 +7442,7 @@ public final class Protos {
|
||||
public Builder clearBroadcastBy() {
|
||||
if (broadcastByBuilder_ == null) {
|
||||
broadcastBy_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
onChanged();
|
||||
} else {
|
||||
broadcastByBuilder_.clear();
|
||||
@ -7640,7 +7519,7 @@ public final class Protos {
|
||||
broadcastByBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
|
||||
org.bitcoinj.wallet.Protos.PeerAddress, org.bitcoinj.wallet.Protos.PeerAddress.Builder, org.bitcoinj.wallet.Protos.PeerAddressOrBuilder>(
|
||||
broadcastBy_,
|
||||
((bitField0_ & 0x00000020) == 0x00000020),
|
||||
((bitField0_ & 0x00000010) == 0x00000010),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
broadcastBy_ = null;
|
||||
@ -7654,7 +7533,7 @@ public final class Protos {
|
||||
* <code>optional .wallet.TransactionConfidence.Source source = 7;</code>
|
||||
*/
|
||||
public boolean hasSource() {
|
||||
return ((bitField0_ & 0x00000040) == 0x00000040);
|
||||
return ((bitField0_ & 0x00000020) == 0x00000020);
|
||||
}
|
||||
/**
|
||||
* <code>optional .wallet.TransactionConfidence.Source source = 7;</code>
|
||||
@ -7669,7 +7548,7 @@ public final class Protos {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000040;
|
||||
bitField0_ |= 0x00000020;
|
||||
source_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
@ -7678,7 +7557,7 @@ public final class Protos {
|
||||
* <code>optional .wallet.TransactionConfidence.Source source = 7;</code>
|
||||
*/
|
||||
public Builder clearSource() {
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
source_ = org.bitcoinj.wallet.Protos.TransactionConfidence.Source.SOURCE_UNKNOWN;
|
||||
onChanged();
|
||||
return this;
|
||||
@ -17364,55 +17243,55 @@ public final class Protos {
|
||||
" \001(\r\022\r\n\005value\030\005 \001(\003\"\177\n\021TransactionOutput" +
|
||||
"\022\r\n\005value\030\001 \002(\003\022\024\n\014script_bytes\030\002 \002(\014\022!\n" +
|
||||
"\031spent_by_transaction_hash\030\003 \001(\014\022\"\n\032spen" +
|
||||
"t_by_transaction_index\030\004 \001(\005\"\234\003\n\025Transac" +
|
||||
"t_by_transaction_index\030\004 \001(\005\"\211\003\n\025Transac" +
|
||||
"tionConfidence\0220\n\004type\030\001 \001(\0162\".wallet.Tr" +
|
||||
"ansactionConfidence.Type\022\032\n\022appeared_at_" +
|
||||
"height\030\002 \001(\005\022\036\n\026overriding_transaction\030\003" +
|
||||
" \001(\014\022\r\n\005depth\030\004 \001(\005\022\021\n\twork_done\030\005 \001(\003\022)" +
|
||||
"\n\014broadcast_by\030\006 \003(\0132\023.wallet.PeerAddres" +
|
||||
"s\0224\n\006source\030\007 \001(\0162$.wallet.TransactionCo",
|
||||
"nfidence.Source\"O\n\004Type\022\013\n\007UNKNOWN\020\000\022\014\n\010" +
|
||||
"BUILDING\020\001\022\013\n\007PENDING\020\002\022\025\n\021NOT_IN_BEST_C" +
|
||||
"HAIN\020\003\022\010\n\004DEAD\020\004\"A\n\006Source\022\022\n\016SOURCE_UNK" +
|
||||
"NOWN\020\000\022\022\n\016SOURCE_NETWORK\020\001\022\017\n\013SOURCE_SEL" +
|
||||
"F\020\002\"\371\004\n\013Transaction\022\017\n\007version\030\001 \002(\005\022\014\n\004" +
|
||||
"hash\030\002 \002(\014\022&\n\004pool\030\003 \001(\0162\030.wallet.Transa" +
|
||||
"ction.Pool\022\021\n\tlock_time\030\004 \001(\r\022\022\n\nupdated" +
|
||||
"_at\030\005 \001(\003\0223\n\021transaction_input\030\006 \003(\0132\030.w" +
|
||||
"allet.TransactionInput\0225\n\022transaction_ou" +
|
||||
"tput\030\007 \003(\0132\031.wallet.TransactionOutput\022\022\n",
|
||||
"\nblock_hash\030\010 \003(\014\022 \n\030block_relativity_of" +
|
||||
"fsets\030\013 \003(\005\0221\n\nconfidence\030\t \001(\0132\035.wallet" +
|
||||
".TransactionConfidence\0225\n\007purpose\030\n \001(\0162" +
|
||||
"\033.wallet.Transaction.Purpose:\007UNKNOWN\"Y\n" +
|
||||
"\004Pool\022\013\n\007UNSPENT\020\004\022\t\n\005SPENT\020\005\022\014\n\010INACTIV" +
|
||||
"E\020\002\022\010\n\004DEAD\020\n\022\013\n\007PENDING\020\020\022\024\n\020PENDING_IN" +
|
||||
"ACTIVE\020\022\"\224\001\n\007Purpose\022\013\n\007UNKNOWN\020\000\022\020\n\014USE" +
|
||||
"R_PAYMENT\020\001\022\020\n\014KEY_ROTATION\020\002\022\034\n\030ASSURAN" +
|
||||
"CE_CONTRACT_CLAIM\020\003\022\035\n\031ASSURANCE_CONTRAC" +
|
||||
"T_PLEDGE\020\004\022\033\n\027ASSURANCE_CONTRACT_STUB\020\005\"",
|
||||
"N\n\020ScryptParameters\022\014\n\004salt\030\001 \002(\014\022\020\n\001n\030\002" +
|
||||
" \001(\003:\00516384\022\014\n\001r\030\003 \001(\005:\0018\022\014\n\001p\030\004 \001(\005:\0011\"" +
|
||||
"8\n\tExtension\022\n\n\002id\030\001 \002(\t\022\014\n\004data\030\002 \002(\014\022\021" +
|
||||
"\n\tmandatory\030\003 \002(\010\" \n\003Tag\022\013\n\003tag\030\001 \002(\t\022\014\n" +
|
||||
"\004data\030\002 \002(\014\"5\n\021TransactionSigner\022\022\n\nclas" +
|
||||
"s_name\030\001 \002(\t\022\014\n\004data\030\002 \001(\014\"\351\004\n\006Wallet\022\032\n" +
|
||||
"\022network_identifier\030\001 \002(\t\022\034\n\024last_seen_b" +
|
||||
"lock_hash\030\002 \001(\014\022\036\n\026last_seen_block_heigh" +
|
||||
"t\030\014 \001(\r\022!\n\031last_seen_block_time_secs\030\016 \001" +
|
||||
"(\003\022\030\n\003key\030\003 \003(\0132\013.wallet.Key\022(\n\013transact",
|
||||
"ion\030\004 \003(\0132\023.wallet.Transaction\022&\n\016watche" +
|
||||
"d_script\030\017 \003(\0132\016.wallet.Script\022C\n\017encryp" +
|
||||
"tion_type\030\005 \001(\0162\035.wallet.Wallet.Encrypti" +
|
||||
"onType:\013UNENCRYPTED\0227\n\025encryption_parame" +
|
||||
"ters\030\006 \001(\0132\030.wallet.ScryptParameters\022\022\n\007" +
|
||||
"version\030\007 \001(\005:\0011\022$\n\textension\030\n \003(\0132\021.wa" +
|
||||
"llet.Extension\022\023\n\013description\030\013 \001(\t\022\031\n\021k" +
|
||||
"ey_rotation_time\030\r \001(\004\022\031\n\004tags\030\020 \003(\0132\013.w" +
|
||||
"allet.Tag\0226\n\023transaction_signers\030\021 \003(\0132\031" +
|
||||
".wallet.TransactionSigner\";\n\016EncryptionT",
|
||||
"ype\022\017\n\013UNENCRYPTED\020\001\022\030\n\024ENCRYPTED_SCRYPT" +
|
||||
"_AES\020\002B\035\n\023org.bitcoinj.walletB\006Protos"
|
||||
" \001(\014\022\r\n\005depth\030\004 \001(\005\022)\n\014broadcast_by\030\006 \003(" +
|
||||
"\0132\023.wallet.PeerAddress\0224\n\006source\030\007 \001(\0162$" +
|
||||
".wallet.TransactionConfidence.Source\"O\n\004",
|
||||
"Type\022\013\n\007UNKNOWN\020\000\022\014\n\010BUILDING\020\001\022\013\n\007PENDI" +
|
||||
"NG\020\002\022\025\n\021NOT_IN_BEST_CHAIN\020\003\022\010\n\004DEAD\020\004\"A\n" +
|
||||
"\006Source\022\022\n\016SOURCE_UNKNOWN\020\000\022\022\n\016SOURCE_NE" +
|
||||
"TWORK\020\001\022\017\n\013SOURCE_SELF\020\002\"\371\004\n\013Transaction" +
|
||||
"\022\017\n\007version\030\001 \002(\005\022\014\n\004hash\030\002 \002(\014\022&\n\004pool\030" +
|
||||
"\003 \001(\0162\030.wallet.Transaction.Pool\022\021\n\tlock_" +
|
||||
"time\030\004 \001(\r\022\022\n\nupdated_at\030\005 \001(\003\0223\n\021transa" +
|
||||
"ction_input\030\006 \003(\0132\030.wallet.TransactionIn" +
|
||||
"put\0225\n\022transaction_output\030\007 \003(\0132\031.wallet" +
|
||||
".TransactionOutput\022\022\n\nblock_hash\030\010 \003(\014\022 ",
|
||||
"\n\030block_relativity_offsets\030\013 \003(\005\0221\n\nconf" +
|
||||
"idence\030\t \001(\0132\035.wallet.TransactionConfide" +
|
||||
"nce\0225\n\007purpose\030\n \001(\0162\033.wallet.Transactio" +
|
||||
"n.Purpose:\007UNKNOWN\"Y\n\004Pool\022\013\n\007UNSPENT\020\004\022" +
|
||||
"\t\n\005SPENT\020\005\022\014\n\010INACTIVE\020\002\022\010\n\004DEAD\020\n\022\013\n\007PE" +
|
||||
"NDING\020\020\022\024\n\020PENDING_INACTIVE\020\022\"\224\001\n\007Purpos" +
|
||||
"e\022\013\n\007UNKNOWN\020\000\022\020\n\014USER_PAYMENT\020\001\022\020\n\014KEY_" +
|
||||
"ROTATION\020\002\022\034\n\030ASSURANCE_CONTRACT_CLAIM\020\003" +
|
||||
"\022\035\n\031ASSURANCE_CONTRACT_PLEDGE\020\004\022\033\n\027ASSUR" +
|
||||
"ANCE_CONTRACT_STUB\020\005\"N\n\020ScryptParameters",
|
||||
"\022\014\n\004salt\030\001 \002(\014\022\020\n\001n\030\002 \001(\003:\00516384\022\014\n\001r\030\003 " +
|
||||
"\001(\005:\0018\022\014\n\001p\030\004 \001(\005:\0011\"8\n\tExtension\022\n\n\002id\030" +
|
||||
"\001 \002(\t\022\014\n\004data\030\002 \002(\014\022\021\n\tmandatory\030\003 \002(\010\" " +
|
||||
"\n\003Tag\022\013\n\003tag\030\001 \002(\t\022\014\n\004data\030\002 \002(\014\"5\n\021Tran" +
|
||||
"sactionSigner\022\022\n\nclass_name\030\001 \002(\t\022\014\n\004dat" +
|
||||
"a\030\002 \001(\014\"\351\004\n\006Wallet\022\032\n\022network_identifier" +
|
||||
"\030\001 \002(\t\022\034\n\024last_seen_block_hash\030\002 \001(\014\022\036\n\026" +
|
||||
"last_seen_block_height\030\014 \001(\r\022!\n\031last_see" +
|
||||
"n_block_time_secs\030\016 \001(\003\022\030\n\003key\030\003 \003(\0132\013.w" +
|
||||
"allet.Key\022(\n\013transaction\030\004 \003(\0132\023.wallet.",
|
||||
"Transaction\022&\n\016watched_script\030\017 \003(\0132\016.wa" +
|
||||
"llet.Script\022C\n\017encryption_type\030\005 \001(\0162\035.w" +
|
||||
"allet.Wallet.EncryptionType:\013UNENCRYPTED" +
|
||||
"\0227\n\025encryption_parameters\030\006 \001(\0132\030.wallet" +
|
||||
".ScryptParameters\022\022\n\007version\030\007 \001(\005:\0011\022$\n" +
|
||||
"\textension\030\n \003(\0132\021.wallet.Extension\022\023\n\013d" +
|
||||
"escription\030\013 \001(\t\022\031\n\021key_rotation_time\030\r " +
|
||||
"\001(\004\022\031\n\004tags\030\020 \003(\0132\013.wallet.Tag\0226\n\023transa" +
|
||||
"ction_signers\030\021 \003(\0132\031.wallet.Transaction" +
|
||||
"Signer\";\n\016EncryptionType\022\017\n\013UNENCRYPTED\020",
|
||||
"\001\022\030\n\024ENCRYPTED_SCRYPT_AES\020\002B\035\n\023org.bitco" +
|
||||
"inj.walletB\006Protos"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
@ -17466,7 +17345,7 @@ public final class Protos {
|
||||
internal_static_wallet_TransactionConfidence_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_wallet_TransactionConfidence_descriptor,
|
||||
new java.lang.String[] { "Type", "AppearedAtHeight", "OverridingTransaction", "Depth", "WorkDone", "BroadcastBy", "Source", });
|
||||
new java.lang.String[] { "Type", "AppearedAtHeight", "OverridingTransaction", "Depth", "BroadcastBy", "Source", });
|
||||
internal_static_wallet_Transaction_descriptor =
|
||||
getDescriptor().getMessageTypes().get(8);
|
||||
internal_static_wallet_Transaction_fieldAccessorTable = new
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -429,10 +430,6 @@ public class ChainSplitTest {
|
||||
assertEquals(2, txns.get(1).getConfidence().getDepthInBlocks());
|
||||
assertEquals(1, txns.get(2).getConfidence().getDepthInBlocks());
|
||||
|
||||
assertEquals(work1.add(work2).add(work3), txns.get(0).getConfidence().getWorkDone());
|
||||
assertEquals(work2.add(work3), txns.get(1).getConfidence().getWorkDone());
|
||||
assertEquals(work3, txns.get(2).getConfidence().getWorkDone());
|
||||
|
||||
// We now have the following chain:
|
||||
// genesis -> b1 -> b2 -> b3
|
||||
//
|
||||
@ -461,10 +458,6 @@ public class ChainSplitTest {
|
||||
assertEquals(2, txns.get(1).getConfidence().getDepthInBlocks());
|
||||
assertEquals(1, txns.get(2).getConfidence().getDepthInBlocks());
|
||||
|
||||
assertEquals(work1.add(work2).add(work3), txns.get(0).getConfidence().getWorkDone());
|
||||
assertEquals(work2.add(work3), txns.get(1).getConfidence().getWorkDone());
|
||||
assertEquals(work3, txns.get(2).getConfidence().getWorkDone());
|
||||
|
||||
// Now we add another block to make the alternative chain longer.
|
||||
Block b6 = b5.createNextBlock(someOtherGuy);
|
||||
BigInteger work6 = b6.getWork();
|
||||
@ -477,7 +470,6 @@ public class ChainSplitTest {
|
||||
assertEquals(3, txns.size());
|
||||
assertEquals(1, txns.get(0).getConfidence().getAppearedAtChainHeight());
|
||||
assertEquals(4, txns.get(0).getConfidence().getDepthInBlocks());
|
||||
assertEquals(work1.add(work4).add(work5).add(work6), txns.get(0).getConfidence().getWorkDone());
|
||||
|
||||
// Transaction 1 (in block b2) is now on a side chain, so it goes pending (not see in chain).
|
||||
assertEquals(ConfidenceType.PENDING, txns.get(1).getConfidence().getConfidenceType());
|
||||
@ -486,7 +478,6 @@ public class ChainSplitTest {
|
||||
fail();
|
||||
} catch (IllegalStateException e) {}
|
||||
assertEquals(0, txns.get(1).getConfidence().getDepthInBlocks());
|
||||
assertEquals(BigInteger.ZERO, txns.get(1).getConfidence().getWorkDone());
|
||||
|
||||
// ... and back to the first chain.
|
||||
Block b7 = b3.createNextBlock(coinsTo);
|
||||
@ -513,13 +504,6 @@ public class ChainSplitTest {
|
||||
assertEquals(4, txns.get(1).getConfidence().getDepthInBlocks());
|
||||
assertEquals(3, txns.get(2).getConfidence().getDepthInBlocks());
|
||||
|
||||
BigInteger newWork1 = work1.add(work2).add(work3).add(work7).add(work8);
|
||||
assertEquals(newWork1, txns.get(0).getConfidence().getWorkDone());
|
||||
BigInteger newWork2 = work2.add(work3).add(work7).add(work8);
|
||||
assertEquals(newWork2, txns.get(1).getConfidence().getWorkDone());
|
||||
BigInteger newWork3 = work3.add(work7).add(work8);
|
||||
assertEquals(newWork3, txns.get(2).getConfidence().getWorkDone());
|
||||
|
||||
assertEquals(Coin.valueOf(250, 0), wallet.getBalance());
|
||||
|
||||
// Now add two more blocks that don't send coins to us. Despite being irrelevant the wallet should still update.
|
||||
@ -531,9 +515,6 @@ public class ChainSplitTest {
|
||||
assertEquals(7, txns.get(0).getConfidence().getDepthInBlocks());
|
||||
assertEquals(6, txns.get(1).getConfidence().getDepthInBlocks());
|
||||
assertEquals(5, txns.get(2).getConfidence().getDepthInBlocks());
|
||||
assertEquals(newWork1.add(extraWork), txns.get(0).getConfidence().getWorkDone());
|
||||
assertEquals(newWork2.add(extraWork), txns.get(1).getConfidence().getWorkDone());
|
||||
assertEquals(newWork3.add(extraWork), txns.get(2).getConfidence().getWorkDone());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -226,9 +226,6 @@ public class WalletProtobufSerializerTest {
|
||||
assertEquals(2, confidence0.getDepthInBlocks());
|
||||
assertEquals(1, confidence1.getDepthInBlocks());
|
||||
|
||||
assertEquals(work1.add(work2), confidence0.getWorkDone());
|
||||
assertEquals(work2, confidence1.getWorkDone());
|
||||
|
||||
// Roundtrip the wallet and check it has stored the depth and workDone.
|
||||
Wallet rebornWallet = roundTrip(myWallet);
|
||||
|
||||
@ -257,9 +254,6 @@ public class WalletProtobufSerializerTest {
|
||||
|
||||
assertEquals(2, rebornConfidence0.getDepthInBlocks());
|
||||
assertEquals(1, rebornConfidence1.getDepthInBlocks());
|
||||
|
||||
assertEquals(work1.add(work2), rebornConfidence0.getWorkDone());
|
||||
assertEquals(work2, rebornConfidence1.getWorkDone());
|
||||
}
|
||||
|
||||
private static Wallet roundTrip(Wallet wallet) throws Exception {
|
||||
|
@ -182,9 +182,8 @@ message TransactionConfidence {
|
||||
// Zero confirmations: depth = 0, one confirmation: depth = 1 etc.
|
||||
optional int32 depth = 4;
|
||||
|
||||
// If type == BUILDING then this is the cumulative workDone for the block the transaction appears in, together with
|
||||
// all blocks that bury it.
|
||||
optional int64 work_done = 5;
|
||||
// deprecated - do not recycle this numeric identifier
|
||||
// optional int64 work_done = 5;
|
||||
|
||||
repeated PeerAddress broadcast_by = 6;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user