This change begins the work of bringing committed filters to the network consensus daemon. Committed filters are designed to enable light wallets without many of the privacy issues associated with server-side bloom filtering. The new gcs package provides the primitives for creating and matching against Golomb-coded sets (GCS) filters while the blockcf package provides creation of filters and filter entries for data structures found in blocks. The wire package has been updated to define a new protocol version and service flag for advertising CF support and includes types for the following new messages: cfheaders, cfilter, cftypes, getcfheaders, getcfilter, getcftypes. The peer package and server implementation have been updated to include support for the new protocol version and messages. Filters are created using a collision probability of 2^-20 and are saved to a new optional database index when running with committed filter support enabled (the default). At first startup, if support is not disabled, the index will be created and populated with filters and filter headers for all preexisting blocks, and new filters will be recorded for processed blocks. Multiple filter types are supported. The regular filter commits to output scripts and previous outpoints that any non-voting wallet will require access to. Scripts and previous outpoints that can only be spent by votes and revocations are not committed to the filter. The extended filter is a supplementary filter which commits to all transaction hashes and script data pushes from the input scripts of non-coinbase regular and ticket purchase transactions. Creating these filters is based on the algorithm defined by BIP0158 but is modified to only commit "regular" data in stake transactions to prevent committed filters from being used to create SPV voting wallets. |
||
|---|---|---|
| .. | ||
| bench_test.go | ||
| blockheader_test.go | ||
| blockheader.go | ||
| common_test.go | ||
| common.go | ||
| doc.go | ||
| error.go | ||
| fakeconn_test.go | ||
| fakemessage_test.go | ||
| fixedIO_test.go | ||
| invvect_test.go | ||
| invvect.go | ||
| message_test.go | ||
| message.go | ||
| msgaddr_test.go | ||
| msgaddr.go | ||
| msgblock_test.go | ||
| msgblock.go | ||
| msgcfheaders.go | ||
| msgcfilter.go | ||
| msgcftypes.go | ||
| msgfeefilter_test.go | ||
| msgfeefilter.go | ||
| msgfilteradd_test.go | ||
| msgfilteradd.go | ||
| msgfilterclear_test.go | ||
| msgfilterclear.go | ||
| msgfilterload_test.go | ||
| msgfilterload.go | ||
| msggetaddr_test.go | ||
| msggetaddr.go | ||
| msggetblocks_test.go | ||
| msggetblocks.go | ||
| msggetcfheaders.go | ||
| msggetcfilter.go | ||
| msggetcftypes.go | ||
| msggetdata_test.go | ||
| msggetdata.go | ||
| msggetheaders_test.go | ||
| msggetheaders.go | ||
| msggetminingstate.go | ||
| msgheaders_test.go | ||
| msgheaders.go | ||
| msginv_test.go | ||
| msginv.go | ||
| msgmempool_test.go | ||
| msgmempool.go | ||
| msgmerkleblock_test.go | ||
| msgmerkleblock.go | ||
| msgminingstate_test.go | ||
| msgminingstate.go | ||
| msgnotfound_test.go | ||
| msgnotfound.go | ||
| msgping_test.go | ||
| msgping.go | ||
| msgpong_test.go | ||
| msgpong.go | ||
| msgreject_test.go | ||
| msgreject.go | ||
| msgsendheaders_test.go | ||
| msgsendheaders.go | ||
| msgtx_test.go | ||
| msgtx.go | ||
| msgverack_test.go | ||
| msgverack.go | ||
| msgversion_test.go | ||
| msgversion.go | ||
| netaddress_test.go | ||
| netaddress.go | ||
| protocol_test.go | ||
| protocol.go | ||
| README.md | ||
wire
Package wire implements the Decred wire protocol. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality.
This package has intentionally been designed so it can be used as a standalone package for any projects needing to interface with Decred peers at the wire protocol level.
Installation and Updating
$ go get -u github.com/decred/dcrd/wire
Decred Message Overview
The Decred protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which decred 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 Decred 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 Decred messages are provided. For these
supported messages, all of the details of marshalling and unmarshalling to and
from the wire using Decred encoding are handled so the caller doesn't have to
concern themselves with the specifics.
Reading Messages Example
In order to unmarshal Decred 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 Decred peer. Example syntax is:
// Use the most recent protocol version supported by the package and the
// main Decred network.
pver := wire.ProtocolVersion
dcrnet := wire.MainNet
// Reads and validates the next Decred message from conn using the
// protocol version pver and the Decred network dcrnet. The returns
// are a wire.Message, a []byte which contains the unmarshalled
// raw payload, and a possible error.
msg, rawPayload, err := wire.ReadMessage(conn, pver, dcrnet)
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 Decred 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 Decred peer. Example syntax to request addresses
from a remote peer is:
// Use the most recent protocol version supported by the package and the
// main Decred network.
pver := wire.ProtocolVersion
dcrnet := wire.MainNet
// Create a new getaddr Decred message.
msg := wire.NewMsgGetAddr()
// Writes a Decred message msg to conn using the protocol version
// pver, and the Decred network dcrnet. The return is a possible
// error.
err := wire.WriteMessage(conn, msg, pver, dcrnet)
if err != nil {
// Log and handle the error
}
License
Package wire is licensed under the copyfree ISC License.