Commit Graph

2919 Commits

Author SHA1 Message Date
Andreas Schildbach
d6851edb2f build.gradle: Update OkHttp to 3.12.13. 2021-09-25 23:36:34 +02:00
Andreas Schildbach
2882d63616 build.gradle: Update BouncyCastle to 1.69. 2021-09-25 23:23:12 +02:00
Andreas Schildbach
47660f6418 build.gradle: migrate from protobuf-java to protobuf-javalite
This commit contains rather hard to review diffs to the protobuf test datasets in .txt format.
To aid the review, this Python script can be used to convert the data from the old to the new
format:

```
import sys

file = open(sys.argv[1])
outfile = open(sys.argv[1] + ".lite", "w")
line = file.readline()
lines = []

def sortAndPrint(group, removeLastLB=False, removeFirstLB=False):
    group.sort()
    if removeFirstLB and group[0] == "\n":
        group.remove("\n")
    for i in range(len(group)):
        if i == len(group) - 1 and removeLastLB:
            group[i] = group[i].rstrip()
        print(group[i], end="", file=outfile)

def sign32neg(value):
    if 0x80000000 <= value <= 0xFFFFFFFF:
        value &= 0x7FFFFFFF
        value = int(value)
        value = ~value
        value ^= 0x7FFFFFFF
    return value

def processPath(path):
    parts = path.rstrip().split(":")
    number = int(parts[1].lstrip())
    if number >= 0x80000000:
        number = sign32neg(number)
    return parts[0] + ": " + str(number) + "\n"

groupcount = 0
while len(line) > 0:
    if line.startswith("type:"):
        if len(lines):
            sortAndPrint(lines, removeFirstLB=groupcount==0)
            groupcount += 1
        lines.clear()
        lines.append(line)
    elif line.find("deterministic_key {") != -1:
        structure = line
        innerlines = []
        line = file.readline()
        while not line.startswith('}'):
            if line.find("path") != -1:  # preserve order of paths
                pathlines = processPath(line)
                line = file.readline()
                if line.startswith('}'):
                    innerlines.append(pathlines)
                    continue
                while line.find("path") != -1:
                    pathlines += processPath(line)
                    line = file.readline()
                innerlines.append(pathlines)
                if line.startswith('}'):
                    continue
            if line.startswith("  sigsRequiredToSpend"):
                line = line.replace("sigsRequiredToSpend", "sigs_required_to_spend")
            innerlines.append(line)
            line = file.readline()
        innerlines.sort()
        for l in innerlines:
            structure += l
        structure += line.rstrip() + "\n"
        lines.append(structure)
    elif line.find("path") != -1:  # preserve order of paths
        accountpathlines = processPath(line)
        line = file.readline()
        while line.find("path") != -1:
            accountpathlines += processPath(line)
            line = file.readline()
        lines.append(accountpathlines)
        lines.append(line)
    else:
        lines.append(line)
    line = file.readline()
print(file=outfile)
sortAndPrint(lines, removeLastLB=True)
file.close()
outfile.close()
```
2021-09-25 11:00:42 +02:00
Andreas Schildbach
f859f571ca BasicKeyChain, DeterministicKeyChain, WalletTool: use only protobuf API that is available also on protobuf-lite
This is meant to aid migration to protobuf-lite.
2021-09-24 11:33:06 +02:00
sqrrm
d6195d584e Wallet: clone transaction before committing
Problem: A transaction received from the network is added to all wallets
that find it relevant. If two wallets find the same transaction relevant
the same Transaction instance is added to both wallets.

Spending the outputs from this transaction can cause consistiency
issues, in particular if the outputs are spent in the same transaction,
as shown in WalletTest.oneTxTwoWallets. There are probably more issues
with having the same Transaction instance handled by two different
wallets.

Fix: Clone the transaction before adding it to the wallet.
2021-09-20 23:01:31 +02:00
Sean Gilligan
7178cd3f4f Secp256k1Context: replace AccessControlException
AccessControlException is deprecated for removal in JDK 17.

its parent classes are:

`AccessControlException` <- `SecurityException` <- `RuntimeException`

It can be replaced with its parent `SecurityException` which is not deprecated and will behave almost identically in this one place where it is used.
2021-09-20 22:34:53 +02:00
Sean Gilligan
6da10f8641 build.gradle: Update SLF4J to 1.7.32. 2021-09-17 11:51:11 +02:00
Sean Gilligan
5a1dbd9fb6 UtilsTest: Fix not resetMocking() after MockClock test 2021-09-08 18:54:42 +02:00
Sean Gilligan
212ac5b95f BlockChainTest, ExponentialBackoffTest, BasicKeyChainTest: Use no-args Utils.setMockClock() where possible
Replace a few calls to:

