Skip to content

Commit

Permalink
Update to upstream btcd v0.22.0-beta (#3)
Browse files Browse the repository at this point in the history
* Improve error message about non-active segwit on simnet

I started playing with simnet and was confronted with error message:

```
[ERR] FNDG: Unable to broadcast funding tx for ChannelPoint(<point>:0):
-22: TX rejected: transaction <tx> has witness data, but segwit isn't active yet
```

I wasn't aware of the activation period so I got quite puzzled.
Google helped. But I think the message could mention likely cause.

Newly it optionally prints something like:

```
(The threshold for segwit activation is 300 blocks on simnet, current best height is 113)
```

* btcctl: add regtest mode to btcctl

* build: replace travis-ci with github actions.

test go 1.14
use golangci-lint

* build: update deps

* build: clean linter warnings

* btcjson: change getblock default verbosity to 1

This change makes btcd's getblock command match bitcoind's. Previously
the default verbosity was 0, which caused errors when using the
rpcclient library to connect to a bitcoind node - getblock would
unmarshall incorrectly since it didn't expect a verbosity=1 result when
it did not specify verbosity.

* rpcclient: send legacy GetBlock request for backwards compatibility

Without this, users of this library wouldn't be able to issue GetBlock
requests to nodes which haven't updated to support the latest request
format, namely the use of a single `int` parameter to denote verbosity
instead of two `bool`s.

* rpcclient: Add cookie auth

Based on Hugo Landau's cookie auth implementation for Namecoin's ncdns.

Fixes btcsuite#1054

* rpcclient: Refactor cookie caching

* rpcclient: Try user+pass auth before cookie auth

* rpcclient: Read first line of cookie instead of trimming space

* rpcclient: serialize nil inputs to empty list

* Improve chain state init efficiency

Remove unnecessary slice of all block indexes and
remove DB iteration over all block indexes that
used to determined the size of the slice.

* Add blockchain.NewUtxoEntry() to directly create entries for UtxoViewpoint

The current methods to add to a UtxoViewpoint don't allow for a situation where
we have only UTXO data but not a whole transaction.  This commit allows
contstruction of a UtxoEntry without requiring a full MsgTx.

AddTxOut() and AddTxOuts() both require a whole transaction, including the inputs,
which are only used in order to calculate the txid.  In some situations, such as
with use of the utreexo accumulator, we only have the utxo data but not the
transaction which created it.

For reference, utreexo's initial usage of the blockchain.NewUtxoEntry() function is at
https://github.com/mit-dci/utreexo/pull/135/files#diff-3f7b8f9991ea957f1f4ad9f5a95415f0R96

* Add getchaintxstats JSON-RPC client command

* Add fundrawtransaction RPC call

* Add getbalances RPC client command

* rpcclient: Add GetTransactionWatchOnly method

* peer: knownInventory, sentNonces - use generic lru

While here, also rename and generalize limitMap and apply to
other maps which need to be bounded.

* btcec: Avoid panic in fieldVal.SetByteSlice for large inputs

The implementation has been adapted from the dcrec module in dcrd. The
bug was initially fixed in decred/dcrd@3d9cda1 while transitioning to a
constant time algorithm. A large set of test vectors were subsequently
added in decred/dcrd@8c6b52d.

The function signature has been preserved for backwards compatibility.
This means that returning whether the value has overflowed, and the
corresponding test vectors have not been backported.

This fixes btcsuite#1170 and closes a previous attempt to fix the bug in btcsuite#1178.

* config+service_windows: add flag to disable win service

To run integration tests with btcd on Windows in non-interactive
environments (such as the Travis build with Windows machines), we
need to make sure we can still spawn a child process instead of only a
windows background service.

* updated docs for getblock-verbosity fixes

* Update json_rpc_api.md

Corrections suggested by @onyb btcsuite#1608 (comment)

* netsync: handle notfound messages from peers

backport from decred/dcrd#2253

When a peer sends a notfound message, remove the hash from requested
map.  Also increase notfound ban score and return early if it
disconnects the peer.

* release: update release script path

* release: remove old scripts and update process doc

- remove prep_release.sh and notes.sample
- update license in release.sh
- add notes for maintainers on the release process
- mention CHANGES file modifications

* Update CHANGES file for 0.21.0 release

Also updated changes for 0.20.1, and added a small note about changes
since 0.12.0.

* btcd: bump version to v0.21.0-beta

* blockchain: remove unknown block version warning

* Add rpclient implementation of getdescriptorinfo RPC

* peer: prevent last block height going backwards

This modifies the UpdateLastBlockHeight function to ensure the new
height is after the existing height before updating it in order to
prevent it from going backwards so it properly matches the intent of the
function which is to report the latest known block height for the peer.

Without this change, the value will properly start out at the latest
known block height reported by the peer during version negotiation,
however, it will be set to lower values when syncing from the peer due
to requesting old blocks and blindly updating the height.

It also adds a test to ensure proper functionality.

This is a backport of decred/dcrd#1747

* Fix monetary unit

* rpcserver: add parity with bitcoind for validateaddress

Updated the rpcserver handler for validateaddress JSON-RPC command to
have parity with the bitcoind 0.20.0 interface.

The new fields included are - isscript, iswitness, witness_version, and
witness_program. The scriptPubKey field has been left out since it
requires wallet access.

This update has no impact on the rpcclient.ValidateAddress method,
which uses the btcjson.ValidateAddressWalletResult type for modelling
the response from bitcoind.

* Add getblockfilter JSON-RPC client command

Add type for second getblockfilter param

* Implement signmessagewithprivkey JSON-RPC command

Reuse the Bitcoin message signature header const
also in verifymessage.

* rpcclient: Implement importmulti JSON-RPC client command

* Add Dockerfile to build and run btcd on Docker.

* btcd: fix conversion of int to string failing in Go 1.15

* btcjson,wire: fix invalid use of string(x) to convert byte value

* Major rework on documentation to make it compatible to readthedocs.org

* Added symlink to index.md for github readme preview.

* btcd+netsync: support witness tx and block in notfound msg

* btcec: set curve name in CurveParams

Set curve name(secp256k1) in KoblitzCurve.CurveParams

Fixes btcsuite#1564

* btcec: add a comment indicating where curve name taken from

Related with btcsuite#1565

* rpcclient: support listtransactions RPC with watchonly argument

Co-authored-by: Gert-Jaap Glasbergen <[email protected]>

* blockchain: Remove unnecessary tx hash

* btcjson: update ListTransactionsResult for Bitcoin 0.20.0

This only adds new fields as optional, in order to make this change
backwards compatible with older versions of Bitcoin Core.

* chaincfg: Add RegisterHDKeyID func to populate HD key ID pairs

Currently, the only way to register HD version bytes is by initializing
chaincfg.Params struct, and registering it during package init.
RegisterHDKeyID provides a way to populate custom HD version bytes,
without having to create new chaincfg.Params instances. This is useful
for library packages who want to use non-standard version bytes for
serializing extended keys, such as the ones documented in SLIP-0132.

This function is complementary to HDPrivateKeyToPublicKeyID, which is
used to lookup previously registered key IDs.

* Nullable optional JSON-RPC parameters

Fix command marshalling dropping params following params with nil value.

btcsuite#1591 Allow specifying null parameter value from command line.

* GitHub Actions: Enable Go Race detector and code coverage

This modifies the goclean.sh script to run tests with the
race detector enabled. It also enables code coverage, and
uploads the results to coveralls.io.

Running tests with -race and -cover flags was disabled in
6487ba1 and 6788df7 respectively, due to some limits on
time/goroutines being hit on Travis CI. Since we have
migrated to GitHub Actions, it is desirable to bring them
back.

* rpc: Add getnodeaddresses JSON-RPC support

Add NodeAddresses function to rpcserverConnManager
interface for fetching known node addresses.

* btcjson,rpcclient: add support for PSBT commands to rpcclient

* Added ListSinceBlockMinConfWatchOnly method.

* wire: add proper types for flag field and improve docs

Summary of changes:

- Add a new const TxFlagMarker to indicate the flag prefix byte.
- Add a new TxFlag type to enumerate the flags supported by the
  tx parser.

  This allows us to avoid hardcoded magics, and will make it easier
  to support new flags in future.
- Improve code comments.

Closes btcsuite#1598.

* removed unnecessary GOMAXPROCS function calls

* rpcclient: add deriveaddresses RPC command

* ci: add go 1.15 to tests

* sample-btcd.conf: fix typo

* btcjson: add test for null params in searchrawtransactions

Closes PR btcsuite#1476.

* GetBlockTemplate RPC client implementation (btcsuite#1629)

* GetBlockTemplate RPC client implementation

* Txid added to the getblocktemplate result

* Omitempty for TxID and improved comment for GetBlockTemplate 'rules' field

* rpcclient: implement getaddressinfo command

Fields such as label, and labelspurpose are not included, since they
are deprecated, and will be removed in Bitcoin Core 0.21.

* Fix link to using bootstrap.dat

* rpcclient: implement getwalletinfo command

* rpcserver: add txid to getblocktemplate response

* rpc: add signrawtransactionwithwallet interface

Adds interface for issuing a signrawtransactionwithwallet command.
Note that this does not add functionality for the btcd rpc server
itself, it simply assumes that the RPC client has this ability and gives
an API for interacting with the RPC client.

rpc: add signrawtransactionwithwallet interface

* rpcclient: implement gettxoutsetinfo command

* Unmarshal hashes/second as float in GetMiningInfoResult

* rpcclient: add more wallet commands

Implement backupwallet, dumpwallet, loadwallet and unloadwallet.

* btcjson: add new JSON-RPC errors and document them

* rpcclient: implement createwallet with functional options

* rpcclient: fix documentation typos

* integration: allow setting custom btcd exe path

To allow using a custom btcd executable, we allow specifying a path to a
file. If the path is empty, the harness will fall back to compiling one
from scratch.

* integration: allow overwriting address generator

* integration: allow specifying connection behavior

* integration/rpctest: randomizes port in rpctest.New to reduce collisions

* btcjson+rpcserverhelp: restore bitcoind compatibility

The PR btcsuite#1594 introduced a change that made the order of parameters
relevant, if one of them is nil. This makes it harder to be backward
compatible with the same JSON message if an existing parameter in
bitcoind was re-purposed to have a different meaning.

* simplify s[:] to s where s is a slice

Found using https://go-critic.github.io/overview#unslice-ref

* rpcclient: add ExtraHeaders in ConnConfig

* Add support for receiving sendaddrv2 message from a peer

* fixed broken link

* Add support for arm32v7 in Dockerfile

* Fixes btcsuite#1653

* btcjson: Update fields in GetBlockChainInfoResult

Update the fields of GetBlockChainInfoResult to reflect the current state of
the RPC returned by other full-node implementations.

 * InitialBlockDownload - Node is in Initial Block Download mode if True.
 * SizeOnDisk - The estimated size of the block and undo files on disk.

* txscript: add benchmark for IsUnspendable

 - create benchmarks to measure allocations
 - add test for benchmark input
 - create a low alloc parseScriptTemplate
 - refactor parsing logic for a single opcode

* txscript/hashcache_test: always add inputs during getTxn

TestHashCacheAddContainsHashes flakes fairly regularly when rebasing
PR btcsuite#1684 with:
    txid <txid> wasn't inserted into cache but was found.

With probabilty 1/10^2 there will be no inputs on the transaction. This
reduces the entropy in the txid, and I belive is the primary cause of
the flake.

* txscript/hashcache_test: call rand.Seed once in init

This resolves the more fundamental flake in the unit tests noted in the
prior commit.

Because multiple unit tests call rand.Seed in parallel, it's possible
they can be executed with the same unix timestamp (in seconds). If the
second call happens between generating the hash cache and checking that
the cache doesn't contain a random txn, the random transaction is in
fact a duplicate of one generated earlier since the RNG state was reset.

To remedy, we initialize rand.Seed once in the init function.

* btcec: validate R and S signature components in RecoverCompact

* Add Batch JSON-RPC support (rpc client & server)

* Fix error message returned by EstimateFee

When you provide an argument to EstimateFee(numblocks uint32) that exceeds the estimateFeeDepth (which is set to 25), you get an error message that says "can only estimate fees for up to 100 blocks from now".  The variable used in the if condition and the variable used for creating the error message should be the same.

* docs: update shields

* rpcserver: Fix Error message returned by processRequest

When processRequest can't find a rpc command, standardCmdResult returns
a `btcjson.ErrRPCMethodNotFound` but it gets ignored and a
`btcjson.ErrRPCInvalidRequest` is returned instead.

This makes processRequest return the right error message.

* peer: allow external testing of peer.Peer

The previous use of allowSelfConns prevented this, as users aren't able
to invoke peer.TstAllowSelfConns themselves due to being part of a test
file, which aren't exported at the library level, leading to a
"disconnecting peer connected to self" error upon establishing a mock
connection between two peers. By including the option at the config
level instead (false by default, prevents connections to self) we enable
users of the peer library to properly test the behavior of the peer.Peer
struct externally.

* addrmgr: Use RLock/RUnlock when possible

* build: update btcutil dependency

* rpcclient: fix documentation typo

* btcjson: Updated TxRawResult.Version from int32 to uint32

* wire+chaincfg: add signet params

This commit adds all necessary chain parameters for connecting to the
public signet network.
Reference: bitcoin/bitcoin#18267

* config+params: add signet config option

This commit adds the --signet command line flag (or signet config
option) for starting btcd in signet mode.

* rpcserver: add taproot deployment to getblockchaininfo

* btcctl: add signet param

This commit adds the --signet command line flag to the btcctl utility.

* mining: extract witness commitment add into method

* rpctest: add witness commitment when calling CreateBlock

If we tried to include transactions having witnesses, the block would be
invalid since the witness commitment was not added.

* Don't reference the readme that we don't produce

* chaincfg: fix deployment bit numbers

On signet all previous soft forks and also taproot are always activated,
meaning the version is always 0x20000000 for all blocks. To make sure
they activate properly in `btcd` we therefore need to use the correct
bit to mask the version.
This means that on any custom signet there would need to be 2016 blocks
mined before SegWit or Taproot can be used.

* mempool: add additional test case for inherited RBF replacement

In this commit, we add an additional test case for inherited RBF
replacement. This test case asserts that if a parent is marked as being
replaceable, but the child isn't, then the child can still be replaced
as according to BIP 125 it shoudl _inhreit_ the replaceability of its
parent.

The addition of this test case was prompted by the recently discovered
Bitcoin Core "CVE" [1]. It turns out that bitcoind doesn't properly
implement BIP 125. Namely it fails to allow a child to "inherit"
replaceability if its parent is also replaceable. Our implementation
makes this trait rather explicit due to its recursive implementation.
Kudos to the original implementer @wpaulino for getting this correct.

[1]: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-May/018893.html.

* Update CHANGES file for 0.22.0 release

* btcd: bump version to v0.22.0-beta

* Update release date for v0.22.0-beta in CHANGES file

* remove duplicate command

Co-authored-by: Antonin Hildebrand <[email protected]>
Co-authored-by: Dan Cline <[email protected]>
Co-authored-by: David Hill <[email protected]>
Co-authored-by: Henry <[email protected]>
Co-authored-by: Wilmer Paulino <[email protected]>
Co-authored-by: Olaoluwa Osuntokun <[email protected]>
Co-authored-by: JeremyRand <[email protected]>
Co-authored-by: Torkel Rogstad <[email protected]>
Co-authored-by: Mikael Lindlof <[email protected]>
Co-authored-by: adiabat <[email protected]>
Co-authored-by: Federico Bond <[email protected]>
Co-authored-by: Anirudha Bose <[email protected]>
Co-authored-by: Javed Khan <[email protected]>
Co-authored-by: Anirudha Bose <[email protected]>
Co-authored-by: Oliver Gugger <[email protected]>
Co-authored-by: qqjettkgjzhxmwj <[email protected]>
Co-authored-by: Dan Cline <[email protected]>
Co-authored-by: John C. Vernaleo <[email protected]>
Co-authored-by: wakiyamap <[email protected]>
Co-authored-by: Christian Lehmann <[email protected]>
Co-authored-by: yyforyongyu <[email protected]>
Co-authored-by: Hanjun Kim <[email protected]>
Co-authored-by: Gert-Jaap Glasbergen <[email protected]>
Co-authored-by: Calvin Kim <[email protected]>
Co-authored-by: Andrew Tugarinov <[email protected]>
Co-authored-by: ipriver <[email protected]>
Co-authored-by: Jake Sylvestre <[email protected]>
Co-authored-by: Tristyn <[email protected]>
Co-authored-by: Elliott Minns <[email protected]>
Co-authored-by: Friedger Müffke <[email protected]>
Co-authored-by: David Mazary <[email protected]>
Co-authored-by: Armando Ochoa <[email protected]>
Co-authored-by: Liran Sharir <[email protected]>
Co-authored-by: Iskander Sharipov <[email protected]>
Co-authored-by: 10gic <[email protected]>
Co-authored-by: Yaacov Akiba Slama <[email protected]>
Co-authored-by: ebiiim <[email protected]>
Co-authored-by: Victor Lavaud <[email protected]>
Co-authored-by: Vinayak Borkar <[email protected]>
Co-authored-by: Steven Kreuzer <[email protected]>
Co-authored-by: Conner Fromknecht <[email protected]>
Co-authored-by: Appelberg-s <[email protected]>
Co-authored-by: Gustavo Chain <[email protected]>
Co-authored-by: Aurèle Oulès <[email protected]>
Co-authored-by: Johan T. Halseth <[email protected]>
  • Loading branch information
Show file tree
Hide file tree
Showing 148 changed files with 6,710 additions and 1,585 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.13, 1.14]
go: [1.14, 1.15]
steps:
- name: Set up Go
uses: actions/setup-go@v2
Expand All @@ -25,3 +25,8 @@ jobs:
GO111MODULE: "on"
run: |
sh ./goclean.sh
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ _cgo_export.*
_testmain.go

*.exe

# Code coverage files
profile.tmp
profile.cov
122 changes: 121 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,126 @@ User visible changes for btcd
A full-node bitcoin implementation written in Go
============================================================================

Changes in 0.22.0 (Tue Jun 01 2021)
- Protocol and network-related changes:
- Add support for witness tx and block in notfound msg (#1625)
- Add support for receiving sendaddrv2 messages from a peer (#1670)
- Fix bug in peer package causing last block height to go backwards
(#1606)
- Add chain parameters for connecting to the public Signet network
(#1692, #1718)
- Crypto changes:
- Fix bug causing panic due to bad R and S signature components in
btcec.RecoverCompact (#1691)
- Set the name (secp256k1) in the CurveParams of the S256 curve
(#1565)
- Notable developer-related package changes:
- Remove unknown block version warning in the blockchain package,
due to false positives triggered by AsicBoost (#1463)
- Add chaincfg.RegisterHDKeyID function to populate HD key ID pairs
(#1617)
- Add new method mining.AddWitnessCommitment to add the witness
commitment as an OP_RETURN output within the coinbase transaction.
(#1716)
- RPC changes:
- Support Batch JSON-RPC in rpcclient and server (#1583)
- Add rpcclient method to invoke getdescriptorinfo JSON-RPC command
(#1578)
- Update the rpcserver handler for validateaddress JSON-RPC command to
have parity with the bitcoind 0.20.0 interface (#1613)
- Add rpcclient method to invoke getblockfilter JSON-RPC command
(#1579)
- Add signmessagewithprivkey JSON-RPC command in rpcserver (#1585)
- Add rpcclient method to invoke importmulti JSON-RPC command (#1579)
- Add watchOnly argument in rpcclient method to invoke
listtransactions JSON-RPC command (#1628)
- Update btcjson.ListTransactionsResult for compatibility with Bitcoin
Core 0.20.0 (#1626)
- Support nullable optional JSON-RPC parameters (#1594)
- Add rpcclient and server method to invoke getnodeaddresses JSON-RPC
command (#1590)
- Add rpcclient methods to invoke PSBT JSON-RPC commands (#1596)
- Add rpcclient method to invoke listsinceblock with the
include_watchonly parameter enabled (#1451)
- Add rpcclient method to invoke deriveaddresses JSON-RPC command
(#1631)
- Add rpcclient method to invoke getblocktemplate JSON-RPC command
(#1629)
- Add rpcclient method to invoke getaddressinfo JSON-RPC command
(#1633)
- Add rpcclient method to invoke getwalletinfo JSON-RPC command
(#1638)
- Fix error message in rpcserver when an unknown RPC command is
encountered (#1695)
- Fix error message returned by estimatefee when the number of blocks
exceeds the max depth (#1678)
- Update btcjson.GetBlockChainInfoResult to include new fields in
Bitcoin Core (#1676)
- Add ExtraHeaders in rpcclient.ConnConfig struct (#1669)
- Fix bitcoind compatibility issue with the sendrawtransaction
JSON-RPC command (#1659)
- Add new JSON-RPC errors to btcjson package, and documented them
(#1648)
- Add rpcclient method to invoke createwallet JSON-RPC command
(#1650)
- Add rpcclient methods to invoke backupwallet, dumpwallet, loadwallet
and unloadwallet JSON-RPC commands (#1645)
- Fix unmarshalling error in getmininginfo JSON-RPC command, for valid
integers in scientific notation (#1644)
- Add rpcclient method to invoke gettxoutsetinfo JSON-RPC command
(#1641)
- Add rpcclient method to invoke signrawtransactionwithwallet JSON-RPC
command (#1642)
- Add txid to getblocktemplate response of rpcserver (#1639)
- Fix monetary unit used in createrawtransaction JSON-RPC command in
rpcserver (#1614)
- Add rawtx field to btcjson.GetBlockVerboseTxResult to provide
backwards compatibility with older versions of Bitcoin Core (#1677)
- Misc changes:
- Update btcutil dependency (#1704)
- Add Dockerfile to build and run btcd on Docker (#1465)
- Rework documentation and publish on https://btcd.readthedocs.io (#1468)
- Add support for Go 1.15 (#1619)
- Add Go 1.14 as the minimum supported version of Golang (#1621)
- Contributors (alphabetical order):
- 10gic
- Andrew Tugarinov
- Anirudha Bose
- Appelberg-s
- Armando Ochoa
- Aurèle Oulès
- Calvin Kim
- Christian Lehmann
- Conner Fromknecht
- Dan Cline
- David Mazary
- Elliott Minns
- Federico Bond
- Friedger Müffke
- Gustavo Chain
- Hanjun Kim
- Henry Fisher
- Iskander Sharipov
- Jake Sylvestre
- Johan T. Halseth
- John C. Vernaleo
- Liran Sharir
- Mikael Lindlof
- Olaoluwa Osuntokun
- Oliver Gugger
- Rjected
- Steven Kreuzer
- Torkel Rogstad
- Tristyn
- Victor Lavaud
- Vinayak Borkar
- Wilmer Paulino
- Yaacov Akiba Slama
- ebiiim
- ipriver
- wakiyamap
- yyforyongyu

Changes in 0.21.0 (Thu Aug 27 2020)
- Network-related changes:
- Handle notfound messages from peers in netsync package (#1603)
Expand All @@ -26,7 +146,7 @@ Changes in 0.21.0 (Thu Aug 27 2020)
- Fix panic in fieldVal.SetByteSlice when called with large values, and
improve the method to be 35% faster (#1602)
- btcctl changes:
- Added -regtest mode to btcctl (#1556)
- Add -regtest mode to btcctl (#1556)
- Misc changes:
- Fix a bug due to a deadlock in connmgr's dynamic ban scoring (#1509)
- Add blockchain.NewUtxoEntry() to directly create entries for
Expand Down
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This Dockerfile builds btcd from source and creates a small (55 MB) docker container based on alpine linux.
#
# Clone this repository and run the following command to build and tag a fresh btcd amd64 container:
#
# docker build . -t yourregistry/btcd
#
# You can use the following command to buid an arm64v8 container:
#
# docker build . -t yourregistry/btcd --build-arg ARCH=arm64v8
#
# For more information how to use this docker image visit:
# https://github.com/btcsuite/btcd/tree/master/docs
#
# 8333 Mainnet Bitcoin peer-to-peer port
# 8334 Mainet RPC port

ARG ARCH=amd64

FROM golang:1.14-alpine3.12 AS build-container

ARG ARCH
ENV GO111MODULE=on

ADD . /app
WORKDIR /app
RUN set -ex \
&& if [ "${ARCH}" = "amd64" ]; then export GOARCH=amd64; fi \
&& if [ "${ARCH}" = "arm32v7" ]; then export GOARCH=arm; fi \
&& if [ "${ARCH}" = "arm64v8" ]; then export GOARCH=arm64; fi \
&& echo "Compiling for $GOARCH" \
&& go install -v . ./cmd/...

FROM $ARCH/alpine:3.12

COPY --from=build-container /go/bin /bin

VOLUME ["/root/.btcd"]

EXPOSE 8333 8334

ENTRYPOINT ["btcd"]
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ btcd
====

[![Build Status](https://github.com/btcsuite/btcd/workflows/Build%20and%20Test/badge.svg)](https://github.com/btcsuite/btcd/actions)
[![Coverage Status](https://coveralls.io/repos/github/btcsuite/btcd/badge.svg?branch=master)](https://coveralls.io/github/btcsuite/btcd?branch=master)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/btcsuite/btcd)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/btcsuite/btcd)

btcd is an alternative full node bitcoin implementation written in Go (golang).

Expand All @@ -26,7 +27,7 @@ transactions based on miner requirements ("standard" transactions).

One key difference between btcd and Bitcoin Core is that btcd does *NOT* include
wallet functionality and this was a very intentional design decision. See the
blog entry [here](https://blog.conformal.com/btcd-not-your-moms-bitcoin-daemon)
blog entry [here](https://web.archive.org/web/20171125143919/https://blog.conformal.com/btcd-not-your-moms-bitcoin-daemon)
for more details. This means you can't actually make or receive payments
directly with btcd. That functionality is provided by the
[btcwallet](https://github.com/btcsuite/btcwallet) and
Expand All @@ -35,12 +36,10 @@ which are both under active development.

## Requirements

[Go](http://golang.org) 1.12 or newer.
[Go](http://golang.org) 1.14 or newer.

## Installation

#### Windows - MSI Available

https://github.com/btcsuite/btcd/releases

#### Linux/BSD/MacOSX/POSIX - Build from Source
Expand Down Expand Up @@ -73,10 +72,6 @@ $ GO111MODULE=on go install -v . ./cmd/...

## Updating

#### Windows

Install a newer MSI

#### Linux/BSD/MacOSX/POSIX - Build from Source

- Run the following commands to update btcd, all dependencies, and install it:
Expand All @@ -93,10 +88,6 @@ btcd has several configuration options available to tweak how it runs, but all
of the basic operations described in the intro section work with zero
configuration.

#### Windows (Installed from MSI)

Launch btcd from your Start menu.

#### Linux/BSD/POSIX/Source

```bash
Expand Down
14 changes: 7 additions & 7 deletions addrmgr/addrmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// AddrManager provides a concurrency safe address manager for caching potential
// peers on the bitcoin network.
type AddrManager struct {
mtx sync.Mutex
mtx sync.RWMutex
peersFile string
lookupFunc func(string) ([]net.IP, error)
rand *rand.Rand
Expand Down Expand Up @@ -645,17 +645,17 @@ func (a *AddrManager) numAddresses() int {

// NumAddresses returns the number of addresses known to the address manager.
func (a *AddrManager) NumAddresses() int {
a.mtx.Lock()
defer a.mtx.Unlock()
a.mtx.RLock()
defer a.mtx.RUnlock()

return a.numAddresses()
}

// NeedMoreAddresses returns whether or not the address manager needs more
// addresses.
func (a *AddrManager) NeedMoreAddresses() bool {
a.mtx.Lock()
defer a.mtx.Unlock()
a.mtx.RLock()
defer a.mtx.RUnlock()

return a.numAddresses() < needAddressThreshold
}
Expand Down Expand Up @@ -685,8 +685,8 @@ func (a *AddrManager) AddressCache() []*wire.NetAddress {
// getAddresses returns all of the addresses currently found within the
// manager's address cache.
func (a *AddrManager) getAddresses() []*wire.NetAddress {
a.mtx.Lock()
defer a.mtx.Unlock()
a.mtx.RLock()
defer a.mtx.RUnlock()

addrIndexLen := len(a.addrIndex)
if addrIndexLen == 0 {
Expand Down
10 changes: 5 additions & 5 deletions blockchain/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
blockchain
==========

[![Build Status](http://img.shields.io/travis/btcsuite/btcd.svg)](https://travis-ci.org/btcsuite/btcd)
[![Build Status](https://github.com/btcsuite/btcd/workflows/Build%20and%20Test/badge.svg)](https://github.com/btcsuite/btcd/actions)
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/btcsuite/btcd/blockchain)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/btcsuite/btcd/blockchain)

Package blockchain implements bitcoin block handling and chain selection rules.
The test coverage is currently only around 60%, but will be increasing over
Expand Down Expand Up @@ -61,18 +61,18 @@ is by no means exhaustive:

## Examples

* [ProcessBlock Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BlockChain-ProcessBlock)
* [ProcessBlock Example](https://pkg.go.dev/github.com/btcsuite/btcd/blockchain#example-BlockChain-ProcessBlock)
Demonstrates how to create a new chain instance and use ProcessBlock to
attempt to add a block to the chain. This example intentionally
attempts to insert a duplicate genesis block to illustrate how an invalid
block is handled.

* [CompactToBig Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-CompactToBig)
* [CompactToBig Example](https://pkg.go.dev/github.com/btcsuite/btcd/blockchain#example-CompactToBig)
Demonstrates how to convert the compact "bits" in a block header which
represent the target difficulty to a big integer and display it using the
typical hex notation.

* [BigToCompact Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BigToCompact)
* [BigToCompact Example](https://pkg.go.dev/github.com/btcsuite/btcd/blockchain#example-BigToCompact)
Demonstrates how to convert a target difficulty into the
compact "bits" in a block header which represent that target difficulty.

Expand Down
15 changes: 2 additions & 13 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ type BlockChain struct {
//
// unknownRulesWarned refers to warnings due to unknown rules being
// activated.
//
// unknownVersionsWarned refers to warnings due to unknown versions
// being mined.
unknownRulesWarned bool
unknownVersionsWarned bool
unknownRulesWarned bool

// The notifications field stores a slice of callbacks to be executed on
// certain blockchain events.
Expand Down Expand Up @@ -574,20 +570,13 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
"spent transaction out information")
}

// No warnings about unknown rules or versions until the chain is
// current.
// No warnings about unknown rules until the chain is current.
if b.isCurrent() {
// Warn if any unknown new rules are either about to activate or
// have already been activated.
if err := b.warnUnknownRuleActivations(node); err != nil {
return err
}

// Warn if a high enough percentage of the last blocks have
// unexpected versions.
if err := b.warnUnknownVersions(node); err != nil {
return err
}
}

// Write any block status changes to DB before updating best state.
Expand Down
4 changes: 2 additions & 2 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func dbFetchVersion(dbTx database.Tx, key []byte) uint32 {
return 0
}

return byteOrder.Uint32(serialized[:])
return byteOrder.Uint32(serialized)
}

// dbPutVersion uses an existing database transaction to update the provided
Expand Down Expand Up @@ -943,7 +943,7 @@ func serializeBestChainState(state bestChainState) []byte {
byteOrder.PutUint32(serializedData[offset:], workSumBytesLen)
offset += 4
copy(serializedData[offset:], workSumBytes)
return serializedData[:]
return serializedData
}

// deserializeBestChainState deserializes the passed serialized best chain
Expand Down
Loading

0 comments on commit 950e8b3

Please sign in to comment.