Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github Actions workflow gradle.yml #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions .github/workflow/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Java CI

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# windows-latest currently fails on some tests
os: [ubuntu-latest, macOS-latest, windows-latest]
java: [ '8', '11' ]
fail-fast: false
name: JAVA ${{ matrix.java }} OS ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Build with Gradle
run: gradle build --stacktrace
27 changes: 15 additions & 12 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,34 +176,37 @@ public class PeerGroup implements TransactionBroadcaster {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
// We received a relevant transaction. We MAY need to recalculate and resend the Bloom filter, but only
// if we have received a transaction that includes a relevant P2PK output.
// if we have received a transaction that includes a relevant P2PK or P2WPKH output.
//
// The reason is that P2PK outputs, when spent, will not repeat any data we can predict in their
// The reason is that P2PK and P2WPKH outputs, when spent, will not repeat any data we can predict in their
// inputs. So a remote peer will update the Bloom filter for us when such an output is seen matching the
// existing filter, so that it includes the tx hash in which the P2PK output was observed. Thus
// existing filter, so that it includes the tx hash in which the P2PK/P2WPKH output was observed. Thus
// the spending transaction will always match (due to the outpoint structure).
//
// Unfortunately, whilst this is required for correct sync of the chain in blocks, there are two edge cases.
//
// (1) If a wallet receives a relevant, confirmed P2PK output that was not broadcast across the network,
// (1) If a wallet receives a relevant, confirmed P2PK/P2WPKH output that was not broadcast across the network,
// for example in a coinbase transaction, then the node that's serving us the chain will update its filter
// but the rest will not. If another transaction then spends it, the other nodes won't match/relay it.
//
// (2) If we receive a P2PK output broadcast across the network, all currently connected nodes will see
// (2) If we receive a P2PK/P2WPKH output broadcast across the network, all currently connected nodes will see
// it and update their filter themselves, but any newly connected nodes will receive the last filter we
// calculated, which would not include this transaction.
//
// For this reason we check if the transaction contained any relevant P2PKs and force a recalc
// For this reason we check if the transaction contained any relevant P2PKs or P2WPKHs and force a recalc
// and possibly retransmit if so. The recalculation process will end up including the tx hash into the
// filter. In case (1), we need to retransmit the filter to the connected peers. In case (2), we don't
// and shouldn't, we should just recalculate and cache the new filter for next time.
for (TransactionOutput output : tx.getOutputs()) {
if (ScriptPattern.isP2PK(output.getScriptPubKey()) && output.isMine(wallet)) {
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
else
recalculateFastCatchupAndFilter(FilterRecalculateMode.DONT_SEND);
return;
Script scriptPubKey = output.getScriptPubKey();
if (ScriptPattern.isP2PK(scriptPubKey) || ScriptPattern.isP2WPKH(scriptPubKey)) {
if (output.isMine(wallet)) {
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
else
recalculateFastCatchupAndFilter(FilterRecalculateMode.DONT_SEND);
return;
}
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions core/src/main/java/org/bitcoinj/utils/BtcFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* <li>access to character information that allows for vertical
* alignment of tabular columns of formatted values.</ol>
*
* <h3>Basic Usage</h3>
* <h2>Basic Usage</h2>
*
* <p>Basic usage is very simple:</p>
*
Expand All @@ -87,13 +87,13 @@
* Coin all = f.parseObject("M฿ 21"); <strong>// All the money in the world</strong>
* </pre></blockquote>
*
* <h3>Auto-Denomination versus Fixed-Denomination</h3>
* <h2>Auto-Denomination versus Fixed-Denomination</h2>
*
* <p>There are two provided concrete classes, one that automatically denominates values to
* be formatted, {@link BtcAutoFormat}, and another that formats any value in units of a
* fixed, specified denomination, {@link BtcFixedFormat}.</p>
*
* <h4>Automatic Denomination</h4>
* <h3>Automatic Denomination</h3>
*
* <p>Automatic denomination means that the formatter adjusts the denominational units in which a
* formatted number is expressed based on the monetary value that number represents. An
Expand All @@ -111,7 +111,7 @@
* locale, a value of one bitcoin might be formatted as {@code ฿1.00} where a value
* exceeding that by one satoshi would be {@code µ฿1,000,000.01}</p>
*
* <h4>Fixed Denomination</h4>
* <h3>Fixed Denomination</h3>
*
* <p>Fixed denomination means that the same denomination of units is used for every value that is
* formatted or parsed by a given formatter instance. A fixed-denomination formatter is
Expand All @@ -122,7 +122,7 @@
* {@code 1.0000 BTC}, or one bitcoin, in millibitcoins, one shifts the decimal point
* three places, that is, to {@code 1000.0 mBTC}.</p>
*
* <h3>Construction</h3>
* <h2>Construction</h2>
*
* <p>There are two ways to obtain an instance of this class:</p>
*
Expand All @@ -136,7 +136,7 @@
* access to some features not available through the factory methods,
* such as using custom formatting patterns and currency symbols.</p>
*
* <h4>Factory Methods</h4>
* <h3>Factory Methods</h3>
*
* <p>Although formatting and parsing is performed by one of the concrete
* subclasses, you can obtain formatters using the various static factory
Expand Down Expand Up @@ -233,7 +233,7 @@
* fractional quantity of satoshis, and these defaults can be overridden by arguments to the
* {@code format()} method. See below for examples.</p>
*
* <h4>The {@link Builder} Class</h4>
* <h3>The {@link Builder} Class</h3>
*
* <p>A new {@link BtcFormat.Builder} instance is returned by the {@link #builder()} method. Such
* an object has methods that set the configuration parameters of a {@link BtcFormat}
Expand Down Expand Up @@ -264,7 +264,7 @@
*
* <p>See the documentation of the {@link BtcFormat.Builder} class for details.</p>
*
* <h3>Formatting</h3>
* <h2>Formatting</h2>
*
* <p>You format a Bitcoin monetary value by passing it to the {@link BtcFormat#format(Object)}
* method. This argument can be either a {@link Coin}-type object or a
Expand Down Expand Up @@ -350,7 +350,7 @@
* BtcFormat(4).code(); <strong>// unnamed denomination has no code; raises exception</strong>
* </pre></blockquote>
*
* <h4>Formatting for Tabular Columns</h4>
* <h3>Formatting for Tabular Columns</h3>
*
* <p>When displaying tables of monetary values, you can lessen the
* risk of human misreading-error by vertically aligning the decimal
Expand Down Expand Up @@ -396,7 +396,7 @@
* then see the documentation for the {@link NumberFormat} class
* for an explanation of how to do that.</p>
*
* <h3>Parsing</h3>
* <h2>Parsing</h2>
*
* <p>The {@link #parse(String)} method accepts a {@link String} argument, and returns a
* {@link Coin}-type value. The difference in parsing behavior between instances of {@link
Expand Down Expand Up @@ -443,9 +443,9 @@
* raise a {@code ParseException}, as will any other detected
* parsing error.</p>
*
* <h3>Limitations</h3>
* <h2>Limitations</h2>
*
* <h4>Parsing</h4>
* <h3>Parsing</h3>
*
* <p>Parsing is performed by an underlying {@link NumberFormat} object. While this
* delivers the benefit of recognizing locale-specific patterns, some have criticized other
Expand All @@ -455,13 +455,13 @@
* input from end-users, then you should consider whether you would benefit from any of the
* work-arounds mentioned in that article.</p>
*
* <h4>Exotic Locales</h4>
* <h3>Exotic Locales</h3>
*
* <p>This class is not well-tested in locales that use non-ascii
* character sets, especially those where writing proceeds from
* right-to-left. Helpful feedback in that regard is appreciated.</p>
*
* <h3>Thread-Safety</h3>
* <h2>Thread-Safety</h2>
*
* <p>Instances of this class are immutable.</p>
*
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/org/bitcoinj/core/PeerGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ public void testBloomOnP2PK() throws Exception {
tx2.addInput(tx.getOutput(0));
TransactionOutPoint outpoint = tx2.getInput(0).getOutpoint();
assertTrue(p1.lastReceivedFilter.contains(key.getPubKey()));
assertTrue(p1.lastReceivedFilter.contains(key.getPubKeyHash()));
assertFalse(p1.lastReceivedFilter.contains(tx.getTxId().getBytes()));
inbound(p1, tx);
// p1 requests dep resolution, p2 is quiet.
Expand All @@ -635,6 +636,7 @@ public void testBloomOnP2PK() throws Exception {
// Now we connect p3 and there is a new bloom filter sent, that DOES match the relevant outpoint.
InboundMessageQueuer p3 = connectPeer(3);
assertTrue(p3.lastReceivedFilter.contains(key.getPubKey()));
assertTrue(p3.lastReceivedFilter.contains(key.getPubKeyHash()));
assertTrue(p3.lastReceivedFilter.contains(outpoint.unsafeBitcoinSerialize()));
}

Expand Down