Skip to content

Commit

Permalink
Merge branch 'btcsuite:master' into refactor/parsefloat
Browse files Browse the repository at this point in the history
  • Loading branch information
lilasxie authored Jun 2, 2024
2 parents 8987efb + d2d286f commit b2a28e8
Show file tree
Hide file tree
Showing 203 changed files with 9,682 additions and 1,772 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ btcutil/psbt/coverage.txt

# vim
*.swp
*.swo
/.vim

# Binaries produced by "make build"
/addblock
/btcctl
/btcd
/findcheckpoint
/gencerts
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ Changes in 0.8.0-beta (Sun May 25 2014)
recent reference client changes
(https://github.com/conformal/btcd/issues/100)
- Raise the maximum signature script size to support standard 15-of-15
multi-signature pay-to-sript-hash transactions with compressed pubkeys
multi-signature pay-to-script-hash transactions with compressed pubkeys
to remain compatible with the reference client
(https://github.com/conformal/btcd/issues/128)
- Reduce max bytes allowed for a standard nulldata transaction to 40 for
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# docker build . -t yourregistry/btcd
#
# You can use the following command to buid an arm64v8 container:
# You can use the following command to build an arm64v8 container:
#
# docker build . -t yourregistry/btcd --build-arg ARCH=arm64v8
#
Expand All @@ -24,7 +24,6 @@ ARG ARCH=amd64
FROM golang@sha256:c80567372be0d486766593cc722d3401038e2f150a0f6c5c719caa63afb4026a AS build-container

ARG ARCH
ENV GO111MODULE=on

ADD . /app
WORKDIR /app
Expand Down
48 changes: 43 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ GOACC_BIN := $(GO_BIN)/go-acc
LINT_COMMIT := v1.18.0
GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b

DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
DEPGET := cd /tmp && go get -v
GOBUILD := go build -v
GOINSTALL := go install -v
DEV_TAGS := rpctest
GOTEST_DEV = GO111MODULE=on go test -v -tags=$(DEV_TAGS)
GOTEST := GO111MODULE=on go test -v
GOTEST_DEV = go test -v -tags=$(DEV_TAGS)
GOTEST := go test -v

GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")

Expand All @@ -39,8 +39,10 @@ define print
echo $(GREEN)$1$(NC)
endef

#? default: Run `make build`
default: build

#? all: Run `make build` and `make check`
all: build check

# ============
Expand All @@ -55,6 +57,7 @@ $(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)

#? goimports: Install goimports
goimports:
@$(call print, "Installing goimports.")
$(DEPGET) $(GOIMPORTS_PKG)
Expand All @@ -63,6 +66,7 @@ goimports:
# INSTALLATION
# ============

#? build: Build all binaries, place them in project directory
build:
@$(call print, "Building all binaries")
$(GOBUILD) $(PKG)
Expand All @@ -71,19 +75,37 @@ build:
$(GOBUILD) $(PKG)/cmd/findcheckpoint
$(GOBUILD) $(PKG)/cmd/addblock

#? install: Install all binaries, place them in $GOPATH/bin
install:
@$(call print, "Installing all binaries")
$(GOINSTALL) $(PKG)
$(GOINSTALL) $(PKG)/cmd/btcctl
$(GOINSTALL) $(PKG)/cmd/gencerts
$(GOINSTALL) $(PKG)/cmd/findcheckpoint
$(GOINSTALL) $(PKG)/cmd/addblock

#? release-install: Install btcd and btcctl release binaries, place them in $GOPATH/bin
release-install:
@$(call print, "Installing btcd and btcctl release binaries")
env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG)
env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG)/cmd/btcctl

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

#? check: Run `make unit`
check: unit

#? unit: Run unit tests
unit:
@$(call print, "Running unit tests.")
$(GOTEST_DEV) ./... -test.timeout=20m
cd btcec; $(GOTEST_DEV) ./... -test.timeout=20m
cd btcutil; $(GOTEST_DEV) ./... -test.timeout=20m
cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m

#? unit-cover: Run unit coverage tests
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) ./...
Expand All @@ -96,6 +118,7 @@ unit-cover: $(GOACC_BIN)

cd btcutil/psbt; $(GOACC_BIN) ./...

#? unit-race: Run unit race tests
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
Expand All @@ -107,19 +130,27 @@ unit-race:
# UTILITIES
# =========

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

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

#? clean: Clean source
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt

#? tidy-module: Run 'go mod tidy' for all modules
tidy-module:
echo "Running 'go mod tidy' for all modules"
scripts/tidy_modules.sh

.PHONY: all \
default \
Expand All @@ -131,3 +162,10 @@ clean:
fmt \
lint \
clean

#? help: Get more info on make commands
help: Makefile
@echo " Choose a command run in btcd:"
@sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /'

.PHONY: help
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ recommended that `GOPATH` is set to a directory in your home directory such as

```bash
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ GO111MODULE=on go install -v . ./cmd/...
$ go install -v . ./cmd/...
```

