mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 11:45:51 +00:00
Add hooks to override protocol version numbers
This commit is contained in:
parent
377d226ef1
commit
ad42302355
@ -27,8 +27,6 @@ import java.util.*;
|
|||||||
* of the block header and a {@link PartialMerkleTree} which contains the transactions which matched the filter.</p>
|
* of the block header and a {@link PartialMerkleTree} which contains the transactions which matched the filter.</p>
|
||||||
*/
|
*/
|
||||||
public class FilteredBlock extends Message {
|
public class FilteredBlock extends Message {
|
||||||
/** The protocol version at which Bloom filtering started to be supported. */
|
|
||||||
public static final int MIN_PROTOCOL_VERSION = 70000;
|
|
||||||
private Block header;
|
private Block header;
|
||||||
|
|
||||||
private PartialMerkleTree merkleTree;
|
private PartialMerkleTree merkleTree;
|
||||||
|
@ -74,7 +74,7 @@ public class GetBlocksMessage extends Message {
|
|||||||
@Override
|
@Override
|
||||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||||
// Version, for some reason.
|
// Version, for some reason.
|
||||||
Utils.uint32ToByteStreamLE(NetworkParameters.PROTOCOL_VERSION, stream);
|
Utils.uint32ToByteStreamLE(params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT), stream);
|
||||||
// Then a vector of block hashes. This is actually a "block locator", a set of block
|
// Then a vector of block hashes. This is actually a "block locator", a set of block
|
||||||
// identifiers that spans the entire chain with exponentially increasing gaps between
|
// identifiers that spans the entire chain with exponentially increasing gaps between
|
||||||
// them, until we end up at the genesis block. See CBlockLocator::Set()
|
// them, until we end up at the genesis block. See CBlockLocator::Set()
|
||||||
|
@ -118,11 +118,13 @@ public abstract class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Message(NetworkParameters params, byte[] payload, int offset) throws ProtocolException {
|
Message(NetworkParameters params, byte[] payload, int offset) throws ProtocolException {
|
||||||
this(params, payload, offset, NetworkParameters.PROTOCOL_VERSION, params.getDefaultSerializer(), UNKNOWN_LENGTH);
|
this(params, payload, offset, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT),
|
||||||
|
params.getDefaultSerializer(), UNKNOWN_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
Message(NetworkParameters params, byte[] payload, int offset, MessageSerializer serializer, int length) throws ProtocolException {
|
Message(NetworkParameters params, byte[] payload, int offset, MessageSerializer serializer, int length) throws ProtocolException {
|
||||||
this(params, payload, offset, NetworkParameters.PROTOCOL_VERSION, serializer, length);
|
this(params, payload, offset, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT),
|
||||||
|
serializer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// These methods handle the serialization/deserialization using the custom Bitcoin protocol.
|
// These methods handle the serialization/deserialization using the custom Bitcoin protocol.
|
||||||
|
@ -46,11 +46,6 @@ import org.bitcoinj.utils.VersionTally;
|
|||||||
* them, you are encouraged to call the static get() methods on each specific params class directly.</p>
|
* them, you are encouraged to call the static get() methods on each specific params class directly.</p>
|
||||||
*/
|
*/
|
||||||
public abstract class NetworkParameters {
|
public abstract class NetworkParameters {
|
||||||
/**
|
|
||||||
* The protocol version this library implements.
|
|
||||||
*/
|
|
||||||
public static final int PROTOCOL_VERSION = 70001;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others.
|
* The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others.
|
||||||
*/
|
*/
|
||||||
@ -517,4 +512,23 @@ public abstract class NetworkParameters {
|
|||||||
verifyFlags.add(Script.VerifyFlag.P2SH);
|
verifyFlags.add(Script.VerifyFlag.P2SH);
|
||||||
return verifyFlags;
|
return verifyFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract int getProtocolVersionNum(final ProtocolVersion version);
|
||||||
|
|
||||||
|
public static enum ProtocolVersion {
|
||||||
|
MINIMUM(70000),
|
||||||
|
PONG(60001),
|
||||||
|
BLOOM_FILTER(70000),
|
||||||
|
CURRENT(70001);
|
||||||
|
|
||||||
|
private final int bitcoinProtocol;
|
||||||
|
|
||||||
|
ProtocolVersion(final int bitcoinProtocol) {
|
||||||
|
this.bitcoinProtocol = bitcoinProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBitcoinProtocolVersion() {
|
||||||
|
return bitcoinProtocol;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||||
private final HashSet<TransactionConfidence> pendingTxDownloads = new HashSet<TransactionConfidence>();
|
private final HashSet<TransactionConfidence> pendingTxDownloads = new HashSet<TransactionConfidence>();
|
||||||
// The lowest version number we're willing to accept. Lower than this will result in an immediate disconnect.
|
// The lowest version number we're willing to accept. Lower than this will result in an immediate disconnect.
|
||||||
private volatile int vMinProtocolVersion = Pong.MIN_PROTOCOL_VERSION;
|
private volatile int vMinProtocolVersion;
|
||||||
// When an API user explicitly requests a block or transaction from a peer, the InventoryItem is put here
|
// When an API user explicitly requests a block or transaction from a peer, the InventoryItem is put here
|
||||||
// whilst waiting for the response. Is not used for downloads Peer generates itself.
|
// whilst waiting for the response. Is not used for downloads Peer generates itself.
|
||||||
private static class GetDataRequest {
|
private static class GetDataRequest {
|
||||||
@ -223,6 +223,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
||||||
this.isAcked = false;
|
this.isAcked = false;
|
||||||
this.pendingPings = new CopyOnWriteArrayList<PendingPing>();
|
this.pendingPings = new CopyOnWriteArrayList<PendingPing>();
|
||||||
|
this.vMinProtocolVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.PONG);
|
||||||
this.wallets = new CopyOnWriteArrayList<Wallet>();
|
this.wallets = new CopyOnWriteArrayList<Wallet>();
|
||||||
this.context = Context.get();
|
this.context = Context.get();
|
||||||
}
|
}
|
||||||
|
@ -78,39 +78,78 @@ public class PeerAddress extends ChildMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a peer address from the given IP address and port. Protocol version is the default.
|
* Constructs a peer address from the given IP address and port. Protocol version is the default
|
||||||
|
* for Bitcoin.
|
||||||
*/
|
*/
|
||||||
public PeerAddress(InetAddress addr, int port) {
|
public PeerAddress(InetAddress addr, int port) {
|
||||||
this(addr, port, NetworkParameters.PROTOCOL_VERSION);
|
this(addr, port, NetworkParameters.ProtocolVersion.CURRENT.getBitcoinProtocolVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a peer address from the given IP address. Port and protocol version are default for the mainnet.
|
* Constructs a peer address from the given IP address and port.
|
||||||
|
*/
|
||||||
|
public PeerAddress(NetworkParameters params, InetAddress addr, int port) {
|
||||||
|
this(addr, port, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a peer address from the given IP address. Port and version number
|
||||||
|
* are default for Bitcoin mainnet.
|
||||||
*/
|
*/
|
||||||
public PeerAddress(InetAddress addr) {
|
public PeerAddress(InetAddress addr) {
|
||||||
this(addr, MainNetParams.get().getPort());
|
this(addr, MainNetParams.get().getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a peer address from the given IP address. Port is default for
|
||||||
|
* Bitcoin mainnet, version number is default for the given parameters.
|
||||||
|
*/
|
||||||
|
public PeerAddress(NetworkParameters params, InetAddress addr) {
|
||||||
|
this(params, addr, MainNetParams.get().getPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a peer address from an {@link InetSocketAddress}. An InetSocketAddress can take in as parameters an
|
||||||
|
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
|
||||||
|
* Protocol version is the default. Protocol version is the default
|
||||||
|
* for Bitcoin.
|
||||||
|
*/
|
||||||
|
public PeerAddress(InetSocketAddress addr) {
|
||||||
|
this(addr.getAddress(), addr.getPort(), NetworkParameters.ProtocolVersion.CURRENT.getBitcoinProtocolVersion());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a peer address from an {@link InetSocketAddress}. An InetSocketAddress can take in as parameters an
|
* Constructs a peer address from an {@link InetSocketAddress}. An InetSocketAddress can take in as parameters an
|
||||||
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
|
* InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
|
||||||
*/
|
*/
|
||||||
public PeerAddress(InetSocketAddress addr) {
|
public PeerAddress(NetworkParameters params, InetSocketAddress addr) {
|
||||||
this(addr.getAddress(), addr.getPort());
|
this(params, addr.getAddress(), addr.getPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
|
||||||
|
* Protocol version is the default for Bitcoin.
|
||||||
|
*/
|
||||||
|
public PeerAddress(String hostname, int port) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.port = port;
|
||||||
|
this.protocolVersion = NetworkParameters.ProtocolVersion.CURRENT.getBitcoinProtocolVersion();
|
||||||
|
this.services = BigInteger.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
|
* Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
|
||||||
*/
|
*/
|
||||||
public PeerAddress(String hostname, int port) {
|
public PeerAddress(NetworkParameters params, String hostname, int port) {
|
||||||
|
super(params);
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.protocolVersion = NetworkParameters.PROTOCOL_VERSION;
|
this.protocolVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
|
||||||
this.services = BigInteger.ZERO;
|
this.services = BigInteger.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PeerAddress localhost(NetworkParameters params) {
|
public static PeerAddress localhost(NetworkParameters params) {
|
||||||
return new PeerAddress(InetAddresses.forString("127.0.0.1"), params.getPort());
|
return new PeerAddress(params, InetAddresses.forString("127.0.0.1"), params.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,7 +130,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
// until we reach this count.
|
// until we reach this count.
|
||||||
@GuardedBy("lock") private int maxConnections;
|
@GuardedBy("lock") private int maxConnections;
|
||||||
// Minimum protocol version we will allow ourselves to connect to: require Bloom filtering.
|
// Minimum protocol version we will allow ourselves to connect to: require Bloom filtering.
|
||||||
private volatile int vMinRequiredProtocolVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
private volatile int vMinRequiredProtocolVersion;
|
||||||
|
|
||||||
/** How many milliseconds to wait after receiving a pong before sending another ping. */
|
/** How many milliseconds to wait after receiving a pong before sending another ping. */
|
||||||
public static final long DEFAULT_PING_INTERVAL_MSEC = 2000;
|
public static final long DEFAULT_PING_INTERVAL_MSEC = 2000;
|
||||||
@ -411,6 +411,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
onTransactionBroadastEventListeners = new CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>>();
|
onTransactionBroadastEventListeners = new CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>>();
|
||||||
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
|
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
|
||||||
bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
|
bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
|
||||||
|
vMinRequiredProtocolVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.BLOOM_FILTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CountDownLatch executorStartupLatch = new CountDownLatch(1);
|
private CountDownLatch executorStartupLatch = new CountDownLatch(1);
|
||||||
@ -855,7 +856,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
|
|
||||||
/** Convenience method for addAddress(new PeerAddress(address, params.port)); */
|
/** Convenience method for addAddress(new PeerAddress(address, params.port)); */
|
||||||
public void addAddress(InetAddress address) {
|
public void addAddress(InetAddress address) {
|
||||||
addAddress(new PeerAddress(address, params.getPort()));
|
addAddress(new PeerAddress(params, address, params.getPort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -884,7 +885,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
for (PeerDiscovery peerDiscovery : peerDiscoverers /* COW */) {
|
for (PeerDiscovery peerDiscovery : peerDiscoverers /* COW */) {
|
||||||
InetSocketAddress[] addresses;
|
InetSocketAddress[] addresses;
|
||||||
addresses = peerDiscovery.getPeers(requiredServices, peerDiscoveryTimeoutMillis, TimeUnit.MILLISECONDS);
|
addresses = peerDiscovery.getPeers(requiredServices, peerDiscoveryTimeoutMillis, TimeUnit.MILLISECONDS);
|
||||||
for (InetSocketAddress address : addresses) addressList.add(new PeerAddress(address));
|
for (InetSocketAddress address : addresses) addressList.add(new PeerAddress(params, address));
|
||||||
if (addressList.size() >= maxPeersToDiscoverCount) break;
|
if (addressList.size() >= maxPeersToDiscoverCount) break;
|
||||||
}
|
}
|
||||||
if (!addressList.isEmpty()) {
|
if (!addressList.isEmpty()) {
|
||||||
@ -1273,7 +1274,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
public Peer connectTo(InetSocketAddress address) {
|
public Peer connectTo(InetSocketAddress address) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
PeerAddress peerAddress = new PeerAddress(address);
|
PeerAddress peerAddress = new PeerAddress(params, address);
|
||||||
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
|
backoffMap.put(peerAddress, new ExponentialBackoff(peerBackoffParams));
|
||||||
return connectTo(peerAddress, true, vConnectTimeoutMillis);
|
return connectTo(peerAddress, true, vConnectTimeoutMillis);
|
||||||
} finally {
|
} finally {
|
||||||
@ -1468,7 +1469,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
return; // Disabled.
|
return; // Disabled.
|
||||||
}
|
}
|
||||||
for (Peer peer : getConnectedPeers()) {
|
for (Peer peer : getConnectedPeers()) {
|
||||||
if (peer.getPeerVersionMessage().clientVersion < Pong.MIN_PROTOCOL_VERSION)
|
if (peer.getPeerVersionMessage().clientVersion < params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.PONG))
|
||||||
continue;
|
continue;
|
||||||
peer.ping();
|
peer.ping();
|
||||||
}
|
}
|
||||||
@ -2079,7 +2080,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
// better then we'll settle for the highest we found instead.
|
// better then we'll settle for the highest we found instead.
|
||||||
int highestVersion = 0, preferredVersion = 0;
|
int highestVersion = 0, preferredVersion = 0;
|
||||||
// If/when PREFERRED_VERSION is not equal to vMinRequiredProtocolVersion, reenable the last test in PeerGroupTest.downloadPeerSelection
|
// If/when PREFERRED_VERSION is not equal to vMinRequiredProtocolVersion, reenable the last test in PeerGroupTest.downloadPeerSelection
|
||||||
final int PREFERRED_VERSION = FilteredBlock.MIN_PROTOCOL_VERSION;
|
final int PREFERRED_VERSION = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.BLOOM_FILTER);
|
||||||
for (Peer peer : candidates) {
|
for (Peer peer : candidates) {
|
||||||
highestVersion = Math.max(peer.getPeerVersionMessage().clientVersion, highestVersion);
|
highestVersion = Math.max(peer.getPeerVersionMessage().clientVersion, highestVersion);
|
||||||
preferredVersion = Math.min(highestVersion, PREFERRED_VERSION);
|
preferredVersion = Math.min(highestVersion, PREFERRED_VERSION);
|
||||||
|
@ -61,7 +61,7 @@ public abstract class PeerSocketHandler extends AbstractTimeoutHandler implement
|
|||||||
public PeerSocketHandler(NetworkParameters params, InetSocketAddress remoteIp) {
|
public PeerSocketHandler(NetworkParameters params, InetSocketAddress remoteIp) {
|
||||||
checkNotNull(params);
|
checkNotNull(params);
|
||||||
serializer = params.getDefaultSerializer();
|
serializer = params.getDefaultSerializer();
|
||||||
this.peerAddress = new PeerAddress(remoteIp);
|
this.peerAddress = new PeerAddress(params, remoteIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PeerSocketHandler(NetworkParameters params, PeerAddress peerAddress) {
|
public PeerSocketHandler(NetworkParameters params, PeerAddress peerAddress) {
|
||||||
|
@ -21,9 +21,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class Pong extends Message {
|
public class Pong extends Message {
|
||||||
/** The smallest protocol version that supports the pong response (BIP 31). Anything beyond version 60000. */
|
|
||||||
public static final int MIN_PROTOCOL_VERSION = 60001;
|
|
||||||
|
|
||||||
private long nonce;
|
private long nonce;
|
||||||
|
|
||||||
public Pong(NetworkParameters params, byte[] payloadBytes) throws ProtocolException {
|
public Pong(NetworkParameters params, byte[] payloadBytes) throws ProtocolException {
|
||||||
|
@ -89,7 +89,7 @@ public class VersionMessage extends Message {
|
|||||||
|
|
||||||
public VersionMessage(NetworkParameters params, int newBestHeight) {
|
public VersionMessage(NetworkParameters params, int newBestHeight) {
|
||||||
super(params);
|
super(params);
|
||||||
clientVersion = NetworkParameters.PROTOCOL_VERSION;
|
clientVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
|
||||||
localServices = 0;
|
localServices = 0;
|
||||||
time = System.currentTimeMillis() / 1000;
|
time = System.currentTimeMillis() / 1000;
|
||||||
// Note that the official client doesn't do anything with these, and finding out your own external IP address
|
// Note that the official client doesn't do anything with these, and finding out your own external IP address
|
||||||
@ -274,7 +274,7 @@ public class VersionMessage extends Message {
|
|||||||
* Returns true if the clientVersion field is >= Pong.MIN_PROTOCOL_VERSION. If it is then ping() is usable.
|
* Returns true if the clientVersion field is >= Pong.MIN_PROTOCOL_VERSION. If it is then ping() is usable.
|
||||||
*/
|
*/
|
||||||
public boolean isPingPongSupported() {
|
public boolean isPingPongSupported() {
|
||||||
return clientVersion >= Pong.MIN_PROTOCOL_VERSION;
|
return clientVersion >= params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.PONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,7 +282,7 @@ public class VersionMessage extends Message {
|
|||||||
* is available and the memory pool of the remote peer will be queried when the downloadData property is true.
|
* is available and the memory pool of the remote peer will be queried when the downloadData property is true.
|
||||||
*/
|
*/
|
||||||
public boolean isBloomFilteringSupported() {
|
public boolean isBloomFilteringSupported() {
|
||||||
return clientVersion >= FilteredBlock.MIN_PROTOCOL_VERSION;
|
return clientVersion >= params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.BLOOM_FILTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if the protocol version and service bits both indicate support for the getutxos message. */
|
/** Returns true if the protocol version and service bits both indicate support for the getutxos message. */
|
||||||
|
@ -116,7 +116,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
public WalletAppKit connectToLocalHost() {
|
public WalletAppKit connectToLocalHost() {
|
||||||
try {
|
try {
|
||||||
final InetAddress localHost = InetAddress.getLocalHost();
|
final InetAddress localHost = InetAddress.getLocalHost();
|
||||||
return setPeerNodes(new PeerAddress(localHost, params.getPort()));
|
return setPeerNodes(new PeerAddress(params, localHost, params.getPort()));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
// Borked machine with no loopback adapter configured properly.
|
// Borked machine with no loopback adapter configured properly.
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -136,6 +136,11 @@ public abstract class AbstractBitcoinNetParams extends NetworkParameters {
|
|||||||
return new MonetaryFormat();
|
return new MonetaryFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getProtocolVersionNum(final ProtocolVersion version) {
|
||||||
|
return version.getBitcoinProtocolVersion();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BitcoinSerializer getSerializer(boolean parseRetain) {
|
public BitcoinSerializer getSerializer(boolean parseRetain) {
|
||||||
return new BitcoinSerializer(this, parseRetain);
|
return new BitcoinSerializer(this, parseRetain);
|
||||||
|
@ -506,7 +506,7 @@ public class WalletProtobufSerializer {
|
|||||||
|
|
||||||
// Update transaction outputs to point to inputs that spend them
|
// Update transaction outputs to point to inputs that spend them
|
||||||
for (Protos.Transaction txProto : walletProto.getTransactionList()) {
|
for (Protos.Transaction txProto : walletProto.getTransactionList()) {
|
||||||
WalletTransaction wtx = connectTransactionOutputs(txProto);
|
WalletTransaction wtx = connectTransactionOutputs(params, txProto);
|
||||||
wallet.addWalletTransaction(wtx);
|
wallet.addWalletTransaction(wtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,7 +672,8 @@ public class WalletProtobufSerializer {
|
|||||||
txMap.put(txProto.getHash(), tx);
|
txMap.put(txProto.getHash(), tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WalletTransaction connectTransactionOutputs(org.bitcoinj.wallet.Protos.Transaction txProto) throws UnreadableWalletException {
|
private WalletTransaction connectTransactionOutputs(final NetworkParameters params,
|
||||||
|
final org.bitcoinj.wallet.Protos.Transaction txProto) throws UnreadableWalletException {
|
||||||
Transaction tx = txMap.get(txProto.getHash());
|
Transaction tx = txMap.get(txProto.getHash());
|
||||||
final WalletTransaction.Pool pool;
|
final WalletTransaction.Pool pool;
|
||||||
switch (txProto.getPool()) {
|
switch (txProto.getPool()) {
|
||||||
@ -710,14 +711,15 @@ public class WalletProtobufSerializer {
|
|||||||
if (txProto.hasConfidence()) {
|
if (txProto.hasConfidence()) {
|
||||||
Protos.TransactionConfidence confidenceProto = txProto.getConfidence();
|
Protos.TransactionConfidence confidenceProto = txProto.getConfidence();
|
||||||
TransactionConfidence confidence = tx.getConfidence();
|
TransactionConfidence confidence = tx.getConfidence();
|
||||||
readConfidence(tx, confidenceProto, confidence);
|
readConfidence(params, tx, confidenceProto, confidence);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WalletTransaction(pool, tx);
|
return new WalletTransaction(pool, tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readConfidence(Transaction tx, Protos.TransactionConfidence confidenceProto,
|
private void readConfidence(final NetworkParameters params, final Transaction tx,
|
||||||
TransactionConfidence confidence) throws UnreadableWalletException {
|
final Protos.TransactionConfidence confidenceProto,
|
||||||
|
final TransactionConfidence confidence) throws UnreadableWalletException {
|
||||||
// We are lenient here because tx confidence is not an essential part of the wallet.
|
// We are lenient here because tx confidence is not an essential part of the wallet.
|
||||||
// If the tx has an unknown type of confidence, ignore.
|
// If the tx has an unknown type of confidence, ignore.
|
||||||
if (!confidenceProto.hasType()) {
|
if (!confidenceProto.hasType()) {
|
||||||
@ -772,7 +774,7 @@ public class WalletProtobufSerializer {
|
|||||||
throw new UnreadableWalletException("Peer IP address does not have the right length", e);
|
throw new UnreadableWalletException("Peer IP address does not have the right length", e);
|
||||||
}
|
}
|
||||||
int port = proto.getPort();
|
int port = proto.getPort();
|
||||||
PeerAddress address = new PeerAddress(ip, port);
|
PeerAddress address = new PeerAddress(params, ip, port);
|
||||||
address.setServices(BigInteger.valueOf(proto.getServices()));
|
address.setServices(BigInteger.valueOf(proto.getServices()));
|
||||||
confidence.markBroadcastBy(address);
|
confidence.markBroadcastBy(address);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,8 @@ public class BitcoinSerializerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddr() throws Exception {
|
public void testAddr() throws Exception {
|
||||||
MessageSerializer serializer = MainNetParams.get().getDefaultSerializer();
|
final NetworkParameters params = MainNetParams.get();
|
||||||
|
MessageSerializer serializer = params.getDefaultSerializer();
|
||||||
// the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
|
// the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
|
||||||
AddressMessage addressMessage = (AddressMessage) serializer.deserialize(ByteBuffer.wrap(ADDRESS_MESSAGE_BYTES));
|
AddressMessage addressMessage = (AddressMessage) serializer.deserialize(ByteBuffer.wrap(ADDRESS_MESSAGE_BYTES));
|
||||||
assertEquals(1, addressMessage.getAddresses().size());
|
assertEquals(1, addressMessage.getAddresses().size());
|
||||||
@ -66,7 +67,7 @@ public class BitcoinSerializerTest {
|
|||||||
serializer.serialize(addressMessage, bos);
|
serializer.serialize(addressMessage, bos);
|
||||||
|
|
||||||
assertEquals(31, addressMessage.getMessageSize());
|
assertEquals(31, addressMessage.getMessageSize());
|
||||||
addressMessage.addAddress(new PeerAddress(InetAddress.getLocalHost()));
|
addressMessage.addAddress(new PeerAddress(params, InetAddress.getLocalHost()));
|
||||||
assertEquals(61, addressMessage.getMessageSize());
|
assertEquals(61, addressMessage.getMessageSize());
|
||||||
addressMessage.removeAddress(0);
|
addressMessage.removeAddress(0);
|
||||||
assertEquals(31, addressMessage.getMessageSize());
|
assertEquals(31, addressMessage.getMessageSize());
|
||||||
|
@ -78,7 +78,7 @@ public class BitcoindComparisonTool {
|
|||||||
VersionMessage ver = new VersionMessage(params, 42);
|
VersionMessage ver = new VersionMessage(params, 42);
|
||||||
ver.appendToSubVer("BlockAcceptanceComparisonTool", "1.1", null);
|
ver.appendToSubVer("BlockAcceptanceComparisonTool", "1.1", null);
|
||||||
ver.localServices = VersionMessage.NODE_NETWORK;
|
ver.localServices = VersionMessage.NODE_NETWORK;
|
||||||
final Peer bitcoind = new Peer(params, ver, new BlockChain(params, new MemoryBlockStore(params)), new PeerAddress(InetAddress.getLocalHost()));
|
final Peer bitcoind = new Peer(params, ver, new BlockChain(params, new MemoryBlockStore(params)), new PeerAddress(params, InetAddress.getLocalHost()));
|
||||||
Preconditions.checkState(bitcoind.getVersionMessage().hasBlockChain());
|
Preconditions.checkState(bitcoind.getVersionMessage().hasBlockChain());
|
||||||
|
|
||||||
final BlockWrapper currentBlock = new BlockWrapper();
|
final BlockWrapper currentBlock = new BlockWrapper();
|
||||||
|
@ -188,8 +188,8 @@ public class ChainSplitTest {
|
|||||||
wallet.commitTx(spend);
|
wallet.commitTx(spend);
|
||||||
// Waiting for confirmation ... make it eligible for selection.
|
// Waiting for confirmation ... make it eligible for selection.
|
||||||
assertEquals(Coin.ZERO, wallet.getBalance());
|
assertEquals(Coin.ZERO, wallet.getBalance());
|
||||||
spend.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{1, 2, 3, 4})));
|
spend.getConfidence().markBroadcastBy(new PeerAddress(unitTestParams, InetAddress.getByAddress(new byte[]{1, 2, 3, 4})));
|
||||||
spend.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{5,6,7,8})));
|
spend.getConfidence().markBroadcastBy(new PeerAddress(unitTestParams, InetAddress.getByAddress(new byte[]{5,6,7,8})));
|
||||||
assertEquals(ConfidenceType.PENDING, spend.getConfidence().getConfidenceType());
|
assertEquals(ConfidenceType.PENDING, spend.getConfidence().getConfidenceType());
|
||||||
assertEquals(valueOf(40, 0), wallet.getBalance());
|
assertEquals(valueOf(40, 0), wallet.getBalance());
|
||||||
Block b2 = b1.createNextBlock(someOtherGuy);
|
Block b2 = b1.createNextBlock(someOtherGuy);
|
||||||
|
@ -429,7 +429,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
peerGroup.start();
|
peerGroup.start();
|
||||||
peerGroup.setPingIntervalMsec(0);
|
peerGroup.setPingIntervalMsec(0);
|
||||||
VersionMessage versionMessage = new VersionMessage(params, 2);
|
VersionMessage versionMessage = new VersionMessage(params, 2);
|
||||||
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
versionMessage.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
|
||||||
versionMessage.localServices = VersionMessage.NODE_NETWORK;
|
versionMessage.localServices = VersionMessage.NODE_NETWORK;
|
||||||
connectPeer(1, versionMessage);
|
connectPeer(1, versionMessage);
|
||||||
peerGroup.waitForPeers(1).get();
|
peerGroup.waitForPeers(1).get();
|
||||||
@ -441,7 +441,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
peerGroup.start();
|
peerGroup.start();
|
||||||
peerGroup.setPingIntervalMsec(100);
|
peerGroup.setPingIntervalMsec(100);
|
||||||
VersionMessage versionMessage = new VersionMessage(params, 2);
|
VersionMessage versionMessage = new VersionMessage(params, 2);
|
||||||
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
versionMessage.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
|
||||||
versionMessage.localServices = VersionMessage.NODE_NETWORK;
|
versionMessage.localServices = VersionMessage.NODE_NETWORK;
|
||||||
InboundMessageQueuer p1 = connectPeer(1, versionMessage);
|
InboundMessageQueuer p1 = connectPeer(1, versionMessage);
|
||||||
Ping ping = (Ping) waitForOutbound(p1);
|
Ping ping = (Ping) waitForOutbound(p1);
|
||||||
@ -458,10 +458,10 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
public void downloadPeerSelection() throws Exception {
|
public void downloadPeerSelection() throws Exception {
|
||||||
peerGroup.start();
|
peerGroup.start();
|
||||||
VersionMessage versionMessage2 = new VersionMessage(params, 2);
|
VersionMessage versionMessage2 = new VersionMessage(params, 2);
|
||||||
versionMessage2.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
versionMessage2.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
|
||||||
versionMessage2.localServices = VersionMessage.NODE_NETWORK;
|
versionMessage2.localServices = VersionMessage.NODE_NETWORK;
|
||||||
VersionMessage versionMessage3 = new VersionMessage(params, 3);
|
VersionMessage versionMessage3 = new VersionMessage(params, 3);
|
||||||
versionMessage3.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
versionMessage3.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
|
||||||
versionMessage3.localServices = VersionMessage.NODE_NETWORK;
|
versionMessage3.localServices = VersionMessage.NODE_NETWORK;
|
||||||
assertNull(peerGroup.getDownloadPeer());
|
assertNull(peerGroup.getDownloadPeer());
|
||||||
Peer a = connectPeer(1, versionMessage2).peer;
|
Peer a = connectPeer(1, versionMessage2).peer;
|
||||||
|
@ -79,7 +79,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
VersionMessage ver = new VersionMessage(params, 100);
|
VersionMessage ver = new VersionMessage(params, 100);
|
||||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4000);
|
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4000);
|
||||||
peer = new Peer(params, ver, new PeerAddress(address), blockChain);
|
peer = new Peer(params, ver, new PeerAddress(params, address), blockChain);
|
||||||
peer.addWallet(wallet);
|
peer.addWallet(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
// Check co-ordination of which peer to download via the memory pool.
|
// Check co-ordination of which peer to download via the memory pool.
|
||||||
VersionMessage ver = new VersionMessage(params, 100);
|
VersionMessage ver = new VersionMessage(params, 100);
|
||||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4242);
|
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4242);
|
||||||
Peer peer2 = new Peer(params, ver, new PeerAddress(address), blockChain);
|
Peer peer2 = new Peer(params, ver, new PeerAddress(params, address), blockChain);
|
||||||
peer2.addWallet(wallet);
|
peer2.addWallet(wallet);
|
||||||
VersionMessage peerVersion = new VersionMessage(params, OTHER_PEER_CHAIN_HEIGHT);
|
VersionMessage peerVersion = new VersionMessage(params, OTHER_PEER_CHAIN_HEIGHT);
|
||||||
peerVersion.clientVersion = 70001;
|
peerVersion.clientVersion = 70001;
|
||||||
|
@ -45,9 +45,9 @@ public class TxConfidenceTableTest {
|
|||||||
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(params, COIN, to, change);
|
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(params, COIN, to, change);
|
||||||
assertEquals(tx1.getHash(), tx2.getHash());
|
assertEquals(tx1.getHash(), tx2.getHash());
|
||||||
|
|
||||||
address1 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
address1 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||||
address2 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }));
|
address2 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }));
|
||||||
address3 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
|
address3 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -423,8 +423,8 @@ public class WalletTest extends TestWithWallet {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{1,2,3,4})));
|
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByAddress(new byte[]{1,2,3,4})));
|
||||||
t.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{10,2,3,4})));
|
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByAddress(new byte[]{10,2,3,4})));
|
||||||
wallet.commitTx(t);
|
wallet.commitTx(t);
|
||||||
Threading.waitForUserCode();
|
Threading.waitForUserCode();
|
||||||
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
|
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
|
||||||
|
@ -104,8 +104,8 @@ public class WalletProtobufSerializerTest {
|
|||||||
// Check basic tx serialization.
|
// Check basic tx serialization.
|
||||||
Coin v1 = COIN;
|
Coin v1 = COIN;
|
||||||
Transaction t1 = createFakeTx(params, v1, myAddress);
|
Transaction t1 = createFakeTx(params, v1, myAddress);
|
||||||
t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
|
t1.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("1.2.3.4")));
|
||||||
t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
|
t1.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("5.6.7.8")));
|
||||||
t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
|
t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
|
||||||
myWallet.receivePending(t1, null);
|
myWallet.receivePending(t1, null);
|
||||||
Wallet wallet1 = roundTrip(myWallet);
|
Wallet wallet1 = roundTrip(myWallet);
|
||||||
|
@ -52,9 +52,9 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
|
|||||||
assertFalse(DefaultCoinSelector.isSelectable(t));
|
assertFalse(DefaultCoinSelector.isSelectable(t));
|
||||||
t.getConfidence().setSource(TransactionConfidence.Source.SELF);
|
t.getConfidence().setSource(TransactionConfidence.Source.SELF);
|
||||||
assertFalse(DefaultCoinSelector.isSelectable(t));
|
assertFalse(DefaultCoinSelector.isSelectable(t));
|
||||||
t.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
|
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("1.2.3.4")));
|
||||||
assertFalse(DefaultCoinSelector.isSelectable(t));
|
assertFalse(DefaultCoinSelector.isSelectable(t));
|
||||||
t.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
|
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("5.6.7.8")));
|
||||||
assertTrue(DefaultCoinSelector.isSelectable(t));
|
assertTrue(DefaultCoinSelector.isSelectable(t));
|
||||||
t = new Transaction(params);
|
t = new Transaction(params);
|
||||||
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
|
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user