Utils.setMockClock(Utils.setCurrentTimeSeconds())

with

Utils.setMockClock()

The behavior of the first is slightly different
and possibly pathological, and I believe that in
all three cases in this PR, it is the later behavior
that is intended.
2021-09-08 18:50:21 +02:00
Sean Gilligan
185f880e78 NetworkParameters: Move genesis block construction to lazy getter
This refactoring breaks the cyclic dependency of NetworkParameters constructors
on the constructors in Block and will allow us to migrate the code
now in the getGenesisBlock() methods into (atomic) factories/constructors
in `Block` allowing us to create block objects that are unmodifiable/immutable.
2021-09-08 11:07:11 +02:00
Sean Gilligan
787c9caced Block, AbstractBitcoinNetParams subclasses: Constants
* Add Block.STANDARD_MAX_DIFFICULTY_TARGET and use in subclasses
* Always define maxTarget in terms of a nBits constant and use
  Utils.decodeCompactBits()
* Define constants for GENESIS_TIME and GENESIS_NONCE
2021-09-08 00:51:24 +02:00
Sean Gilligan
01efcea5ea RegTestParams: Set RegTest MAX_TARGET to match EASIEST_DIFFICULTY_TARGET
Clear the lowest 232 bits.
2021-09-08 00:34:46 +02:00
Sean Gilligan
9fa36d495f UnitTestParams: Set UnitTest maxTarget to EASIEST_DIFFICULTY_TARGET
The tests are currently using a custom value for maxTarget
that can’t be generated via CompactBits format.

This commit changes the string constant to match what would be
generated by using Utils.decodeCompactBits(EASIEST_DIFFICULTY_TARGET).
2021-09-08 00:29:53 +02:00
Sean Gilligan
42bb5b386e AbstractBitcoinNetParams subclasses: Improve Genesis hash checking
1. Define Sha256 constants for expected hashes
2. Compare hashes in binary form
3. Move hash comparison to immediately follow Block creation
4. Add error message to the check state call
2021-09-08 00:24:11 +02:00
Sean Gilligan
34184f0949 ChainSplitTest: Use getGenesisBlock() getter
This is the only place where getGenesisBlock() is
not being used.
2021-09-08 00:20:10 +02:00
Sean Gilligan
0cb686481f Block: Fix JavaDoc comment on EASIEST_DIFFICULTY_TARGET
It said “half of all possible hash solutions” which
led me to believe that decodeCompactBits() would
extend 1’s all the way out to the least significant
bit.
2021-09-07 12:27:54 +02:00
Sean Gilligan
6412db3319 UtilsTest: Add CompactBits test cases for common difficulties 2021-09-07 12:23:19 +02:00
Sean Gilligan
a19986d475 RegTestParams: remove redundant init of genesis block
(It looks like the override of getGenesisBlock() was added
back in 2013 when RegTestParams was a subclass of
TestNet2Params.)
2021-09-06 23:15:49 +02:00
Sean Gilligan
eb74d8aae4 Reorganize NetworkParameters subclass for easy diffs
Reorganize the initialization of the constants in each NetworkParameters
subclass so we can easily do diffs of `MainNetParms` vs `TestNet3Params`
and easily see how they are the same and how they are different.

I also reorganized the import statements so they “diff” better as well.

Other than those changes the only code I actually changed is
using the constant `PAYMENT_PROTOCOL_ID_UNIT_TESTS` instead of “unittest”
in getPaymentProcolId in UnitTestParams.

This will help us with the next step which is to create symbolic constants
for some of the parameters for the genesis blocks.
2021-09-05 13:38:59 -07:00
Sean Gilligan
2d9e43f51d Block: cloneAsHeader() cleanup
* Fix redundant write of version in new block
* Re-order setting other fields more logically
2021-09-05 16:01:37 +02:00
Sean Gilligan
4a5207e7ce FullPrunedBlockChain: Remove use of deprecated Block::getBlockInflation 2021-09-05 15:54:25 +02:00
Sean Gilligan
1df13312b3 AbstractBlockChain: Fix JavaDocs warnings 2021-09-05 15:51:44 +02:00
Sean Gilligan
09ba08ec7c PeerAddress: Ignore time in equals()/hashCode() 2021-09-05 00:39:13 +02:00
Sean Gilligan
345cfcad40 Address: Make binary constructor protected, fix JavaDocs 2021-09-05 00:36:19 +02:00
Sean Gilligan
083a8bda3b core/org.bitcoin.*: Fix JavaDoc warnings 2021-09-05 00:30:21 +02:00
Sean Gilligan
9313097bad Block: Remove deprecated constructor 2021-09-05 00:18:25 +02:00
Sean Gilligan
5ccc41f35b BlockTest: Remove unneeded suppress deprecation warning 2021-09-04 09:56:58 +02:00
Sean Gilligan
56a1e24ed2 Block: add createGenesisTransaction() method
* Refactor code from createGenesis()
* Also replace (unnecessarily broad) catch of Exception with
  catch of IOException
