An alternative full node implementation of LBRY's blockchain written in Go (golang)
Find a file
Dave Collins 144822d4bf Remove BlockHeader.TxnCount field.
This commit removes the TxnCount field from the BlockHeader type and
updates the tests accordingly.  Note that this change does not affect the
actual wire protocol encoding in any way.

The reason the field has been removed is it really doesn't belong there
even though the wire protocol wiki entry on the official bitcoin wiki
implies it does.  The implication is an artifact from the way the
reference implementation serializes headers (MsgHeaders) messages.  It
includes the transaction count, which is naturally always 0 for headers,
along with every header.  However, in reality, a block header does not
include the transaction count.  This can be evidenced by looking at how a
block hash is calculated.  It is only up to and including the Nonce field
(a total of 80 bytes).

From an API standpoint, having the field as part of the BlockHeader type
results in several odd cases.

For example, the transaction count for MsgBlocks (the only place that
actually has a real transaction count since MsgHeaders does not) is
available by taking the len of the Transactions slice.  As such, having
the extra field in the BlockHeader is really a useless field that could
potentially get out of sync and cause the encode to fail.

Another example is related to deserializing a block header from the
database in order to serve it in response to a getheaders (MsgGetheaders)
request.  If a block header is assumed to have the transaction count as a
part of it, then derserializing a block header not only consumes more than
the 80 bytes that actually comprise the header as stated above, but you
then need to change the transaction count to 0 before sending the headers
(MsgHeaders) message.  So, not only are you reading and deserializing more
bytes than needed, but worse, you generally have to make a copy of it so
you can change the transaction count without busting cached headers.

This is part 1 of #13.
2014-01-18 20:53:20 -06:00
.gitignore Initial commit. 2013-05-08 14:16:41 -05:00
.travis.yml Configure TravisCI to pull pkgs needed for tests. 2013-12-10 16:13:08 -06:00
bench_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
blockheader.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
blockheader_test.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
common.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
common_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
cov_report.sh Update gocov path in comments to correct path. 2013-05-10 15:58:05 -05:00
doc.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
error.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fakeconn_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fakemessage_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fixedIO_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
genesis.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
genesis_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
internal_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
invvect.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
invvect_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
legacy.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
LICENSE Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
message.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
message_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgaddr.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgaddr_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgalert.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgalert_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgblock.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
msgblock_test.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
msggetaddr.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetaddr_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetblocks.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetblocks_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetdata.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetdata_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetheaders.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetheaders_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgheaders.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
msgheaders_test.go Remove BlockHeader.TxnCount field. 2014-01-18 20:53:20 -06:00
msginv.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msginv_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgmempool.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgmempool_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgnotfound.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgnotfound_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgping.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgping_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgpong.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgpong_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgtx.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgtx_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgverack.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgverack_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgversion.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgversion_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
netaddress.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
netaddress_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
protocol.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
protocol_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
README.md Add support for TravisCI. 2013-12-09 05:41:54 -06:00
shahash.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
shahash_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
test_coverage.txt Add tests for new size hint functions. 2014-01-08 17:43:18 -06:00

btcwire

[Build Status] (https://travis-ci.org/conformal/btcwire)

Package btcwire implements the bitcoin wire protocol. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality. See test_coverage.txt for the gocov coverage report. Alternatively, if you are running a POSIX OS, you can run the cov_report.sh script for a real-time report. Package btcwire is licensed under the liberal ISC license.

There is an associated blog post about the release of this package here.

This package is one of the core packages from btcd, an alternative full-node implementation of bitcoin which is under active development by Conformal. Although it was primarily written for btcd, this package has intentionally been designed so it can be used as a standalone package for any projects needing to interface with bitcoin peers at the wire protocol level.

Documentation

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here: http://godoc.org/github.com/conformal/btcwire

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/conformal/btcwire

Installation

$ go get github.com/conformal/btcwire

Bitcoin Message Overview

The bitcoin protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which bitcoin network it is a part of, its type, how big it is, and a checksum to verify validity. All encoding and decoding of message headers is handled by this package.

To accomplish this, there is a generic interface for bitcoin messages named Message which allows messages of any type to be read, written, or passed around through channels, functions, etc. In addition, concrete implementations of most of the currently supported bitcoin messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the wire using bitcoin encoding are handled so the caller doesn't have to concern themselves with the specifics.

Reading Messages Example

In order to unmarshal bitcoin messages from the wire, use the ReadMessage function. It accepts any io.Reader, but typically this will be a net.Conn to a remote node running a bitcoin peer. Example syntax is:

	// Use the most recent protocol version supported by the package and the
	// main bitcoin network.
	pver := btcwire.ProtocolVersion
	btcnet := btcwire.MainNet

	// Reads and validates the next bitcoin message from conn using the
	// protocol version pver and the bitcoin network btcnet.  The returns
	// are a btcwire.Message, a []byte which contains the unmarshalled
	// raw payload, and a possible error.
	msg, rawPayload, err := btcwire.ReadMessage(conn, pver, btcnet)
	if err != nil {
		// Log and handle the error
	}

See the package documentation for details on determining the message type.

Writing Messages Example

In order to marshal bitcoin messages to the wire, use the WriteMessage function. It accepts any io.Writer, but typically this will be a net.Conn to a remote node running a bitcoin peer. Example syntax to request addresses from a remote peer is:

	// Use the most recent protocol version supported by the package and the
	// main bitcoin network.
	pver := btcwire.ProtocolVersion
	btcnet := btcwire.MainNet

	// Create a new getaddr bitcoin message.
	msg := btcwire.NewMsgGetAddr()

	// Writes a bitcoin message msg to conn using the protocol version
	// pver, and the bitcoin network btcnet.  The return is a possible
	// error.
	err := btcwire.WriteMessage(conn, msg, pver, btcnet)
	if err != nil {
		// Log and handle the error
	}

TODO

  • Implement functions for BIP 0014
  • Implement alert message decoding/encoding
  • Implement bloom filter messages (filterload, filteradd, filterclear, merkleblock) as defined in BIP 0037

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btcwire is licensed under the liberal ISC License.