Skip to content

Commit 3237163

Browse files
committed
Update deps, fix linting errors, general maintenance
1 parent 3b18782 commit 3237163

18 files changed

+1446
-53
lines changed

.github/workflows/main.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
permissions:
10+
contents: read
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 30
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup Go ${{ matrix.go-version }}
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: stable
21+
- name: Install golangci-lint
22+
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
23+
env:
24+
GO111MODULE: on
25+
- name: Run goclean.sh
26+
run: ./goclean.sh
27+
env:
28+
GO111MODULE: on

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
# Neutrino: Privacy-Preserving Bitcoin Cash Light Client
22

3-
[![Build Status](https://travis-ci.org/gcash/neutrino.svg?branch=master)](https://travis-ci.org/gcash/neutrino)
3+
[![Build Status](https://github.com/gcash/neutrino/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/gcash/neutrino/actions/workflows/main.yml)
44
[![Godoc](https://godoc.org/github.com/gcash/neutrino?status.svg)](https://godoc.org/github.com/gcash/neutrino)
55

66
Neutrino is an **experimental** Bitcoin light client written in Go. It was developed by Roasbeef and other BTC contributors as part of the broader Lightning Network project.
77
This repo is a port of neutrino to the Bitcoin Cash network as part of the bchd project. It uses a [new proposal](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-June/014474.html) for compact block filters to minimize bandwidth and storage use on the client side, while attempting to preserve privacy and minimize processor load on full nodes serving light clients.
88

99
## Mechanism of operation
10+
1011
The light client synchronizes only block headers and a chain of compact block filter headers specifying the correct filters for each block. Filters are loaded lazily and stored in the database upon request; blocks are loaded lazily and not saved. There are multiple [known major issues](https://github.com/gcash/neutrino/issues) with the client, so it is **not recommended** to use it with real money at this point.
1112

1213
## Usage
14+
1315
The client is instantiated as an object using `NewChainService` and then started. Upon start, the client sets up its database and other relevant files and connects to the p2p network. At this point, it becomes possible to query the client.
1416

1517
### Queries
18+
1619
There are various types of queries supported by the client. There are many ways to access the database, for example, to get block headers by height and hash; in addition, it's possible to get a full block from the network using `GetBlockFromNetwork` by hash. However, the most useful methods are specifically tailored to scan the blockchain for data relevant to a wallet or a smart contract platform such as a [Lightning Network node like `lnd`](https://github.com/lightningnetwork/lnd). These are described below.
1720

1821
#### Rescan
22+
1923
`Rescan` allows a wallet to scan a chain for specific TXIDs, outputs, and addresses. A start and end block may be specified along with other options. If no end block is specified, the rescan continues until stopped. If no start block is specified, the rescan begins with the latest known block. While a rescan runs, it notifies the client of each connected and disconnected block; the notifications follow the [btcjson](https://github.com/gcash/bchd/blob/master/btcjson/chainsvrwsntfns.go) format with the option to use any of the relevant notifications. It's important to note that "recvtx" and "redeemingtx" notifications are only sent when a transaction is confirmed, not when it enters the mempool; the client does not currently support accepting 0-confirmation transactions.
2024

2125
#### GetUtxo
26+
2227
`GetUtxo` allows a wallet or smart contract platform to check that a UTXO exists on the blockchain and has not been spent. It is **highly recommended** to specify a start block; otherwise, in the event that the UTXO doesn't exist on the blockchain, the client will download all the filters back to block 1 searching for it. The client scans from the tip of the chain backwards, stopping when it finds the UTXO having been either spent or created; if it finds neither, it keeps scanning backwards until it hits the specified start block or, if a start block isn't specified, the first block in the blockchain. It returns a `SpendReport` containing either a `TxOut` including the `PkScript` required to spend the output, or containing information about the spending transaction, spending input, and block height in which the spending transaction was seen.
2328

2429
### Stopping the client
30+
2531
Calling `Stop` on the `ChainService` client allows the user to stop the client; the method doesn't return until the `ChainService` is cleanly shut down.

batch_spend_reporter.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package neutrino
22

33
import (
44
"bytes"
5+
56
"github.com/gcash/bchd/chaincfg/chainhash"
67
"github.com/gcash/bchd/wire"
78
)
@@ -65,7 +66,8 @@ func (b *batchSpendReporter) NotifyUnspentAndUnfound() {
6566
// FailRemaining will return an error to all remaining requests in the event we
6667
// experience a critical rescan error. The error is threaded through to allow
6768
// the syntax:
68-
// return reporter.FailRemaining(err)
69+
//
70+
// return reporter.FailRemaining(err)
6971
func (b *batchSpendReporter) FailRemaining(err error) error {
7072
for outpoint, requests := range b.requests {
7173
b.notifyRequests(&outpoint, requests, nil, err)

blockmanager.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ func (b *blockManager) detectBadPeers(headers map[string]*wire.MsgCFHeaders,
15381538
// other peers.
15391539
func resolveFilterMismatchFromBlock(block *wire.MsgBlock,
15401540
fType wire.FilterType, filtersFromPeers map[string]*gcs.Filter,
1541-
threshold int) ([]string, error) {
1541+
_ int) ([]string, error) {
15421542

15431543
badPeers := make(map[string]struct{})
15441544

@@ -1630,7 +1630,7 @@ func (b *blockManager) getCFHeadersForAllPeers(height uint32,
16301630
// Send the query to all peers and record their responses in the map.
16311631
b.server.queryAllPeers(
16321632
msg,
1633-
func(sp *ServerPeer, resp wire.Message, quit chan<- struct{},
1633+
func(sp *ServerPeer, resp wire.Message, _ chan<- struct{},
16341634
peerQuit chan<- struct{}) {
16351635
switch m := resp.(type) {
16361636
case *wire.MsgCFHeaders:
@@ -1668,8 +1668,8 @@ func (b *blockManager) fetchFilterFromAllPeers(
16681668
fitlerReqMsg := wire.NewMsgGetCFilters(filterType, height, &blockHash)
16691669
b.queries.queryAllPeers(
16701670
fitlerReqMsg,
1671-
func(sp *ServerPeer, resp wire.Message, quit chan<- struct{},
1672-
peerQuit chan<- struct{}) {
1671+
func(sp *ServerPeer, resp wire.Message, _ chan<- struct{},
1672+
_ chan<- struct{}) {
16731673

16741674
switch response := resp.(type) {
16751675
// We're only interested in "cfilter" messages.
@@ -1716,7 +1716,7 @@ func (b *blockManager) getCheckpts(lastHash *chainhash.Hash,
17161716
getCheckptMsg := wire.NewMsgGetCFCheckpt(fType, lastHash)
17171717
b.queries.queryAllPeers(
17181718
getCheckptMsg,
1719-
func(sp *ServerPeer, resp wire.Message, quit chan<- struct{},
1719+
func(sp *ServerPeer, resp wire.Message, _ chan<- struct{},
17201720
peerQuit chan<- struct{}) {
17211721
switch m := resp.(type) {
17221722
case *wire.MsgCFCheckpt:
@@ -2085,7 +2085,7 @@ func (b *blockManager) QueueInv(inv *wire.MsgInv, sp *ServerPeer) {
20852085
}
20862086
}
20872087

2088-
/// QueueTx adds the passed transaction message and peer to the block handling
2088+
// / QueueTx adds the passed transaction message and peer to the block handling
20892089
// queue. Responds to the done channel argument after the tx message is
20902090
// processed.
20912091
func (b *blockManager) QueueTx(tx *bchutil.Tx, sp *ServerPeer) {
@@ -2679,7 +2679,7 @@ func (b *blockManager) calcNextRequiredDifficulty(newBlockTime time.Time,
26792679
return 0, errors.New("unknown difficulty algorithm")
26802680
}
26812681

2682-
func (b *blockManager) calcAsertRequiredDifficulty(lastNode *headerlist.Node, anchorBlockHeight int32, anchorBlockTime int64, anchorBlockBits uint32, newBlockTime time.Time) (uint32, error) {
2682+
func (b *blockManager) calcAsertRequiredDifficulty(lastNode *headerlist.Node, _ int32, _ int64, _ uint32, newBlockTime time.Time) (uint32, error) {
26832683
// For networks that support it, allow special reduction of the
26842684
// required difficulty once too much time has elapsed without
26852685
// mining a block.

blockmanager_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func TestBlockManagerInitialInterval(t *testing.T) {
347347
// responses.
348348
bm.server.queryBatch = func(msgs []wire.Message,
349349
f func(*ServerPeer, wire.Message, wire.Message) bool,
350-
q <-chan struct{}, qo ...QueryOption) {
350+
_ <-chan struct{}, _ ...QueryOption) {
351351

352352
responses, err := generateResponses(msgs, headers)
353353
if err != nil {
@@ -572,7 +572,7 @@ func TestBlockManagerInvalidInterval(t *testing.T) {
572572

573573
bm.server.queryBatch = func(msgs []wire.Message,
574574
f func(*ServerPeer, wire.Message, wire.Message) bool,
575-
q <-chan struct{}, qo ...QueryOption) {
575+
_ <-chan struct{}, _ ...QueryOption) {
576576

577577
responses, err := generateResponses(msgs, headers)
578578
if err != nil {
@@ -718,10 +718,10 @@ type mockQueryAccess struct {
718718
}
719719

720720
func (m *mockQueryAccess) queryAllPeers(
721-
queryMsg wire.Message,
721+
_ wire.Message,
722722
checkResponse func(sp *ServerPeer, resp wire.Message,
723723
quit chan<- struct{}, peerQuit chan<- struct{}),
724-
options ...QueryOption) {
724+
_ ...QueryOption) {
725725

726726
for p, resp := range m.answers {
727727
pp, err := peer.NewOutboundPeer(&peer.Config{}, p)

0 commit comments

Comments
 (0)