2021-09-03 12:06:01 +02:00
Sean Gilligan
c31d071a04 Block: Move NetworkParameters::createGenesis to Block
Its a factory method for creating Blocks, so it really belongs
there. Moving it there will also help us move further along
our path to reduced mutability in the Block class.
2021-09-02 09:31:19 +02:00
Sean Gilligan
05c911115e Block: Merge copyBitcoinHeaderTo() into cloneAsHeader()
Merge copyBitcoinHeaderTo() into cloneAsHeader() as part of an
overall effort to reduce mutability of the Block class.
2021-09-02 00:42:34 +02:00
Sean Gilligan
cd8226987f Block: Make EMPTY_BYTES constant private 2021-09-02 00:38:32 +02:00
Sean Gilligan
1463423310 Block: Add @VisibleForTesting to some mutating methods
These methods should only be used for testing and will hopefully be
deprecated and/or refactored to another class in the future.
2021-09-02 00:34:55 +02:00
Andreas Schildbach
c632aa19fa AbstractBitcoinNetParams: Make use of REWARD_HALVING_INTERVAL constant 2021-09-01 09:20:20 +02:00
Sean Gilligan
fd75b539da Sha256Hash: Clarify javadoc 2021-09-01 08:53:37 +02:00
Andreas Schildbach
8a775a37d8 build.gradle: Migrate from maven to maven-publish plugin
To publish to the local Maven repository, use `gradle publishToMavenLocal` rather than `gradle install`.
2021-09-01 01:37:28 +02:00
Andreas Schildbach
6a9893c3df MonetaryFormat: Support satoshi denomination. 2021-08-23 13:58:27 +02:00
Andreas Schildbach
4e4968ecb5 LazyECPoint: JavaDoc for the constructors. 2021-08-10 23:37:00 +02:00
Andreas Schildbach
ca8811e1f6 UTXO: Make index, hash and value the identity. 2021-08-10 23:26:54 +02:00
Andreas Schildbach
6629bfb4f4 UTXO: Make fields final. 2021-08-10 23:26:54 +02:00
Andreas Schildbach
0857e339dd UTXO: Migrate constructor that takes a stream to a static constructor fromStream(). 2021-08-10 23:26:54 +02:00
Andreas Schildbach
8a99965ac9 UTXO: Remove Java serialization. 2021-08-10 23:26:54 +02:00
newbull
d9157218ea SendAddrV2Message: Fix 'unterminated inline tag' in a Javadoc. 2021-08-10 23:19:48 +02:00
Andreas Schildbach
a61080ebeb BlockFileLoader: Remove inexact block size check.
Bitcoin Core doesn't allow over- or undersized blocks in its dat files.
2021-08-10 21:58:14 +02:00
Andreas Schildbach
e407240b7e Support BIP133 feefilter messages. 2021-05-03 16:23:51 +02:00
Andreas Schildbach
fd85807422 PeerAddress: Support Tor hidden service addresses. 2021-04-30 12:59:47 +02:00
Andreas Schildbach
d511effbce Support BIP155 addrv2 messages. 2021-04-30 12:52:33 +02:00
Andreas Schildbach
9e9b6b4c74 Block, Transaction: Use VarInt.getSizeInBytes() on a VarInt we already have, rather than the static VarInt.sizeOf(). 2021-04-28 14:39:40 +02:00
Andreas Schildbach
bdc0310f1f Message hierarchy: Use int (rather than long) for several array and string lengths. 2021-04-28 14:39:24 +02:00
Andreas Schildbach
67399b6c13 Message: Make readVarInt() return a VarInt rather than long. 2021-04-24 17:08:59 +02:00
Andreas Schildbach
ae4f6d43ce VarInt: Introduce intValue() and longValue() accessors and use them, deprecating access to the field. 2021-04-24 17:00:12 +02:00