- btcd (and utilities) will now be installed in ```$GOPATH/bin```. If you did
Expand All @@ -79,7 +79,7 @@ $ GO111MODULE=on go install -v . ./cmd/...
```bash
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ git pull
$ GO111MODULE=on go install -v . ./cmd/...
$ go install -v . ./cmd/...
```

## Getting Started
Expand Down
15 changes: 15 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Security Policy

## Supported Versions

The last major `btcd` release is to be considered the current support version.
Given an issue severe enough, a backport will be issued either to the prior
major release or the set of releases considered utilized enough.

## Reporting a Vulnerability

To report security issues, send an email to security@lightning.engineering
(this list isn't to be used for support).

The following key can be used to communicate sensitive information: `91FE 464C
D751 01DA 6B6B AB60 555C 6465 E5BC B3AF`.
34 changes: 25 additions & 9 deletions addrmgr/addrmanager_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package addrmgr

import (
"io/ioutil"
"math/rand"
"net"
"os"
Expand All @@ -12,7 +11,7 @@ import (
)

// randAddr generates a *wire.NetAddressV2 backed by a random IPv4/IPv6
// address.
// address. Some of the returned addresses may not be routable.
func randAddr(t *testing.T) *wire.NetAddressV2 {
t.Helper()

Expand Down Expand Up @@ -40,6 +39,23 @@ func randAddr(t *testing.T) *wire.NetAddressV2 {
)
}

// routableRandAddr generates a *wire.NetAddressV2 backed by a random IPv4/IPv6
// address that is always routable.
func routableRandAddr(t *testing.T) *wire.NetAddressV2 {
t.Helper()

var addr *wire.NetAddressV2

// If the address is not routable, try again.
routable := false
for !routable {
addr = randAddr(t)
routable = IsRoutable(addr)
}

return addr
}

// assertAddr ensures that the two addresses match. The timestamp is not
// checked as it does not affect uniquely identifying a specific address.
func assertAddr(t *testing.T, got, expected *wire.NetAddressV2) {
Expand Down Expand Up @@ -91,7 +107,7 @@ func TestAddrManagerSerialization(t *testing.T) {

// We'll start by creating our address manager backed by a temporary
// directory.
tempDir, err := ioutil.TempDir("", "addrmgr")
tempDir, err := os.MkdirTemp("", "addrmgr")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
Expand All @@ -104,9 +120,9 @@ func TestAddrManagerSerialization(t *testing.T) {

expectedAddrs := make(map[string]*wire.NetAddressV2, numAddrs)
for i := 0; i < numAddrs; i++ {
addr := randAddr(t)
addr := routableRandAddr(t)
expectedAddrs[NetAddressKey(addr)] = addr
addrMgr.AddAddress(addr, randAddr(t))
addrMgr.AddAddress(addr, routableRandAddr(t))
}

// Now that the addresses have been added, we should be able to retrieve
Expand All @@ -131,7 +147,7 @@ func TestAddrManagerV1ToV2(t *testing.T) {

// We'll start by creating our address manager backed by a temporary
// directory.
tempDir, err := ioutil.TempDir("", "addrmgr")
tempDir, err := os.MkdirTemp("", "addrmgr")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
Expand All @@ -149,9 +165,9 @@ func TestAddrManagerV1ToV2(t *testing.T) {

expectedAddrs := make(map[string]*wire.NetAddressV2, numAddrs)
for i := 0; i < numAddrs; i++ {
addr := randAddr(t)
addr := routableRandAddr(t)
expectedAddrs[NetAddressKey(addr)] = addr
addrMgr.AddAddress(addr, randAddr(t))
addrMgr.AddAddress(addr, routableRandAddr(t))
}

// Then, we'll persist these addresses to disk and restart the address
Expand All @@ -168,7 +184,7 @@ func TestAddrManagerV1ToV2(t *testing.T) {
addrMgr.loadPeers()
addrs := addrMgr.getAddresses()
if len(addrs) != len(expectedAddrs) {
t.Fatalf("expected to find %d adddresses, found %d",
t.Fatalf("expected to find %d addresses, found %d",
len(expectedAddrs), len(addrs))
}
for _, addr := range addrs {
Expand Down
8 changes: 5 additions & 3 deletions blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags)
// Notify the caller that the new block was accepted into the block
// chain. The caller would typically want to react by relaying the
// inventory to other peers.
b.chainLock.Unlock()
b.sendNotification(NTBlockAccepted, block)
b.chainLock.Lock()
func() {
b.chainLock.Unlock()
defer b.chainLock.Lock()
b.sendNotification(NTBlockAccepted, block)
}()

return isMainChain, nil
}
13 changes: 13 additions & 0 deletions blockchain/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ func BenchmarkUtxoFetchSlices(b *testing.B) {
}
}
}

func BenchmarkAncestor(b *testing.B) {
height := 1 << 19
blockNodes := chainedNodes(nil, height)

b.ResetTimer()
for i := 0; i < b.N; i++ {
blockNodes[len(blockNodes)-1].Ancestor(0)
for j := 0; j <= 19; j++ {
blockNodes[len(blockNodes)-1].Ancestor(1 << j)
}
}
}
Loading

0 comments on commit b2a28e8

Please sign in to comment.