Skip to content

Commit

Permalink
neutrino v0.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
losh11 committed Feb 23, 2022
2 parents 1192623 + 86e8ff6 commit 765a6a3
Show file tree
Hide file tree
Showing 59 changed files with 2,050 additions and 1,089 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
branches:
- "master"
pull_request:
branches:
- "*"

defaults:
run:
shell: bash

env:
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
GO_VERSION: 1.16.x

jobs:
########################
# compilation check
########################
rpc-check:
name: RPC and mobile compilation check
runs-on: ubuntu-latest
steps:
- name: git checkout
uses: actions/checkout@v2

- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: '${{ env.GO_VERSION }}'

- name: run check
run: make build

########################
# lint code
########################
lint:
name: lint code
runs-on: ubuntu-latest
steps:
- name: git checkout
uses: actions/checkout@v2
with:
# The same as "git fetch --unshallow" but also works when running the
# action locally with "act".
fetch-depth: 0

- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: '${{ env.GO_VERSION }}'

- name: lint
run: make lint

########################
# run unit tests
########################
unit-test:
name: run unit tests
runs-on: ubuntu-latest
strategy:
# Allow other tests in the matrix to continue if one fails.
fail-fast: false
matrix:
unit_type:
- unit-cover
- unit-race
steps:
- name: git checkout
uses: actions/checkout@v2

- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: '${{ env.GO_VERSION }}'

- name: run ${{ matrix.unit_type }}
run: make ${{ matrix.unit_type }}

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
if: matrix.unit_type == 'unit-cover'
with:
path-to-profile: coverage.txt
parallel: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ vendor/
breakpoints.txt

# coverage output
profile.cov
coverage.txt
50 changes: 50 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
run:
# timeout for analysis
deadline: 10m

linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
maligned:
suggest-new: true

linters:
enable-all: true
disable:
# Global variables are used in many places throughout the code base.
- gochecknoglobals

# Some lines are over 80 characters on purpose and we don't want to make them
# even longer by marking them as 'nolint'.
- lll

# We have long functions, especially in tests. Moving or renaming those would
# trigger funlen problems that we may not want to solve at that time.
- funlen

# Disable for now as we haven't yet tuned the sensitivity to our codebase
# yet. Enabling by default for example, would also force new contributors to
# potentially extensively refactor code, when they want to smaller change to
# land.
- gocyclo

# Init functions are used by loggers throughout the codebase.
- gochecknoinits

issues:
exclude-rules:
# Exclude gosec from running for tests so that tests with weak randomness
# (math/rand) will pass the linter.
- path: _test\.go
linters:
- gosec
- errcheck
- dupl

# Instances of table driven tests that don't pre-allocate shouldn't
# trigger the linter.
- prealloc
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

127 changes: 127 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
PKG := github.com/ltcsuite/neutrino

BTCD_PKG := github.com/ltcsuite/ltcd
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports

GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc

LINT_COMMIT := v1.18.0
GOACC_COMMIT := v0.2.6

DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOTEST := GO111MODULE=on go test

GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'
GOLIST_COVER := $$(go list -deps $(PKG)/... | grep '$(PKG)')
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")

BTCD_COMMIT := $(shell cat go.mod | \
grep $(BTCD_PKG) | \
head -n1 | \
awk -F " " '{ print $$2 }' | \
awk -F "/" '{ print $$1 }')

RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1

# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
LINT_WORKERS = --concurrency=$(workers)
endif

LINT = $(LINT_BIN) run -v $(LINT_WORKERS)

GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef

default: build

all: build check

# ============
# DEPENDENCIES
# ============

btcd:
@$(call print, "Installing btcd.")
$(DEPGET) $(BTCD_PKG)@$(BTCD_COMMIT)

$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)

$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)

goimports:
@$(call print, "Installing goimports.")
$(DEPGET) $(GOIMPORTS_PKG)

# ============
# INSTALLATION
# ============

build:
@$(call print, "Compiling neutrino.")
$(GOBUILD) $(PKG)/...

# =======
# TESTING
# =======

check: unit

unit: btcd
@$(call print, "Running unit tests.")
$(GOLIST) | $(XARGS) env $(GOTEST)

unit-cover: btcd $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) $(GOLIST_COVER)

unit-race: btcd
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race

# =========
# UTILITIES
# =========

fmt: goimports
@$(call print, "Fixing imports.")
goimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)

lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)

clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt

.PHONY: all \
btcd \
default \
build \
check \
unit \
unit-cover \
unit-race \
fmt \
lint \
clean
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ The light client synchronizes only block headers and a chain of compact block fi
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.

### Queries
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.
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/ltcsuite/lnd). These are described below.

#### Rescan
`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/btcsuite/btcd/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.
`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/ltcsuite/ltcd/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.

#### GetUtxo
`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.
Expand Down
Loading

0 comments on commit 765a6a3

Please sign in to comment.