ci: gofmt with go 1.19
Go 1.19 introduces various updates to gofmt.
This commit is contained in:
parent
66c8567a27
commit
e323751218
49 changed files with 685 additions and 647 deletions
|
@ -5,7 +5,7 @@
|
||||||
/*
|
/*
|
||||||
Package addrmgr implements concurrency safe Bitcoin address manager.
|
Package addrmgr implements concurrency safe Bitcoin address manager.
|
||||||
|
|
||||||
Address Manager Overview
|
# Address Manager Overview
|
||||||
|
|
||||||
In order maintain the peer-to-peer Bitcoin network, there needs to be a source
|
In order maintain the peer-to-peer Bitcoin network, there needs to be a source
|
||||||
of addresses to connect to as nodes come and go. The Bitcoin protocol provides
|
of addresses to connect to as nodes come and go. The Bitcoin protocol provides
|
||||||
|
|
|
@ -37,8 +37,9 @@ const (
|
||||||
// from the block being located.
|
// from the block being located.
|
||||||
//
|
//
|
||||||
// For example, assume a block chain with a side chain as depicted below:
|
// For example, assume a block chain with a side chain as depicted below:
|
||||||
// genesis -> 1 -> 2 -> ... -> 15 -> 16 -> 17 -> 18
|
//
|
||||||
// \-> 16a -> 17a
|
// genesis -> 1 -> 2 -> ... -> 15 -> 16 -> 17 -> 18
|
||||||
|
// \-> 16a -> 17a
|
||||||
//
|
//
|
||||||
// The block locator for block 17a would be the hashes of blocks:
|
// The block locator for block 17a would be the hashes of blocks:
|
||||||
// [17a 16a 15 14 13 12 11 10 9 8 7 6 4 genesis]
|
// [17a 16a 15 14 13 12 11 10 9 8 7 6 4 genesis]
|
||||||
|
@ -488,7 +489,7 @@ func (b *BlockChain) calcSequenceLock(node *blockNode, tx *btcutil.Tx, utxoView
|
||||||
// LockTimeToSequence converts the passed relative locktime to a sequence
|
// LockTimeToSequence converts the passed relative locktime to a sequence
|
||||||
// number in accordance to BIP-68.
|
// number in accordance to BIP-68.
|
||||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||||
// * (Compatibility)
|
// - (Compatibility)
|
||||||
func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||||
// If we're expressing the relative lock time in blocks, then the
|
// If we're expressing the relative lock time in blocks, then the
|
||||||
// corresponding sequence number is simply the desired input age.
|
// corresponding sequence number is simply the desired input age.
|
||||||
|
@ -1107,8 +1108,8 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
|
||||||
// a reorganization to become the main chain).
|
// a reorganization to become the main chain).
|
||||||
//
|
//
|
||||||
// The flags modify the behavior of this function as follows:
|
// The flags modify the behavior of this function as follows:
|
||||||
// - BFFastAdd: Avoids several expensive transaction validation operations.
|
// - BFFastAdd: Avoids several expensive transaction validation operations.
|
||||||
// This is useful when using checkpoints.
|
// This is useful when using checkpoints.
|
||||||
//
|
//
|
||||||
// This function MUST be called with the chain state lock held (for writes).
|
// This function MUST be called with the chain state lock held (for writes).
|
||||||
func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, flags BehaviorFlags) (bool, error) {
|
func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, flags BehaviorFlags) (bool, error) {
|
||||||
|
@ -1249,8 +1250,8 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fla
|
||||||
// isCurrent returns whether or not the chain believes it is current. Several
|
// isCurrent returns whether or not the chain believes it is current. Several
|
||||||
// factors are used to guess, but the key factors that allow the chain to
|
// factors are used to guess, but the key factors that allow the chain to
|
||||||
// believe it is current are:
|
// believe it is current are:
|
||||||
// - Latest block height is after the latest checkpoint (if enabled)
|
// - Latest block height is after the latest checkpoint (if enabled)
|
||||||
// - Latest block has a timestamp newer than ~6 hours ago (as LBRY block time is one fourth of bitcoin)
|
// - Latest block has a timestamp newer than ~6 hours ago (as LBRY block time is one fourth of bitcoin)
|
||||||
//
|
//
|
||||||
// This function MUST be called with the chain state lock held (for reads).
|
// This function MUST be called with the chain state lock held (for reads).
|
||||||
func (b *BlockChain) isCurrent() bool {
|
func (b *BlockChain) isCurrent() bool {
|
||||||
|
@ -1273,8 +1274,8 @@ func (b *BlockChain) isCurrent() bool {
|
||||||
// IsCurrent returns whether or not the chain believes it is current. Several
|
// IsCurrent returns whether or not the chain believes it is current. Several
|
||||||
// factors are used to guess, but the key factors that allow the chain to
|
// factors are used to guess, but the key factors that allow the chain to
|
||||||
// believe it is current are:
|
// believe it is current are:
|
||||||
// - Latest block height is after the latest checkpoint (if enabled)
|
// - Latest block height is after the latest checkpoint (if enabled)
|
||||||
// - Latest block has a timestamp newer than 24 hours ago
|
// - Latest block has a timestamp newer than 24 hours ago
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (b *BlockChain) IsCurrent() bool {
|
func (b *BlockChain) IsCurrent() bool {
|
||||||
|
@ -1557,11 +1558,11 @@ func (b *BlockChain) IntervalBlockHashes(endHash *chainhash.Hash, interval int,
|
||||||
//
|
//
|
||||||
// In addition, there are two special cases:
|
// In addition, there are two special cases:
|
||||||
//
|
//
|
||||||
// - When no locators are provided, the stop hash is treated as a request for
|
// - When no locators are provided, the stop hash is treated as a request for
|
||||||
// that block, so it will either return the node associated with the stop hash
|
// that block, so it will either return the node associated with the stop hash
|
||||||
// if it is known, or nil if it is unknown
|
// if it is known, or nil if it is unknown
|
||||||
// - When locators are provided, but none of them are known, nodes starting
|
// - When locators are provided, but none of them are known, nodes starting
|
||||||
// after the genesis block will be returned
|
// after the genesis block will be returned
|
||||||
//
|
//
|
||||||
// This is primarily a helper function for the locateBlocks and locateHeaders
|
// This is primarily a helper function for the locateBlocks and locateHeaders
|
||||||
// functions.
|
// functions.
|
||||||
|
@ -1645,11 +1646,11 @@ func (b *BlockChain) locateBlocks(locator BlockLocator, hashStop *chainhash.Hash
|
||||||
//
|
//
|
||||||
// In addition, there are two special cases:
|
// In addition, there are two special cases:
|
||||||
//
|
//
|
||||||
// - When no locators are provided, the stop hash is treated as a request for
|
// - When no locators are provided, the stop hash is treated as a request for
|
||||||
// that block, so it will either return the stop hash itself if it is known,
|
// that block, so it will either return the stop hash itself if it is known,
|
||||||
// or nil if it is unknown
|
// or nil if it is unknown
|
||||||
// - When locators are provided, but none of them are known, hashes starting
|
// - When locators are provided, but none of them are known, hashes starting
|
||||||
// after the genesis block will be returned
|
// after the genesis block will be returned
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
|
func (b *BlockChain) LocateBlocks(locator BlockLocator, hashStop *chainhash.Hash, maxHashes uint32) []chainhash.Hash {
|
||||||
|
@ -1690,11 +1691,11 @@ func (b *BlockChain) locateHeaders(locator BlockLocator, hashStop *chainhash.Has
|
||||||
//
|
//
|
||||||
// In addition, there are two special cases:
|
// In addition, there are two special cases:
|
||||||
//
|
//
|
||||||
// - When no locators are provided, the stop hash is treated as a request for
|
// - When no locators are provided, the stop hash is treated as a request for
|
||||||
// that header, so it will either return the header for the stop hash itself
|
// that header, so it will either return the header for the stop hash itself
|
||||||
// if it is known, or nil if it is unknown
|
// if it is known, or nil if it is unknown
|
||||||
// - When locators are provided, but none of them are known, headers starting
|
// - When locators are provided, but none of them are known, headers starting
|
||||||
// after the genesis block will be returned
|
// after the genesis block will be returned
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (b *BlockChain) LocateHeaders(locator BlockLocator, hashStop *chainhash.Hash) []wire.BlockHeader {
|
func (b *BlockChain) LocateHeaders(locator BlockLocator, hashStop *chainhash.Hash) []wire.BlockHeader {
|
||||||
|
|
|
@ -36,11 +36,13 @@ func fastLog2Floor(n uint32) uint8 {
|
||||||
// for comparing chains.
|
// for comparing chains.
|
||||||
//
|
//
|
||||||
// For example, assume a block chain with a side chain as depicted below:
|
// For example, assume a block chain with a side chain as depicted below:
|
||||||
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
//
|
||||||
// \-> 4a -> 5a -> 6a
|
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
||||||
|
// \-> 4a -> 5a -> 6a
|
||||||
//
|
//
|
||||||
// The chain view for the branch ending in 6a consists of:
|
// The chain view for the branch ending in 6a consists of:
|
||||||
// genesis -> 1 -> 2 -> 3 -> 4a -> 5a -> 6a
|
//
|
||||||
|
// genesis -> 1 -> 2 -> 3 -> 4a -> 5a -> 6a
|
||||||
type chainView struct {
|
type chainView struct {
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
nodes []*blockNode
|
nodes []*blockNode
|
||||||
|
@ -258,12 +260,14 @@ func (c *chainView) next(node *blockNode) *blockNode {
|
||||||
// view.
|
// view.
|
||||||
//
|
//
|
||||||
// For example, assume a block chain with a side chain as depicted below:
|
// For example, assume a block chain with a side chain as depicted below:
|
||||||
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
//
|
||||||
// \-> 4a -> 5a -> 6a
|
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
||||||
|
// \-> 4a -> 5a -> 6a
|
||||||
//
|
//
|
||||||
// Further, assume the view is for the longer chain depicted above. That is to
|
// Further, assume the view is for the longer chain depicted above. That is to
|
||||||
// say it consists of:
|
// say it consists of:
|
||||||
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
//
|
||||||
|
// genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
|
||||||
//
|
//
|
||||||
// Invoking this function with block node 5 would return block node 6 while
|
// Invoking this function with block node 5 would return block node 6 while
|
||||||
// invoking it with block node 5a would return nil since that node is not part
|
// invoking it with block node 5a would return nil since that node is not part
|
||||||
|
@ -321,12 +325,14 @@ func (c *chainView) findFork(node *blockNode) *blockNode {
|
||||||
// the chain view. It will return nil if there is no common block.
|
// the chain view. It will return nil if there is no common block.
|
||||||
//
|
//
|
||||||
// For example, assume a block chain with a side chain as depicted below:
|
// For example, assume a block chain with a side chain as depicted below:
|
||||||
// genesis -> 1 -> 2 -> ... -> 5 -> 6 -> 7 -> 8
|
//
|
||||||
// \-> 6a -> 7a
|
// genesis -> 1 -> 2 -> ... -> 5 -> 6 -> 7 -> 8
|
||||||
|
// \-> 6a -> 7a
|
||||||
//
|
//
|
||||||
// Further, assume the view is for the longer chain depicted above. That is to
|
// Further, assume the view is for the longer chain depicted above. That is to
|
||||||
// say it consists of:
|
// say it consists of:
|
||||||
// genesis -> 1 -> 2 -> ... -> 5 -> 6 -> 7 -> 8.
|
//
|
||||||
|
// genesis -> 1 -> 2 -> ... -> 5 -> 6 -> 7 -> 8.
|
||||||
//
|
//
|
||||||
// Invoking this function with block node 7a would return block node 5 while
|
// Invoking this function with block node 7a would return block node 5 while
|
||||||
// invoking it with block node 7 would return itself since it is already part of
|
// invoking it with block node 7 would return itself since it is already part of
|
||||||
|
|
|
@ -185,14 +185,14 @@ func isNonstandardTransaction(tx *btcutil.Tx) bool {
|
||||||
// checkpoint candidate.
|
// checkpoint candidate.
|
||||||
//
|
//
|
||||||
// The factors used to determine a good checkpoint are:
|
// The factors used to determine a good checkpoint are:
|
||||||
// - The block must be in the main chain
|
// - The block must be in the main chain
|
||||||
// - The block must be at least 'CheckpointConfirmations' blocks prior to the
|
// - The block must be at least 'CheckpointConfirmations' blocks prior to the
|
||||||
// current end of the main chain
|
// current end of the main chain
|
||||||
// - The timestamps for the blocks before and after the checkpoint must have
|
// - The timestamps for the blocks before and after the checkpoint must have
|
||||||
// timestamps which are also before and after the checkpoint, respectively
|
// timestamps which are also before and after the checkpoint, respectively
|
||||||
// (due to the median time allowance this is not always the case)
|
// (due to the median time allowance this is not always the case)
|
||||||
// - The block must not contain any strange transaction such as those with
|
// - The block must not contain any strange transaction such as those with
|
||||||
// nonstandard scripts
|
// nonstandard scripts
|
||||||
//
|
//
|
||||||
// The intent is that candidates are reviewed by a developer to make the final
|
// The intent is that candidates are reviewed by a developer to make the final
|
||||||
// decision and then manually added to the list of checkpoints for a network.
|
// decision and then manually added to the list of checkpoints for a network.
|
||||||
|
|
|
@ -42,18 +42,21 @@ func HashToBig(hash *chainhash.Hash) *big.Int {
|
||||||
// Like IEEE754 floating point, there are three basic components: the sign,
|
// Like IEEE754 floating point, there are three basic components: the sign,
|
||||||
// the exponent, and the mantissa. They are broken out as follows:
|
// the exponent, and the mantissa. They are broken out as follows:
|
||||||
//
|
//
|
||||||
// * the most significant 8 bits represent the unsigned base 256 exponent
|
// - the most significant 8 bits represent the unsigned base 256 exponent
|
||||||
// * bit 23 (the 24th bit) represents the sign bit
|
|
||||||
// * the least significant 23 bits represent the mantissa
|
|
||||||
//
|
//
|
||||||
// -------------------------------------------------
|
// - bit 23 (the 24th bit) represents the sign bit
|
||||||
// | Exponent | Sign | Mantissa |
|
//
|
||||||
// -------------------------------------------------
|
// - the least significant 23 bits represent the mantissa
|
||||||
// | 8 bits [31-24] | 1 bit [23] | 23 bits [22-00] |
|
//
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
// | Exponent | Sign | Mantissa |
|
||||||
|
// -------------------------------------------------
|
||||||
|
// | 8 bits [31-24] | 1 bit [23] | 23 bits [22-00] |
|
||||||
|
// -------------------------------------------------
|
||||||
//
|
//
|
||||||
// The formula to calculate N is:
|
// The formula to calculate N is:
|
||||||
// N = (-1^sign) * mantissa * 256^(exponent-3)
|
//
|
||||||
|
// N = (-1^sign) * mantissa * 256^(exponent-3)
|
||||||
//
|
//
|
||||||
// This compact form is only used in bitcoin to encode unsigned 256-bit numbers
|
// This compact form is only used in bitcoin to encode unsigned 256-bit numbers
|
||||||
// which represent difficulty targets, thus there really is not a need for a
|
// which represent difficulty targets, thus there really is not a need for a
|
||||||
|
|
|
@ -26,42 +26,42 @@ caller a high level of flexibility in how they want to react to certain events
|
||||||
such as orphan blocks which need their parents requested and newly connected
|
such as orphan blocks which need their parents requested and newly connected
|
||||||
main chain blocks which might result in wallet updates.
|
main chain blocks which might result in wallet updates.
|
||||||
|
|
||||||
Bitcoin Chain Processing Overview
|
# Bitcoin Chain Processing Overview
|
||||||
|
|
||||||
Before a block is allowed into the block chain, it must go through an intensive
|
Before a block is allowed into the block chain, it must go through an intensive
|
||||||
series of validation rules. The following list serves as a general outline of
|
series of validation rules. The following list serves as a general outline of
|
||||||
those rules to provide some intuition into what is going on under the hood, but
|
those rules to provide some intuition into what is going on under the hood, but
|
||||||
is by no means exhaustive:
|
is by no means exhaustive:
|
||||||
|
|
||||||
- Reject duplicate blocks
|
- Reject duplicate blocks
|
||||||
- Perform a series of sanity checks on the block and its transactions such as
|
- Perform a series of sanity checks on the block and its transactions such as
|
||||||
verifying proof of work, timestamps, number and character of transactions,
|
verifying proof of work, timestamps, number and character of transactions,
|
||||||
transaction amounts, script complexity, and merkle root calculations
|
transaction amounts, script complexity, and merkle root calculations
|
||||||
- Compare the block against predetermined checkpoints for expected timestamps
|
- Compare the block against predetermined checkpoints for expected timestamps
|
||||||
and difficulty based on elapsed time since the checkpoint
|
and difficulty based on elapsed time since the checkpoint
|
||||||
- Save the most recent orphan blocks for a limited time in case their parent
|
- Save the most recent orphan blocks for a limited time in case their parent
|
||||||
blocks become available
|
blocks become available
|
||||||
- Stop processing if the block is an orphan as the rest of the processing
|
- Stop processing if the block is an orphan as the rest of the processing
|
||||||
depends on the block's position within the block chain
|
depends on the block's position within the block chain
|
||||||
- Perform a series of more thorough checks that depend on the block's position
|
- Perform a series of more thorough checks that depend on the block's position
|
||||||
within the block chain such as verifying block difficulties adhere to
|
within the block chain such as verifying block difficulties adhere to
|
||||||
difficulty retarget rules, timestamps are after the median of the last
|
difficulty retarget rules, timestamps are after the median of the last
|
||||||
several blocks, all transactions are finalized, checkpoint blocks match, and
|
several blocks, all transactions are finalized, checkpoint blocks match, and
|
||||||
block versions are in line with the previous blocks
|
block versions are in line with the previous blocks
|
||||||
- Determine how the block fits into the chain and perform different actions
|
- Determine how the block fits into the chain and perform different actions
|
||||||
accordingly in order to ensure any side chains which have higher difficulty
|
accordingly in order to ensure any side chains which have higher difficulty
|
||||||
than the main chain become the new main chain
|
than the main chain become the new main chain
|
||||||
- When a block is being connected to the main chain (either through
|
- When a block is being connected to the main chain (either through
|
||||||
reorganization of a side chain to the main chain or just extending the
|
reorganization of a side chain to the main chain or just extending the
|
||||||
main chain), perform further checks on the block's transactions such as
|
main chain), perform further checks on the block's transactions such as
|
||||||
verifying transaction duplicates, script complexity for the combination of
|
verifying transaction duplicates, script complexity for the combination of
|
||||||
connected scripts, coinbase maturity, double spends, and connected
|
connected scripts, coinbase maturity, double spends, and connected
|
||||||
transaction values
|
transaction values
|
||||||
- Run the transaction scripts to verify the spender is allowed to spend the
|
- Run the transaction scripts to verify the spender is allowed to spend the
|
||||||
coins
|
coins
|
||||||
- Insert the block into the block database
|
- Insert the block into the block database
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
Errors returned by this package are either the raw errors provided by underlying
|
Errors returned by this package are either the raw errors provided by underlying
|
||||||
calls or of type blockchain.RuleError. This allows the caller to differentiate
|
calls or of type blockchain.RuleError. This allows the caller to differentiate
|
||||||
|
@ -70,12 +70,12 @@ violations through type assertions. In addition, callers can programmatically
|
||||||
determine the specific rule violation by examining the ErrorCode field of the
|
determine the specific rule violation by examining the ErrorCode field of the
|
||||||
type asserted blockchain.RuleError.
|
type asserted blockchain.RuleError.
|
||||||
|
|
||||||
Bitcoin Improvement Proposals
|
# Bitcoin Improvement Proposals
|
||||||
|
|
||||||
This package includes spec changes outlined by the following BIPs:
|
This package includes spec changes outlined by the following BIPs:
|
||||||
|
|
||||||
BIP0016 (https://en.bitcoin.it/wiki/BIP_0016)
|
BIP0016 (https://en.bitcoin.it/wiki/BIP_0016)
|
||||||
BIP0030 (https://en.bitcoin.it/wiki/BIP_0030)
|
BIP0030 (https://en.bitcoin.it/wiki/BIP_0030)
|
||||||
BIP0034 (https://en.bitcoin.it/wiki/BIP_0034)
|
BIP0034 (https://en.bitcoin.it/wiki/BIP_0034)
|
||||||
*/
|
*/
|
||||||
package blockchain
|
package blockchain
|
||||||
|
|
|
@ -464,9 +464,9 @@ func createSpendTxForTx(tx *wire.MsgTx, fee btcutil.Amount) *wire.MsgTx {
|
||||||
// - A coinbase that pays the required subsidy to an OP_TRUE script
|
// - A coinbase that pays the required subsidy to an OP_TRUE script
|
||||||
// - When a spendable output is provided:
|
// - When a spendable output is provided:
|
||||||
// - A transaction that spends from the provided output the following outputs:
|
// - A transaction that spends from the provided output the following outputs:
|
||||||
// - One that pays the inputs amount minus 1 atom to an OP_TRUE script
|
// - One that pays the inputs amount minus 1 atom to an OP_TRUE script
|
||||||
// - One that contains an OP_RETURN output with a random uint64 in order to
|
// - One that contains an OP_RETURN output with a random uint64 in order to
|
||||||
// ensure the transaction has a unique hash
|
// ensure the transaction has a unique hash
|
||||||
//
|
//
|
||||||
// Additionally, if one or more munge functions are specified, they will be
|
// Additionally, if one or more munge functions are specified, they will be
|
||||||
// invoked with the block prior to solving it. This provides callers with the
|
// invoked with the block prior to solving it. This provides callers with the
|
||||||
|
|
|
@ -27,8 +27,9 @@ type blockProgressLogger struct {
|
||||||
|
|
||||||
// newBlockProgressLogger returns a new block progress logger.
|
// newBlockProgressLogger returns a new block progress logger.
|
||||||
// The progress message is templated as follows:
|
// The progress message is templated as follows:
|
||||||
// {progressAction} {numProcessed} {blocks|block} in the last {timePeriod}
|
//
|
||||||
// ({numTxs}, height {lastBlockHeight}, {lastBlockTimeStamp})
|
// {progressAction} {numProcessed} {blocks|block} in the last {timePeriod}
|
||||||
|
// ({numTxs}, height {lastBlockHeight}, {lastBlockTimeStamp})
|
||||||
func newBlockProgressLogger(progressMessage string, logger btclog.Logger) *blockProgressLogger {
|
func newBlockProgressLogger(progressMessage string, logger btclog.Logger) *blockProgressLogger {
|
||||||
return &blockProgressLogger{
|
return &blockProgressLogger{
|
||||||
lastBlockLogTime: time.Now(),
|
lastBlockLogTime: time.Now(),
|
||||||
|
|
|
@ -86,7 +86,7 @@ func HashMerkleBranches(left *chainhash.Hash, right *chainhash.Hash) *chainhash.
|
||||||
//
|
//
|
||||||
// The above stored as a linear array is as follows:
|
// The above stored as a linear array is as follows:
|
||||||
//
|
//
|
||||||
// [h1 h2 h3 h4 h12 h34 root]
|
// [h1 h2 h3 h4 h12 h34 root]
|
||||||
//
|
//
|
||||||
// As the above shows, the merkle root is always the last element in the array.
|
// As the above shows, the merkle root is always the last element in the array.
|
||||||
//
|
//
|
||||||
|
|
|
@ -50,9 +50,9 @@ func (n NotificationType) String() string {
|
||||||
// Notification defines notification that is sent to the caller via the callback
|
// Notification defines notification that is sent to the caller via the callback
|
||||||
// function provided during the call to New and consists of a notification type
|
// function provided during the call to New and consists of a notification type
|
||||||
// as well as associated data that depends on the type as follows:
|
// as well as associated data that depends on the type as follows:
|
||||||
// - NTBlockAccepted: *btcutil.Block
|
// - NTBlockAccepted: *btcutil.Block
|
||||||
// - NTBlockConnected: *btcutil.Block
|
// - NTBlockConnected: *btcutil.Block
|
||||||
// - NTBlockDisconnected: *btcutil.Block
|
// - NTBlockDisconnected: *btcutil.Block
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
Type NotificationType
|
Type NotificationType
|
||||||
Data interface{}
|
Data interface{}
|
||||||
|
|
|
@ -232,24 +232,25 @@ func determineMainChainBlocks(blocksMap map[chainhash.Hash]*blockChainContext, t
|
||||||
//
|
//
|
||||||
// The legacy format is as follows:
|
// The legacy format is as follows:
|
||||||
//
|
//
|
||||||
// <version><height><header code><unspentness bitmap>[<compressed txouts>,...]
|
// <version><height><header code><unspentness bitmap>[<compressed txouts>,...]
|
||||||
//
|
//
|
||||||
// Field Type Size
|
// Field Type Size
|
||||||
// version VLQ variable
|
// version VLQ variable
|
||||||
// block height VLQ variable
|
// block height VLQ variable
|
||||||
// header code VLQ variable
|
// header code VLQ variable
|
||||||
// unspentness bitmap []byte variable
|
// unspentness bitmap []byte variable
|
||||||
// compressed txouts
|
// compressed txouts
|
||||||
// compressed amount VLQ variable
|
// compressed amount VLQ variable
|
||||||
// compressed script []byte variable
|
// compressed script []byte variable
|
||||||
//
|
//
|
||||||
// The serialized header code format is:
|
// The serialized header code format is:
|
||||||
// bit 0 - containing transaction is a coinbase
|
//
|
||||||
// bit 1 - output zero is unspent
|
// bit 0 - containing transaction is a coinbase
|
||||||
// bit 2 - output one is unspent
|
// bit 1 - output zero is unspent
|
||||||
// bits 3-x - number of bytes in unspentness bitmap. When both bits 1 and 2
|
// bit 2 - output one is unspent
|
||||||
// are unset, it encodes N-1 since there must be at least one unspent
|
// bits 3-x - number of bytes in unspentness bitmap. When both bits 1 and 2
|
||||||
// output.
|
// are unset, it encodes N-1 since there must be at least one unspent
|
||||||
|
// output.
|
||||||
//
|
//
|
||||||
// The rationale for the header code scheme is as follows:
|
// The rationale for the header code scheme is as follows:
|
||||||
// - Transactions which only pay to a single output and a change output are
|
// - Transactions which only pay to a single output and a change output are
|
||||||
|
@ -269,65 +270,65 @@ func determineMainChainBlocks(blocksMap map[chainhash.Hash]*blockChainContext, t
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// Blk 1, 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
|
// Blk 1, 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
|
||||||
//
|
//
|
||||||
// 010103320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
// 010103320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
|
||||||
// <><><><------------------------------------------------------------------>
|
// <><><><------------------------------------------------------------------>
|
||||||
// | | \--------\ |
|
// | | \--------\ |
|
||||||
// | height | compressed txout 0
|
// | height | compressed txout 0
|
||||||
// version header code
|
// version header code
|
||||||
//
|
//
|
||||||
// - version: 1
|
// - version: 1
|
||||||
// - height: 1
|
// - height: 1
|
||||||
// - header code: 0x03 (coinbase, output zero unspent, 0 bytes of unspentness)
|
// - header code: 0x03 (coinbase, output zero unspent, 0 bytes of unspentness)
|
||||||
// - unspentness: Nothing since it is zero bytes
|
// - unspentness: Nothing since it is zero bytes
|
||||||
// - compressed txout 0:
|
// - compressed txout 0:
|
||||||
// - 0x32: VLQ-encoded compressed amount for 5000000000 (50 BTC)
|
// - 0x32: VLQ-encoded compressed amount for 5000000000 (50 BTC)
|
||||||
// - 0x04: special script type pay-to-pubkey
|
// - 0x04: special script type pay-to-pubkey
|
||||||
// - 0x96...52: x-coordinate of the pubkey
|
// - 0x96...52: x-coordinate of the pubkey
|
||||||
//
|
//
|
||||||
// Example 2:
|
// Example 2:
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// Blk 113931, 4a16969aa4764dd7507fc1de7f0baa4850a246de90c45e59a3207f9a26b5036f
|
// Blk 113931, 4a16969aa4764dd7507fc1de7f0baa4850a246de90c45e59a3207f9a26b5036f
|
||||||
//
|
//
|
||||||
// 0185f90b0a011200e2ccd6ec7c6e2e581349c77e067385fa8236bf8a800900b8025be1b3efc63b0ad48e7f9f10e87544528d58
|
// 0185f90b0a011200e2ccd6ec7c6e2e581349c77e067385fa8236bf8a800900b8025be1b3efc63b0ad48e7f9f10e87544528d58
|
||||||
// <><----><><><------------------------------------------><-------------------------------------------->
|
// <><----><><><------------------------------------------><-------------------------------------------->
|
||||||
// | | | \-------------------\ | |
|
// | | | \-------------------\ | |
|
||||||
// version | \--------\ unspentness | compressed txout 2
|
// version | \--------\ unspentness | compressed txout 2
|
||||||
// height header code compressed txout 0
|
// height header code compressed txout 0
|
||||||
//
|
//
|
||||||
// - version: 1
|
// - version: 1
|
||||||
// - height: 113931
|
// - height: 113931
|
||||||
// - header code: 0x0a (output zero unspent, 1 byte in unspentness bitmap)
|
// - header code: 0x0a (output zero unspent, 1 byte in unspentness bitmap)
|
||||||
// - unspentness: [0x01] (bit 0 is set, so output 0+2 = 2 is unspent)
|
// - unspentness: [0x01] (bit 0 is set, so output 0+2 = 2 is unspent)
|
||||||
// NOTE: It's +2 since the first two outputs are encoded in the header code
|
// NOTE: It's +2 since the first two outputs are encoded in the header code
|
||||||
// - compressed txout 0:
|
// - compressed txout 0:
|
||||||
// - 0x12: VLQ-encoded compressed amount for 20000000 (0.2 BTC)
|
// - 0x12: VLQ-encoded compressed amount for 20000000 (0.2 BTC)
|
||||||
// - 0x00: special script type pay-to-pubkey-hash
|
// - 0x00: special script type pay-to-pubkey-hash
|
||||||
// - 0xe2...8a: pubkey hash
|
// - 0xe2...8a: pubkey hash
|
||||||
// - compressed txout 2:
|
// - compressed txout 2:
|
||||||
// - 0x8009: VLQ-encoded compressed amount for 15000000 (0.15 BTC)
|
// - 0x8009: VLQ-encoded compressed amount for 15000000 (0.15 BTC)
|
||||||
// - 0x00: special script type pay-to-pubkey-hash
|
// - 0x00: special script type pay-to-pubkey-hash
|
||||||
// - 0xb8...58: pubkey hash
|
// - 0xb8...58: pubkey hash
|
||||||
//
|
//
|
||||||
// Example 3:
|
// Example 3:
|
||||||
// From tx in main blockchain:
|
// From tx in main blockchain:
|
||||||
// Blk 338156, 1b02d1c8cfef60a189017b9a420c682cf4a0028175f2f563209e4ff61c8c3620
|
// Blk 338156, 1b02d1c8cfef60a189017b9a420c682cf4a0028175f2f563209e4ff61c8c3620
|
||||||
//
|
//
|
||||||
// 0193d06c100000108ba5b9e763011dd46a006572d820e448e12d2bbb38640bc718e6
|
// 0193d06c100000108ba5b9e763011dd46a006572d820e448e12d2bbb38640bc718e6
|
||||||
// <><----><><----><-------------------------------------------------->
|
// <><----><><----><-------------------------------------------------->
|
||||||
// | | | \-----------------\ |
|
// | | | \-----------------\ |
|
||||||
// version | \--------\ unspentness |
|
// version | \--------\ unspentness |
|
||||||
// height header code compressed txout 22
|
// height header code compressed txout 22
|
||||||
//
|
//
|
||||||
// - version: 1
|
// - version: 1
|
||||||
// - height: 338156
|
// - height: 338156
|
||||||
// - header code: 0x10 (2+1 = 3 bytes in unspentness bitmap)
|
// - header code: 0x10 (2+1 = 3 bytes in unspentness bitmap)
|
||||||
// NOTE: It's +1 since neither bit 1 nor 2 are set, so N-1 is encoded.
|
// NOTE: It's +1 since neither bit 1 nor 2 are set, so N-1 is encoded.
|
||||||
// - unspentness: [0x00 0x00 0x10] (bit 20 is set, so output 20+2 = 22 is unspent)
|
// - unspentness: [0x00 0x00 0x10] (bit 20 is set, so output 20+2 = 22 is unspent)
|
||||||
// NOTE: It's +2 since the first two outputs are encoded in the header code
|
// NOTE: It's +2 since the first two outputs are encoded in the header code
|
||||||
// - compressed txout 22:
|
// - compressed txout 22:
|
||||||
// - 0x8ba5b9e763: VLQ-encoded compressed amount for 366875659 (3.66875659 BTC)
|
// - 0x8ba5b9e763: VLQ-encoded compressed amount for 366875659 (3.66875659 BTC)
|
||||||
// - 0x01: special script type pay-to-script-hash
|
// - 0x01: special script type pay-to-script-hash
|
||||||
// - 0x1d...e6: script hash
|
// - 0x1d...e6: script hash
|
||||||
func deserializeUtxoEntryV0(serialized []byte) (map[uint32]*UtxoEntry, error) {
|
func deserializeUtxoEntryV0(serialized []byte) (map[uint32]*UtxoEntry, error) {
|
||||||
// Deserialize the version.
|
// Deserialize the version.
|
||||||
//
|
//
|
||||||
|
|
|
@ -334,8 +334,8 @@ func CheckTransactionSanity(tx *btcutil.Tx, enforceSoftFork bool) error {
|
||||||
// target difficulty as claimed.
|
// target difficulty as claimed.
|
||||||
//
|
//
|
||||||
// The flags modify the behavior of this function as follows:
|
// The flags modify the behavior of this function as follows:
|
||||||
// - BFNoPoWCheck: The check to ensure the block hash is less than the target
|
// - BFNoPoWCheck: The check to ensure the block hash is less than the target
|
||||||
// difficulty is not performed.
|
// difficulty is not performed.
|
||||||
func checkProofOfWork(header *wire.BlockHeader, powLimit *big.Int, flags BehaviorFlags) error {
|
func checkProofOfWork(header *wire.BlockHeader, powLimit *big.Int, flags BehaviorFlags) error {
|
||||||
// The target difficulty must be larger than zero.
|
// The target difficulty must be larger than zero.
|
||||||
target := CompactToBig(header.Bits)
|
target := CompactToBig(header.Bits)
|
||||||
|
@ -669,8 +669,8 @@ func checkSerializedHeight(coinbaseTx *btcutil.Tx, wantHeight int32) error {
|
||||||
// which depend on its position within the block chain.
|
// which depend on its position within the block chain.
|
||||||
//
|
//
|
||||||
// The flags modify the behavior of this function as follows:
|
// The flags modify the behavior of this function as follows:
|
||||||
// - BFFastAdd: All checks except those involving comparing the header against
|
// - BFFastAdd: All checks except those involving comparing the header against
|
||||||
// the checkpoints are not performed.
|
// the checkpoints are not performed.
|
||||||
//
|
//
|
||||||
// This function MUST be called with the chain state lock held (for writes).
|
// This function MUST be called with the chain state lock held (for writes).
|
||||||
func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, prevNode *blockNode, flags BehaviorFlags) error {
|
func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, prevNode *blockNode, flags BehaviorFlags) error {
|
||||||
|
@ -748,8 +748,8 @@ func (b *BlockChain) checkBlockHeaderContext(header *wire.BlockHeader, prevNode
|
||||||
// on its position within the block chain.
|
// on its position within the block chain.
|
||||||
//
|
//
|
||||||
// The flags modify the behavior of this function as follows:
|
// The flags modify the behavior of this function as follows:
|
||||||
// - BFFastAdd: The transaction are not checked to see if they are finalized
|
// - BFFastAdd: The transaction are not checked to see if they are finalized
|
||||||
// and the somewhat expensive BIP0034 validation is not performed.
|
// and the somewhat expensive BIP0034 validation is not performed.
|
||||||
//
|
//
|
||||||
// The flags are also passed to checkBlockHeaderContext. See its documentation
|
// The flags are also passed to checkBlockHeaderContext. See its documentation
|
||||||
// for how the flags modify its behavior.
|
// for how the flags modify its behavior.
|
||||||
|
|
|
@ -527,7 +527,7 @@ type baseMultTest struct {
|
||||||
x, y string
|
x, y string
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add more test vectors
|
// TODO: add more test vectors
|
||||||
var s256BaseMultTests = []baseMultTest{
|
var s256BaseMultTests = []baseMultTest{
|
||||||
{
|
{
|
||||||
"AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522",
|
"AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522",
|
||||||
|
@ -556,7 +556,7 @@ var s256BaseMultTests = []baseMultTest{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: test different curves as well?
|
// TODO: test different curves as well?
|
||||||
func TestBaseMult(t *testing.T) {
|
func TestBaseMult(t *testing.T) {
|
||||||
s256 := S256()
|
s256 := S256()
|
||||||
for i, e := range s256BaseMultTests {
|
for i, e := range s256BaseMultTests {
|
||||||
|
|
|
@ -125,27 +125,30 @@ var (
|
||||||
// the arithmetic needed for elliptic curve operations.
|
// the arithmetic needed for elliptic curve operations.
|
||||||
//
|
//
|
||||||
// The following depicts the internal representation:
|
// The following depicts the internal representation:
|
||||||
// -----------------------------------------------------------------
|
//
|
||||||
// | n[9] | n[8] | ... | n[0] |
|
// -----------------------------------------------------------------
|
||||||
// | 32 bits available | 32 bits available | ... | 32 bits available |
|
// | n[9] | n[8] | ... | n[0] |
|
||||||
// | 22 bits for value | 26 bits for value | ... | 26 bits for value |
|
// | 32 bits available | 32 bits available | ... | 32 bits available |
|
||||||
// | 10 bits overflow | 6 bits overflow | ... | 6 bits overflow |
|
// | 22 bits for value | 26 bits for value | ... | 26 bits for value |
|
||||||
// | Mult: 2^(26*9) | Mult: 2^(26*8) | ... | Mult: 2^(26*0) |
|
// | 10 bits overflow | 6 bits overflow | ... | 6 bits overflow |
|
||||||
// -----------------------------------------------------------------
|
// | Mult: 2^(26*9) | Mult: 2^(26*8) | ... | Mult: 2^(26*0) |
|
||||||
|
// -----------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// For example, consider the number 2^49 + 1. It would be represented as:
|
// For example, consider the number 2^49 + 1. It would be represented as:
|
||||||
// n[0] = 1
|
//
|
||||||
// n[1] = 2^23
|
// n[0] = 1
|
||||||
// n[2..9] = 0
|
// n[1] = 2^23
|
||||||
|
// n[2..9] = 0
|
||||||
//
|
//
|
||||||
// The full 256-bit value is then calculated by looping i from 9..0 and
|
// The full 256-bit value is then calculated by looping i from 9..0 and
|
||||||
// doing sum(n[i] * 2^(26i)) like so:
|
// doing sum(n[i] * 2^(26i)) like so:
|
||||||
// n[9] * 2^(26*9) = 0 * 2^234 = 0
|
//
|
||||||
// n[8] * 2^(26*8) = 0 * 2^208 = 0
|
// n[9] * 2^(26*9) = 0 * 2^234 = 0
|
||||||
// ...
|
// n[8] * 2^(26*8) = 0 * 2^208 = 0
|
||||||
// n[1] * 2^(26*1) = 2^23 * 2^26 = 2^49
|
// ...
|
||||||
// n[0] * 2^(26*0) = 1 * 2^0 = 1
|
// n[1] * 2^(26*1) = 2^23 * 2^26 = 2^49
|
||||||
// Sum: 0 + 0 + ... + 2^49 + 1 = 2^49 + 1
|
// n[0] * 2^(26*0) = 1 * 2^0 = 1
|
||||||
|
// Sum: 0 + 0 + ... + 2^49 + 1 = 2^49 + 1
|
||||||
type fieldVal struct {
|
type fieldVal struct {
|
||||||
n [10]uint32
|
n [10]uint32
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
/*
|
/*
|
||||||
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.
|
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.
|
||||||
|
|
||||||
Overview
|
# Overview
|
||||||
|
|
||||||
When communicating via the JSON-RPC protocol, all of the commands need to be
|
When communicating via the JSON-RPC protocol, all of the commands need to be
|
||||||
marshalled to and from the the wire in the appropriate format. This package
|
marshalled to and from the the wire in the appropriate format. This package
|
||||||
|
@ -14,7 +14,7 @@ provides data structures and primitives to ease this process.
|
||||||
In addition, it also provides some additional features such as custom command
|
In addition, it also provides some additional features such as custom command
|
||||||
registration, command categorization, and reflection-based help generation.
|
registration, command categorization, and reflection-based help generation.
|
||||||
|
|
||||||
JSON-RPC Protocol Overview
|
# JSON-RPC Protocol Overview
|
||||||
|
|
||||||
This information is not necessary in order to use this package, but it does
|
This information is not necessary in order to use this package, but it does
|
||||||
provide some intuition into what the marshalling and unmarshalling that is
|
provide some intuition into what the marshalling and unmarshalling that is
|
||||||
|
@ -47,39 +47,39 @@ with it) doesn't always follow the spec and will sometimes return an error
|
||||||
string in the result field with a null error for certain commands. However,
|
string in the result field with a null error for certain commands. However,
|
||||||
for the most part, the error field will be set as described on failure.
|
for the most part, the error field will be set as described on failure.
|
||||||
|
|
||||||
Marshalling and Unmarshalling
|
# Marshalling and Unmarshalling
|
||||||
|
|
||||||
Based upon the discussion above, it should be easy to see how the types of this
|
Based upon the discussion above, it should be easy to see how the types of this
|
||||||
package map into the required parts of the protocol
|
package map into the required parts of the protocol
|
||||||
|
|
||||||
- Request Objects (type Request)
|
- Request Objects (type Request)
|
||||||
- Commands (type <Foo>Cmd)
|
- Commands (type <Foo>Cmd)
|
||||||
- Notifications (type <Foo>Ntfn)
|
- Notifications (type <Foo>Ntfn)
|
||||||
- Response Objects (type Response)
|
- Response Objects (type Response)
|
||||||
- Result (type <Foo>Result)
|
- Result (type <Foo>Result)
|
||||||
|
|
||||||
To simplify the marshalling of the requests and responses, the MarshalCmd and
|
To simplify the marshalling of the requests and responses, the MarshalCmd and
|
||||||
MarshalResponse functions are provided. They return the raw bytes ready to be
|
MarshalResponse functions are provided. They return the raw bytes ready to be
|
||||||
sent across the wire.
|
sent across the wire.
|
||||||
|
|
||||||
Unmarshalling a received Request object is a two step process:
|
Unmarshalling a received Request object is a two step process:
|
||||||
1) Unmarshal the raw bytes into a Request struct instance via json.Unmarshal
|
1. Unmarshal the raw bytes into a Request struct instance via json.Unmarshal
|
||||||
2) Use UnmarshalCmd on the Result field of the unmarshalled Request to create
|
2. Use UnmarshalCmd on the Result field of the unmarshalled Request to create
|
||||||
a concrete command or notification instance with all struct fields set
|
a concrete command or notification instance with all struct fields set
|
||||||
accordingly
|
accordingly
|
||||||
|
|
||||||
This approach is used since it provides the caller with access to the additional
|
This approach is used since it provides the caller with access to the additional
|
||||||
fields in the request that are not part of the command such as the ID.
|
fields in the request that are not part of the command such as the ID.
|
||||||
|
|
||||||
Unmarshalling a received Response object is also a two step process:
|
Unmarshalling a received Response object is also a two step process:
|
||||||
1) Unmarhsal the raw bytes into a Response struct instance via json.Unmarshal
|
1. Unmarhsal the raw bytes into a Response struct instance via json.Unmarshal
|
||||||
2) Depending on the ID, unmarshal the Result field of the unmarshalled
|
2. Depending on the ID, unmarshal the Result field of the unmarshalled
|
||||||
Response to create a concrete type instance
|
Response to create a concrete type instance
|
||||||
|
|
||||||
As above, this approach is used since it provides the caller with access to the
|
As above, this approach is used since it provides the caller with access to the
|
||||||
fields in the response such as the ID and Error.
|
fields in the response such as the ID and Error.
|
||||||
|
|
||||||
Command Creation
|
# Command Creation
|
||||||
|
|
||||||
This package provides two approaches for creating a new command. This first,
|
This package provides two approaches for creating a new command. This first,
|
||||||
and preferred, method is to use one of the New<Foo>Cmd functions. This allows
|
and preferred, method is to use one of the New<Foo>Cmd functions. This allows
|
||||||
|
@ -93,7 +93,7 @@ obviously, run-time which means any mistakes won't be found until the code is
|
||||||
actually executed. However, it is quite useful for user-supplied commands
|
actually executed. However, it is quite useful for user-supplied commands
|
||||||
that are intentionally dynamic.
|
that are intentionally dynamic.
|
||||||
|
|
||||||
Custom Command Registration
|
# Custom Command Registration
|
||||||
|
|
||||||
The command handling of this package is built around the concept of registered
|
The command handling of this package is built around the concept of registered
|
||||||
commands. This is true for the wide variety of commands already provided by the
|
commands. This is true for the wide variety of commands already provided by the
|
||||||
|
@ -104,7 +104,7 @@ function for this purpose.
|
||||||
A list of all registered methods can be obtained with the RegisteredCmdMethods
|
A list of all registered methods can be obtained with the RegisteredCmdMethods
|
||||||
function.
|
function.
|
||||||
|
|
||||||
Command Inspection
|
# Command Inspection
|
||||||
|
|
||||||
All registered commands are registered with flags that identify information such
|
All registered commands are registered with flags that identify information such
|
||||||
as whether the command applies to a chain server, wallet server, or is a
|
as whether the command applies to a chain server, wallet server, or is a
|
||||||
|
@ -112,7 +112,7 @@ notification along with the method name to use. These flags can be obtained
|
||||||
with the MethodUsageFlags flags, and the method can be obtained with the
|
with the MethodUsageFlags flags, and the method can be obtained with the
|
||||||
CmdMethod function.
|
CmdMethod function.
|
||||||
|
|
||||||
Help Generation
|
# Help Generation
|
||||||
|
|
||||||
To facilitate providing consistent help to users of the RPC server, this package
|
To facilitate providing consistent help to users of the RPC server, this package
|
||||||
exposes the GenerateHelp and function which uses reflection on registered
|
exposes the GenerateHelp and function which uses reflection on registered
|
||||||
|
@ -122,7 +122,7 @@ generate the final help text.
|
||||||
In addition, the MethodUsageText function is provided to generate consistent
|
In addition, the MethodUsageText function is provided to generate consistent
|
||||||
one-line usage for registered commands and notifications using reflection.
|
one-line usage for registered commands and notifications using reflection.
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
There are 2 distinct type of errors supported by this package:
|
There are 2 distinct type of errors supported by this package:
|
||||||
|
|
||||||
|
|
|
@ -476,11 +476,12 @@ func isValidResultType(kind reflect.Kind) bool {
|
||||||
// an error will use the key in place of the description.
|
// an error will use the key in place of the description.
|
||||||
//
|
//
|
||||||
// The following outlines the required keys:
|
// The following outlines the required keys:
|
||||||
// "<method>--synopsis" Synopsis for the command
|
//
|
||||||
// "<method>-<lowerfieldname>" Description for each command argument
|
// "<method>--synopsis" Synopsis for the command
|
||||||
// "<typename>-<lowerfieldname>" Description for each object field
|
// "<method>-<lowerfieldname>" Description for each command argument
|
||||||
// "<method>--condition<#>" Description for each result condition
|
// "<typename>-<lowerfieldname>" Description for each object field
|
||||||
// "<method>--result<#>" Description for each primitive result num
|
// "<method>--condition<#>" Description for each result condition
|
||||||
|
// "<method>--result<#>" Description for each primitive result num
|
||||||
//
|
//
|
||||||
// Notice that the "special" keys synopsis, condition<#>, and result<#> are
|
// Notice that the "special" keys synopsis, condition<#>, and result<#> are
|
||||||
// preceded by a double dash to ensure they don't conflict with field names.
|
// preceded by a double dash to ensure they don't conflict with field names.
|
||||||
|
@ -492,16 +493,17 @@ func isValidResultType(kind reflect.Kind) bool {
|
||||||
// For example, consider the 'help' command itself. There are two possible
|
// For example, consider the 'help' command itself. There are two possible
|
||||||
// returns depending on the provided parameters. So, the help would be
|
// returns depending on the provided parameters. So, the help would be
|
||||||
// generated by calling the function as follows:
|
// generated by calling the function as follows:
|
||||||
// GenerateHelp("help", descs, (*string)(nil), (*string)(nil)).
|
//
|
||||||
|
// GenerateHelp("help", descs, (*string)(nil), (*string)(nil)).
|
||||||
//
|
//
|
||||||
// The following keys would then be required in the provided descriptions map:
|
// The following keys would then be required in the provided descriptions map:
|
||||||
//
|
//
|
||||||
// "help--synopsis": "Returns a list of all commands or help for ...."
|
// "help--synopsis": "Returns a list of all commands or help for ...."
|
||||||
// "help-command": "The command to retrieve help for",
|
// "help-command": "The command to retrieve help for",
|
||||||
// "help--condition0": "no command provided"
|
// "help--condition0": "no command provided"
|
||||||
// "help--condition1": "command specified"
|
// "help--condition1": "command specified"
|
||||||
// "help--result0": "List of commands"
|
// "help--result0": "List of commands"
|
||||||
// "help--result1": "Help for specified command"
|
// "help--result1": "Help for specified command"
|
||||||
func GenerateHelp(method string, descs map[string]string, resultTypes ...interface{}) (string, error) {
|
func GenerateHelp(method string, descs map[string]string, resultTypes ...interface{}) (string, error) {
|
||||||
// Look up details about the provided method and error out if not
|
// Look up details about the provided method and error out if not
|
||||||
// registered.
|
// registered.
|
||||||
|
|
|
@ -833,7 +833,8 @@ func (s *ScriptPubKey) UnmarshalJSON(data []byte) error {
|
||||||
//
|
//
|
||||||
// Descriptors are typically ranged when specified in the form of generic HD
|
// Descriptors are typically ranged when specified in the form of generic HD
|
||||||
// chain paths.
|
// chain paths.
|
||||||
// Example of a ranged descriptor: pkh(tpub.../*)
|
//
|
||||||
|
// Example of a ranged descriptor: pkh(tpub.../*)
|
||||||
//
|
//
|
||||||
// The value can be an int to specify the end of the range, or the range
|
// The value can be an int to specify the end of the range, or the range
|
||||||
// itself, as []int{begin, end}.
|
// itself, as []int{begin, end}.
|
||||||
|
|
|
@ -47,11 +47,11 @@ type embeddedAddressInfo struct {
|
||||||
// Reference: https://bitcoincore.org/en/doc/0.20.0/rpc/wallet/getaddressinfo
|
// Reference: https://bitcoincore.org/en/doc/0.20.0/rpc/wallet/getaddressinfo
|
||||||
//
|
//
|
||||||
// The GetAddressInfoResult has three segments:
|
// The GetAddressInfoResult has three segments:
|
||||||
// 1. General information about the address.
|
// 1. General information about the address.
|
||||||
// 2. Metadata (Timestamp, HDKeyPath, HDSeedID) and wallet fields
|
// 2. Metadata (Timestamp, HDKeyPath, HDSeedID) and wallet fields
|
||||||
// (IsMine, IsWatchOnly).
|
// (IsMine, IsWatchOnly).
|
||||||
// 3. Information about the embedded address in case of P2SH or P2WSH.
|
// 3. Information about the embedded address in case of P2SH or P2WSH.
|
||||||
// Same structure as (1).
|
// Same structure as (1).
|
||||||
type GetAddressInfoResult struct {
|
type GetAddressInfoResult struct {
|
||||||
// The following fields are identical to embeddedAddressInfo.
|
// The following fields are identical to embeddedAddressInfo.
|
||||||
// However, the utility to generate RPC help message can't handle
|
// However, the utility to generate RPC help message can't handle
|
||||||
|
|
|
@ -39,11 +39,11 @@ func DoubleHashH(b []byte) Hash {
|
||||||
|
|
||||||
// LbryPoWHashH calculates returns the PoW Hash.
|
// LbryPoWHashH calculates returns the PoW Hash.
|
||||||
//
|
//
|
||||||
// doubled := SHA256(SHA256(b))
|
// doubled := SHA256(SHA256(b))
|
||||||
// expanded := SHA512(doubled)
|
// expanded := SHA512(doubled)
|
||||||
// left := RIPEMD160(expanded[0:32])
|
// left := RIPEMD160(expanded[0:32])
|
||||||
// right := RIPEMD160(expanded[32:64])
|
// right := RIPEMD160(expanded[32:64])
|
||||||
// result := SHA256(SHA256(left||right))
|
// result := SHA256(SHA256(left||right))
|
||||||
func LbryPoWHashH(b []byte) Hash {
|
func LbryPoWHashH(b []byte) Hash {
|
||||||
doubled := DoubleHashB(b)
|
doubled := DoubleHashB(b)
|
||||||
expanded := sha512.Sum512(doubled)
|
expanded := sha512.Sum512(doubled)
|
||||||
|
|
|
@ -18,40 +18,40 @@
|
||||||
// When a network parameter is needed, it may then be looked up through this
|
// When a network parameter is needed, it may then be looked up through this
|
||||||
// variable (either directly, or hidden in a library call).
|
// variable (either directly, or hidden in a library call).
|
||||||
//
|
//
|
||||||
// package main
|
// package main
|
||||||
//
|
//
|
||||||
// import (
|
// import (
|
||||||
// "flag"
|
// "flag"
|
||||||
// "fmt"
|
// "fmt"
|
||||||
// "log"
|
// "log"
|
||||||
//
|
//
|
||||||
// btcutil "github.com/lbryio/lbcutil"
|
// btcutil "github.com/lbryio/lbcutil"
|
||||||
// "github.com/lbryio/lbcd/chaincfg"
|
// "github.com/lbryio/lbcd/chaincfg"
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// var testnet = flag.Bool("testnet", false, "operate on the testnet Bitcoin network")
|
// var testnet = flag.Bool("testnet", false, "operate on the testnet Bitcoin network")
|
||||||
//
|
//
|
||||||
// // By default (without -testnet), use mainnet.
|
// // By default (without -testnet), use mainnet.
|
||||||
// var chainParams = &chaincfg.MainNetParams
|
// var chainParams = &chaincfg.MainNetParams
|
||||||
//
|
//
|
||||||
// func main() {
|
// func main() {
|
||||||
// flag.Parse()
|
// flag.Parse()
|
||||||
//
|
//
|
||||||
// // Modify active network parameters if operating on testnet.
|
// // Modify active network parameters if operating on testnet.
|
||||||
// if *testnet {
|
// if *testnet {
|
||||||
// chainParams = &chaincfg.TestNet3Params
|
// chainParams = &chaincfg.TestNet3Params
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // later...
|
// // later...
|
||||||
//
|
//
|
||||||
// // Create and print new payment address, specific to the active network.
|
// // Create and print new payment address, specific to the active network.
|
||||||
// pubKeyHash := make([]byte, 20)
|
// pubKeyHash := make([]byte, 20)
|
||||||
// addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
|
// addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// fmt.Println(addr)
|
// fmt.Println(addr)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// If an application does not use one of the three standard Bitcoin networks,
|
// If an application does not use one of the three standard Bitcoin networks,
|
||||||
// a new Params struct may be created which defines the parameters for the
|
// a new Params struct may be created which defines the parameters for the
|
||||||
|
|
|
@ -794,8 +794,9 @@ func IsBech32SegwitPrefix(prefix string) bool {
|
||||||
// ErrInvalidHDKeyID error will be returned.
|
// ErrInvalidHDKeyID error will be returned.
|
||||||
//
|
//
|
||||||
// Reference:
|
// Reference:
|
||||||
// SLIP-0132 : Registered HD version bytes for BIP-0032
|
//
|
||||||
// https://github.com/satoshilabs/slips/blob/master/slip-0132.md
|
// SLIP-0132 : Registered HD version bytes for BIP-0032
|
||||||
|
// https://github.com/satoshilabs/slips/blob/master/slip-0132.md
|
||||||
func RegisterHDKeyID(hdPublicKeyID []byte, hdPrivateKeyID []byte) error {
|
func RegisterHDKeyID(hdPublicKeyID []byte, hdPrivateKeyID []byte) error {
|
||||||
if len(hdPublicKeyID) != 4 || len(hdPrivateKeyID) != 4 {
|
if len(hdPublicKeyID) != 4 || len(hdPrivateKeyID) != 4 {
|
||||||
return ErrInvalidHDKeyID
|
return ErrInvalidHDKeyID
|
||||||
|
|
|
@ -26,7 +26,8 @@ type claimProgressLogger struct {
|
||||||
|
|
||||||
// newClaimProgressLogger returns a new name progress logger.
|
// newClaimProgressLogger returns a new name progress logger.
|
||||||
// The progress message is templated as follows:
|
// The progress message is templated as follows:
|
||||||
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
|
//
|
||||||
|
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
|
||||||
func newClaimProgressLogger(progressMessage string, logger btclog.Logger) *claimProgressLogger {
|
func newClaimProgressLogger(progressMessage string, logger btclog.Logger) *claimProgressLogger {
|
||||||
return &claimProgressLogger{
|
return &claimProgressLogger{
|
||||||
lastLogNameTime: time.Now(),
|
lastLogNameTime: time.Now(),
|
||||||
|
|
|
@ -17,10 +17,11 @@ func newVertex(hash *chainhash.Hash) *vertex {
|
||||||
// TODO: more professional to use msgpack here?
|
// TODO: more professional to use msgpack here?
|
||||||
|
|
||||||
// nbuf decodes the on-disk format of a node, which has the following form:
|
// nbuf decodes the on-disk format of a node, which has the following form:
|
||||||
// ch(1B) hash(32B)
|
//
|
||||||
// ...
|
// ch(1B) hash(32B)
|
||||||
// ch(1B) hash(32B)
|
// ...
|
||||||
// vhash(32B)
|
// ch(1B) hash(32B)
|
||||||
|
// vhash(32B)
|
||||||
type nbuf []byte
|
type nbuf []byte
|
||||||
|
|
||||||
func (nb nbuf) entries() int {
|
func (nb nbuf) entries() int {
|
||||||
|
|
|
@ -175,10 +175,10 @@ func cleanAndExpandPath(path string) string {
|
||||||
// line options.
|
// line options.
|
||||||
//
|
//
|
||||||
// The configuration proceeds as follows:
|
// The configuration proceeds as follows:
|
||||||
// 1) Start with a default config with sane settings
|
// 1. Start with a default config with sane settings
|
||||||
// 2) Pre-parse the command line to check for an alternative config file
|
// 2. Pre-parse the command line to check for an alternative config file
|
||||||
// 3) Load configuration file overwriting defaults with any specified options
|
// 3. Load configuration file overwriting defaults with any specified options
|
||||||
// 4) Parse CLI options and overwrite/add any specified options
|
// 4. Parse CLI options and overwrite/add any specified options
|
||||||
//
|
//
|
||||||
// The above results in functioning properly without any config settings
|
// The above results in functioning properly without any config settings
|
||||||
// while still allowing the user to override settings with config files and
|
// while still allowing the user to override settings with config files and
|
||||||
|
|
|
@ -409,10 +409,10 @@ func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *fl
|
||||||
// line options.
|
// line options.
|
||||||
//
|
//
|
||||||
// The configuration proceeds as follows:
|
// The configuration proceeds as follows:
|
||||||
// 1) Start with a default config with sane settings
|
// 1. Start with a default config with sane settings
|
||||||
// 2) Pre-parse the command line to check for an alternative config file
|
// 2. Pre-parse the command line to check for an alternative config file
|
||||||
// 3) Load configuration file overwriting defaults with any specified options
|
// 3. Load configuration file overwriting defaults with any specified options
|
||||||
// 4) Parse CLI options and overwrite/add any specified options
|
// 4. Parse CLI options and overwrite/add any specified options
|
||||||
//
|
//
|
||||||
// The above results in lbcd functioning properly without any config settings
|
// The above results in lbcd functioning properly without any config settings
|
||||||
// while still allowing the user to override settings with config files and
|
// while still allowing the user to override settings with config files and
|
||||||
|
|
|
@ -20,7 +20,6 @@ var (
|
||||||
// parameters which are command-line only. These fields are copied line-by-line
|
// parameters which are command-line only. These fields are copied line-by-line
|
||||||
// from "config" struct in "config.go", and the field names, types, and tags must
|
// from "config" struct in "config.go", and the field names, types, and tags must
|
||||||
// match for the test to work.
|
// match for the test to work.
|
||||||
//
|
|
||||||
type configCmdLineOnly struct {
|
type configCmdLineOnly struct {
|
||||||
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
|
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
|
||||||
DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"`
|
DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"`
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
/*
|
/*
|
||||||
Package connmgr implements a generic Bitcoin network connection manager.
|
Package connmgr implements a generic Bitcoin network connection manager.
|
||||||
|
|
||||||
Connection Manager Overview
|
# Connection Manager Overview
|
||||||
|
|
||||||
Connection Manager handles all the general connection concerns such as
|
Connection Manager handles all the general connection concerns such as
|
||||||
maintaining a set number of outbound connections, sourcing peers, banning,
|
maintaining a set number of outbound connections, sourcing peers, banning,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
/*
|
/*
|
||||||
Package database provides a block and metadata storage database.
|
Package database provides a block and metadata storage database.
|
||||||
|
|
||||||
Overview
|
# Overview
|
||||||
|
|
||||||
As of Feb 2016, there are over 400,000 blocks in the Bitcoin block chain and
|
As of Feb 2016, there are over 400,000 blocks in the Bitcoin block chain and
|
||||||
and over 112 million transactions (which turns out to be over 60GB of data).
|
and over 112 million transactions (which turns out to be over 60GB of data).
|
||||||
|
@ -18,15 +18,15 @@ storage, and strict checksums in key areas to ensure data integrity.
|
||||||
|
|
||||||
A quick overview of the features database provides are as follows:
|
A quick overview of the features database provides are as follows:
|
||||||
|
|
||||||
- Key/value metadata store
|
- Key/value metadata store
|
||||||
- Bitcoin block storage
|
- Bitcoin block storage
|
||||||
- Efficient retrieval of block headers and regions (transactions, scripts, etc)
|
- Efficient retrieval of block headers and regions (transactions, scripts, etc)
|
||||||
- Read-only and read-write transactions with both manual and managed modes
|
- Read-only and read-write transactions with both manual and managed modes
|
||||||
- Nested buckets
|
- Nested buckets
|
||||||
- Supports registration of backend databases
|
- Supports registration of backend databases
|
||||||
- Comprehensive test coverage
|
- Comprehensive test coverage
|
||||||
|
|
||||||
Database
|
# Database
|
||||||
|
|
||||||
The main entry point is the DB interface. It exposes functionality for
|
The main entry point is the DB interface. It exposes functionality for
|
||||||
transactional-based access and storage of metadata and block data. It is
|
transactional-based access and storage of metadata and block data. It is
|
||||||
|
@ -43,14 +43,14 @@ The Begin function provides an unmanaged transaction while the View and Update
|
||||||
functions provide a managed transaction. These are described in more detail
|
functions provide a managed transaction. These are described in more detail
|
||||||
below.
|
below.
|
||||||
|
|
||||||
Transactions
|
# Transactions
|
||||||
|
|
||||||
The Tx interface provides facilities for rolling back or committing changes that
|
The Tx interface provides facilities for rolling back or committing changes that
|
||||||
took place while the transaction was active. It also provides the root metadata
|
took place while the transaction was active. It also provides the root metadata
|
||||||
bucket under which all keys, values, and nested buckets are stored. A
|
bucket under which all keys, values, and nested buckets are stored. A
|
||||||
transaction can either be read-only or read-write and managed or unmanaged.
|
transaction can either be read-only or read-write and managed or unmanaged.
|
||||||
|
|
||||||
Managed versus Unmanaged Transactions
|
# Managed versus Unmanaged Transactions
|
||||||
|
|
||||||
A managed transaction is one where the caller provides a function to execute
|
A managed transaction is one where the caller provides a function to execute
|
||||||
within the context of the transaction and the commit or rollback is handled
|
within the context of the transaction and the commit or rollback is handled
|
||||||
|
@ -63,7 +63,7 @@ call Commit or Rollback when they are finished with it. Leaving transactions
|
||||||
open for long periods of time can have several adverse effects, so it is
|
open for long periods of time can have several adverse effects, so it is
|
||||||
recommended that managed transactions are used instead.
|
recommended that managed transactions are used instead.
|
||||||
|
|
||||||
Buckets
|
# Buckets
|
||||||
|
|
||||||
The Bucket interface provides the ability to manipulate key/value pairs and
|
The Bucket interface provides the ability to manipulate key/value pairs and
|
||||||
nested buckets as well as iterate through them.
|
nested buckets as well as iterate through them.
|
||||||
|
@ -73,7 +73,7 @@ CreateBucket, CreateBucketIfNotExists, and DeleteBucket functions work with
|
||||||
buckets. The ForEach function allows the caller to provide a function to be
|
buckets. The ForEach function allows the caller to provide a function to be
|
||||||
called with each key/value pair and nested bucket in the current bucket.
|
called with each key/value pair and nested bucket in the current bucket.
|
||||||
|
|
||||||
Metadata Bucket
|
# Metadata Bucket
|
||||||
|
|
||||||
As discussed above, all of the functions which are used to manipulate key/value
|
As discussed above, all of the functions which are used to manipulate key/value
|
||||||
pairs and nested buckets exist on the Bucket interface. The root metadata
|
pairs and nested buckets exist on the Bucket interface. The root metadata
|
||||||
|
@ -81,7 +81,7 @@ bucket is the upper-most bucket in which data is stored and is created at the
|
||||||
same time as the database. Use the Metadata function on the Tx interface
|
same time as the database. Use the Metadata function on the Tx interface
|
||||||
to retrieve it.
|
to retrieve it.
|
||||||
|
|
||||||
Nested Buckets
|
# Nested Buckets
|
||||||
|
|
||||||
The CreateBucket and CreateBucketIfNotExists functions on the Bucket interface
|
The CreateBucket and CreateBucketIfNotExists functions on the Bucket interface
|
||||||
provide the ability to create an arbitrary number of nested buckets. It is
|
provide the ability to create an arbitrary number of nested buckets. It is
|
||||||
|
|
|
@ -622,8 +622,8 @@ func (s *blockStore) syncBlocks() error {
|
||||||
// were partially written.
|
// were partially written.
|
||||||
//
|
//
|
||||||
// There are effectively two scenarios to consider here:
|
// There are effectively two scenarios to consider here:
|
||||||
// 1) Transient write failures from which recovery is possible
|
// 1. Transient write failures from which recovery is possible
|
||||||
// 2) More permanent failures such as hard disk death and/or removal
|
// 2. More permanent failures such as hard disk death and/or removal
|
||||||
//
|
//
|
||||||
// In either case, the write cursor will be repositioned to the old block file
|
// In either case, the write cursor will be repositioned to the old block file
|
||||||
// offset regardless of any other errors that occur while attempting to undo
|
// offset regardless of any other errors that occur while attempting to undo
|
||||||
|
|
|
@ -10,7 +10,7 @@ This driver is the recommended driver for use with lbcd. It makes use leveldb
|
||||||
for the metadata, flat files for block storage, and checksums in key areas to
|
for the metadata, flat files for block storage, and checksums in key areas to
|
||||||
ensure data integrity.
|
ensure data integrity.
|
||||||
|
|
||||||
Usage
|
# Usage
|
||||||
|
|
||||||
This package is a driver to the database package and provides the database type
|
This package is a driver to the database package and provides the database type
|
||||||
of "ffldb". The parameters the Open and Create functions take are the
|
of "ffldb". The parameters the Open and Create functions take are the
|
||||||
|
|
|
@ -318,13 +318,14 @@ func (iter *Iterator) ForceReseek() {
|
||||||
// unexpected keys and/or values.
|
// unexpected keys and/or values.
|
||||||
//
|
//
|
||||||
// For example:
|
// For example:
|
||||||
// iter := t.Iterator(nil, nil)
|
//
|
||||||
// for iter.Next() {
|
// iter := t.Iterator(nil, nil)
|
||||||
// if someCondition {
|
// for iter.Next() {
|
||||||
// t.Delete(iter.Key())
|
// if someCondition {
|
||||||
// iter.ForceReseek()
|
// t.Delete(iter.Key())
|
||||||
// }
|
// iter.ForceReseek()
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
func (t *Mutable) Iterator(startKey, limitKey []byte) *Iterator {
|
func (t *Mutable) Iterator(startKey, limitKey []byte) *Iterator {
|
||||||
iter := &Iterator{
|
iter := &Iterator{
|
||||||
t: t,
|
t: t,
|
||||||
|
|
266
doc.go
266
doc.go
|
@ -18,142 +18,144 @@ on Windows. The -C (--configfile) flag, as shown below, can be used to override
|
||||||
this location.
|
this location.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
lbcd [OPTIONS]
|
|
||||||
|
lbcd [OPTIONS]
|
||||||
|
|
||||||
Application Options:
|
Application Options:
|
||||||
--addcheckpoint= Add a custom checkpoint. Format:
|
|
||||||
'<height>:<hash>'
|
--addcheckpoint= Add a custom checkpoint. Format:
|
||||||
-a, --addpeer= Add a peer to connect with at startup
|
'<height>:<hash>'
|
||||||
--addrindex Maintain a full address-based transaction index
|
-a, --addpeer= Add a peer to connect with at startup
|
||||||
which makes the searchrawtransactions RPC
|
--addrindex Maintain a full address-based transaction index
|
||||||
available
|
which makes the searchrawtransactions RPC
|
||||||
--banduration= How long to ban misbehaving peers. Valid time
|
available
|
||||||
units are {s, m, h}. Minimum 1 second (default:
|
--banduration= How long to ban misbehaving peers. Valid time
|
||||||
24h0m0s)
|
units are {s, m, h}. Minimum 1 second (default:
|
||||||
--banthreshold= Maximum allowed ban score before disconnecting
|
24h0m0s)
|
||||||
and banning misbehaving peers. (default: 100)
|
--banthreshold= Maximum allowed ban score before disconnecting
|
||||||
--blockmaxsize= Maximum block size in bytes to be used when
|
and banning misbehaving peers. (default: 100)
|
||||||
creating a block (default: 750000)
|
--blockmaxsize= Maximum block size in bytes to be used when
|
||||||
--blockminsize= Mininum block size in bytes to be used when
|
creating a block (default: 750000)
|
||||||
creating a block
|
--blockminsize= Mininum block size in bytes to be used when
|
||||||
--blockmaxweight= Maximum block weight to be used when creating a
|
creating a block
|
||||||
block (default: 3000000)
|
--blockmaxweight= Maximum block weight to be used when creating a
|
||||||
--blockminweight= Mininum block weight to be used when creating a
|
block (default: 3000000)
|
||||||
block
|
--blockminweight= Mininum block weight to be used when creating a
|
||||||
--blockprioritysize= Size in bytes for high-priority/low-fee
|
block
|
||||||
transactions when creating a block (default:
|
--blockprioritysize= Size in bytes for high-priority/low-fee
|
||||||
50000)
|
transactions when creating a block (default:
|
||||||
--blocksonly Do not accept transactions from remote peers.
|
50000)
|
||||||
-C, --configfile= Path to configuration file
|
--blocksonly Do not accept transactions from remote peers.
|
||||||
--connect= Connect only to the specified peers at startup
|
-C, --configfile= Path to configuration file
|
||||||
--cpuprofile= Write CPU profile to the specified file
|
--connect= Connect only to the specified peers at startup
|
||||||
-b, --datadir= Directory to store data
|
--cpuprofile= Write CPU profile to the specified file
|
||||||
--dbtype= Database backend to use for the Block Chain
|
-b, --datadir= Directory to store data
|
||||||
(default: ffldb)
|
--dbtype= Database backend to use for the Block Chain
|
||||||
-d, --debuglevel= Logging level for all subsystems {trace, debug,
|
(default: ffldb)
|
||||||
info, warn, error, critical} -- You may also
|
-d, --debuglevel= Logging level for all subsystems {trace, debug,
|
||||||
specify
|
info, warn, error, critical} -- You may also
|
||||||
<subsystem>=<level>,<subsystem2>=<level>,... to
|
specify
|
||||||
set the log level for individual subsystems --
|
<subsystem>=<level>,<subsystem2>=<level>,... to
|
||||||
Use show to list available subsystems (default:
|
set the log level for individual subsystems --
|
||||||
info)
|
Use show to list available subsystems (default:
|
||||||
--dropaddrindex Deletes the address-based transaction index from
|
info)
|
||||||
the database on start up and then exits.
|
--dropaddrindex Deletes the address-based transaction index from
|
||||||
--dropcfindex Deletes the index used for committed filtering
|
the database on start up and then exits.
|
||||||
(CF) support from the database on start up and
|
--dropcfindex Deletes the index used for committed filtering
|
||||||
then exits.
|
(CF) support from the database on start up and
|
||||||
--droptxindex Deletes the hash-based transaction index from the
|
then exits.
|
||||||
database on start up and then exits.
|
--droptxindex Deletes the hash-based transaction index from the
|
||||||
--externalip= Add an ip to the list of local addresses we claim
|
database on start up and then exits.
|
||||||
to listen on to peers
|
--externalip= Add an ip to the list of local addresses we claim
|
||||||
--generate Generate (mine) bitcoins using the CPU
|
to listen on to peers
|
||||||
--limitfreerelay= Limit relay of transactions with no transaction
|
--generate Generate (mine) bitcoins using the CPU
|
||||||
fee to the given amount in thousands of bytes per
|
--limitfreerelay= Limit relay of transactions with no transaction
|
||||||
minute (default: 15)
|
fee to the given amount in thousands of bytes per
|
||||||
--listen= Add an interface/port to listen for connections
|
minute (default: 15)
|
||||||
(default all interfaces port: 9246, testnet:
|
--listen= Add an interface/port to listen for connections
|
||||||
19246, regtest: 29246, signet: 39246)
|
(default all interfaces port: 9246, testnet:
|
||||||
--logdir= Directory to log output
|
19246, regtest: 29246, signet: 39246)
|
||||||
--maxorphantx= Max number of orphan transactions to keep in
|
--logdir= Directory to log output
|
||||||
memory (default: 100)
|
--maxorphantx= Max number of orphan transactions to keep in
|
||||||
--maxpeers= Max number of inbound and outbound peers
|
memory (default: 100)
|
||||||
(default: 125)
|
--maxpeers= Max number of inbound and outbound peers
|
||||||
--memprofile= Write memory profile to the specified file
|
(default: 125)
|
||||||
--miningaddr= Add the specified payment address to the list of
|
--memprofile= Write memory profile to the specified file
|
||||||
addresses to use for generated blocks -- At least
|
--miningaddr= Add the specified payment address to the list of
|
||||||
one address is required if the generate option is
|
addresses to use for generated blocks -- At least
|
||||||
set
|
one address is required if the generate option is
|
||||||
--minrelaytxfee= The minimum transaction fee in BTC/kB to be
|
set
|
||||||
considered a non-zero fee. (default: 1e-05)
|
--minrelaytxfee= The minimum transaction fee in BTC/kB to be
|
||||||
--nobanning Disable banning of misbehaving peers
|
considered a non-zero fee. (default: 1e-05)
|
||||||
--nocfilters Disable committed filtering (CF) support
|
--nobanning Disable banning of misbehaving peers
|
||||||
--nocheckpoints Disable built-in checkpoints. Don't do this
|
--nocfilters Disable committed filtering (CF) support
|
||||||
unless you know what you're doing.
|
--nocheckpoints Disable built-in checkpoints. Don't do this
|
||||||
--nodnsseed Disable DNS seeding for peers
|
unless you know what you're doing.
|
||||||
--nolisten Disable listening for incoming connections --
|
--nodnsseed Disable DNS seeding for peers
|
||||||
NOTE: Listening is automatically disabled if the
|
--nolisten Disable listening for incoming connections --
|
||||||
--connect or --proxy options are used without
|
NOTE: Listening is automatically disabled if the
|
||||||
also specifying listen interfaces via --listen
|
--connect or --proxy options are used without
|
||||||
--noonion Disable connecting to tor hidden services
|
also specifying listen interfaces via --listen
|
||||||
--nopeerbloomfilters Disable bloom filtering support
|
--noonion Disable connecting to tor hidden services
|
||||||
--norelaypriority Do not require free or low-fee transactions to
|
--nopeerbloomfilters Disable bloom filtering support
|
||||||
have high priority for relaying
|
--norelaypriority Do not require free or low-fee transactions to
|
||||||
--norpc Disable built-in RPC server -- NOTE: The RPC
|
have high priority for relaying
|
||||||
server is disabled by default if no
|
--norpc Disable built-in RPC server -- NOTE: The RPC
|
||||||
rpcuser/rpcpass or rpclimituser/rpclimitpass is
|
server is disabled by default if no
|
||||||
specified
|
rpcuser/rpcpass or rpclimituser/rpclimitpass is
|
||||||
--notls Disable TLS for the RPC server
|
specified
|
||||||
--onion= Connect to tor hidden services via SOCKS5 proxy
|
--notls Disable TLS for the RPC server
|
||||||
(eg. 127.0.0.1:9050)
|
--onion= Connect to tor hidden services via SOCKS5 proxy
|
||||||
--onionpass= Password for onion proxy server
|
(eg. 127.0.0.1:9050)
|
||||||
--onionuser= Username for onion proxy server
|
--onionpass= Password for onion proxy server
|
||||||
--profile= Enable HTTP profiling on given port -- NOTE port
|
--onionuser= Username for onion proxy server
|
||||||
must be between 1024 and 65536
|
--profile= Enable HTTP profiling on given port -- NOTE port
|
||||||
--proxy= Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)
|
must be between 1024 and 65536
|
||||||
--proxypass= Password for proxy server
|
--proxy= Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)
|
||||||
--proxyuser= Username for proxy server
|
--proxypass= Password for proxy server
|
||||||
--regtest Use the regression test network
|
--proxyuser= Username for proxy server
|
||||||
--rejectnonstd Reject non-standard transactions regardless of
|
--regtest Use the regression test network
|
||||||
the default settings for the active network.
|
--rejectnonstd Reject non-standard transactions regardless of
|
||||||
--relaynonstd Relay non-standard transactions regardless of the
|
the default settings for the active network.
|
||||||
default settings for the active network.
|
--relaynonstd Relay non-standard transactions regardless of the
|
||||||
--rpccert= File containing the certificate file
|
default settings for the active network.
|
||||||
--rpckey= File containing the certificate key
|
--rpccert= File containing the certificate file
|
||||||
--rpclimitpass= Password for limited RPC connections
|
--rpckey= File containing the certificate key
|
||||||
--rpclimituser= Username for limited RPC connections
|
--rpclimitpass= Password for limited RPC connections
|
||||||
--rpclisten= Add an interface/port to listen for RPC
|
--rpclimituser= Username for limited RPC connections
|
||||||
connections (default port: 9245, testnet: 19245, regtest: 29245)
|
--rpclisten= Add an interface/port to listen for RPC
|
||||||
--rpcmaxclients= Max number of RPC clients for standard
|
connections (default port: 9245, testnet: 19245, regtest: 29245)
|
||||||
connections (default: 10)
|
--rpcmaxclients= Max number of RPC clients for standard
|
||||||
--rpcmaxconcurrentreqs= Max number of concurrent RPC requests that may be
|
connections (default: 10)
|
||||||
processed concurrently (default: 20)
|
--rpcmaxconcurrentreqs= Max number of concurrent RPC requests that may be
|
||||||
--rpcmaxwebsockets= Max number of RPC websocket connections (default:
|
processed concurrently (default: 20)
|
||||||
25)
|
--rpcmaxwebsockets= Max number of RPC websocket connections (default:
|
||||||
--rpcquirks Mirror some JSON-RPC quirks of Bitcoin Core --
|
25)
|
||||||
NOTE: Discouraged unless interoperability issues
|
--rpcquirks Mirror some JSON-RPC quirks of Bitcoin Core --
|
||||||
need to be worked around
|
NOTE: Discouraged unless interoperability issues
|
||||||
-P, --rpcpass= Password for RPC connections
|
need to be worked around
|
||||||
-u, --rpcuser= Username for RPC connections
|
-P, --rpcpass= Password for RPC connections
|
||||||
--sigcachemaxsize= The maximum number of entries in the signature
|
-u, --rpcuser= Username for RPC connections
|
||||||
verification cache (default: 100000)
|
--sigcachemaxsize= The maximum number of entries in the signature
|
||||||
--simnet Use the simulation test network
|
verification cache (default: 100000)
|
||||||
--testnet Use the test network
|
--simnet Use the simulation test network
|
||||||
--torisolation Enable Tor stream isolation by randomizing user
|
--testnet Use the test network
|
||||||
credentials for each connection.
|
--torisolation Enable Tor stream isolation by randomizing user
|
||||||
--trickleinterval= Minimum time between attempts to send new
|
credentials for each connection.
|
||||||
inventory to a connected peer (default: 10s)
|
--trickleinterval= Minimum time between attempts to send new
|
||||||
--txindex Maintain a full hash-based transaction index
|
inventory to a connected peer (default: 10s)
|
||||||
which makes all transactions available via the
|
--txindex Maintain a full hash-based transaction index
|
||||||
getrawtransaction RPC
|
which makes all transactions available via the
|
||||||
--uacomment= Comment to add to the user agent -- See BIP 14
|
getrawtransaction RPC
|
||||||
for more information.
|
--uacomment= Comment to add to the user agent -- See BIP 14
|
||||||
--upnp Use UPnP to map our listening port outside of NAT
|
for more information.
|
||||||
-V, --version Display version information and exit
|
--upnp Use UPnP to map our listening port outside of NAT
|
||||||
--whitelist= Add an IP network or IP that will not be banned.
|
-V, --version Display version information and exit
|
||||||
(eg. 192.168.1.0/24 or ::1)
|
--whitelist= Add an IP network or IP that will not be banned.
|
||||||
|
(eg. 192.168.1.0/24 or ::1)
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
-h, --help Show this help message
|
|
||||||
|
|
||||||
|
-h, --help Show this help message
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
42
fees/doc.go
42
fees/doc.go
|
@ -7,11 +7,11 @@ Package fees provides decred-specific methods for tracking and estimating fee
|
||||||
rates for new transactions to be mined into the network. Fee rate estimation has
|
rates for new transactions to be mined into the network. Fee rate estimation has
|
||||||
two main goals:
|
two main goals:
|
||||||
|
|
||||||
- Ensuring transactions are mined within a target _confirmation range_
|
- Ensuring transactions are mined within a target _confirmation range_
|
||||||
(expressed in blocks);
|
(expressed in blocks);
|
||||||
- Attempting to minimize fees while maintaining be above restriction.
|
- Attempting to minimize fees while maintaining be above restriction.
|
||||||
|
|
||||||
Preliminaries
|
# Preliminaries
|
||||||
|
|
||||||
There are two main regimes against which fee estimation needs to be evaluated
|
There are two main regimes against which fee estimation needs to be evaluated
|
||||||
according to how full blocks being mined are (and consequently how important fee
|
according to how full blocks being mined are (and consequently how important fee
|
||||||
|
@ -39,7 +39,7 @@ The current approach to implement this estimation is based on bitcoin core's
|
||||||
algorithm. References [1] and [2] provide a high level description of how it
|
algorithm. References [1] and [2] provide a high level description of how it
|
||||||
works there. Actual code is linked in references [3] and [4].
|
works there. Actual code is linked in references [3] and [4].
|
||||||
|
|
||||||
Outline of the Algorithm
|
# Outline of the Algorithm
|
||||||
|
|
||||||
The algorithm is currently based in fee estimation as used in v0.14 of bitcoin
|
The algorithm is currently based in fee estimation as used in v0.14 of bitcoin
|
||||||
core (which is also the basis for the v0.15+ method). A more comprehensive
|
core (which is also the basis for the v0.15+ method). A more comprehensive
|
||||||
|
@ -54,31 +54,31 @@ The basic algorithm is as follows (as executed by a single full node):
|
||||||
|
|
||||||
Stats building stage:
|
Stats building stage:
|
||||||
|
|
||||||
- For each transaction observed entering mempool, record the block at which it
|
- For each transaction observed entering mempool, record the block at which it
|
||||||
was first seen
|
was first seen
|
||||||
- For each mined transaction which was previously observed to enter the mempool,
|
- For each mined transaction which was previously observed to enter the mempool,
|
||||||
record how long (in blocks) it took to be mined and its fee rate
|
record how long (in blocks) it took to be mined and its fee rate
|
||||||
- Group mined transactions into fee rate _buckets_ and _confirmation ranges_,
|
- Group mined transactions into fee rate _buckets_ and _confirmation ranges_,
|
||||||
creating a table of how many transactions were mined at each confirmation
|
creating a table of how many transactions were mined at each confirmation
|
||||||
range and fee rate bucket and their total committed fee
|
range and fee rate bucket and their total committed fee
|
||||||
- Whenever a new block is mined, decay older transactions to account for a
|
- Whenever a new block is mined, decay older transactions to account for a
|
||||||
dynamic fee environment
|
dynamic fee environment
|
||||||
|
|
||||||
Estimation stage:
|
Estimation stage:
|
||||||
|
|
||||||
- Input a target confirmation range (how many blocks to wait for the tx to be
|
- Input a target confirmation range (how many blocks to wait for the tx to be
|
||||||
mined)
|
mined)
|
||||||
- Starting at the highest fee bucket, look for buckets where the chance of
|
- Starting at the highest fee bucket, look for buckets where the chance of
|
||||||
confirmation within the desired confirmation window is > 95%
|
confirmation within the desired confirmation window is > 95%
|
||||||
- Average all such buckets to get the estimated fee rate
|
- Average all such buckets to get the estimated fee rate
|
||||||
|
|
||||||
Simulation
|
# Simulation
|
||||||
|
|
||||||
Development of the estimator was originally performed and simulated using the
|
Development of the estimator was originally performed and simulated using the
|
||||||
code in [5]. Simulation of the current code can be performed by using the
|
code in [5]. Simulation of the current code can be performed by using the
|
||||||
dcrfeesim tool available in [6].
|
dcrfeesim tool available in [6].
|
||||||
|
|
||||||
Acknowledgements
|
# Acknowledgements
|
||||||
|
|
||||||
Thanks to @davecgh for providing the initial review of the results and the
|
Thanks to @davecgh for providing the initial review of the results and the
|
||||||
original developers of the bitcoin core code (the brunt of which seems to have
|
original developers of the bitcoin core code (the brunt of which seems to have
|
||||||
|
|
|
@ -282,19 +282,20 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
|
||||||
// - Assert the chain height is 0 and the state is ThresholdDefined
|
// - Assert the chain height is 0 and the state is ThresholdDefined
|
||||||
// - Generate 1 fewer blocks than needed to reach the first state transition
|
// - Generate 1 fewer blocks than needed to reach the first state transition
|
||||||
// - Assert chain height is expected and state is still ThresholdDefined
|
// - Assert chain height is expected and state is still ThresholdDefined
|
||||||
|
//
|
||||||
// - Generate 1 more block to reach the first state transition
|
// - Generate 1 more block to reach the first state transition
|
||||||
// - Assert chain height is expected and state moved to ThresholdStarted
|
// - Assert chain height is expected and state moved to ThresholdStarted
|
||||||
// - Generate enough blocks to reach the next state transition window, but only
|
// - Generate enough blocks to reach the next state transition window, but only
|
||||||
// signal support in 1 fewer than the required number to achieve
|
// signal support in 1 fewer than the required number to achieve
|
||||||
// ThresholdLockedIn
|
// ThresholdLockedIn
|
||||||
// - Assert chain height is expected and state is still ThresholdStarted
|
// - Assert chain height is expected and state is still ThresholdStarted
|
||||||
// - Generate enough blocks to reach the next state transition window with only
|
// - Generate enough blocks to reach the next state transition window with only
|
||||||
// the exact number of blocks required to achieve locked in status signalling
|
// the exact number of blocks required to achieve locked in status signalling
|
||||||
// support.
|
// support.
|
||||||
// - Assert chain height is expected and state moved to ThresholdLockedIn
|
// - Assert chain height is expected and state moved to ThresholdLockedIn
|
||||||
// - Generate 1 fewer blocks than needed to reach the next state transition
|
// - Generate 1 fewer blocks than needed to reach the next state transition
|
||||||
// - Assert chain height is expected and state is still ThresholdLockedIn
|
// - Assert chain height is expected and state is still ThresholdLockedIn
|
||||||
// - Generate 1 more block to reach the next state transition
|
// - Generate 1 more block to reach the next state transition
|
||||||
// - Assert chain height is expected and state moved to ThresholdActive
|
// - Assert chain height is expected and state moved to ThresholdActive
|
||||||
func TestBIP0009(t *testing.T) {
|
func TestBIP0009(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -309,11 +310,14 @@ func TestBIP0009(t *testing.T) {
|
||||||
// Overview:
|
// Overview:
|
||||||
// - Generate block 1
|
// - Generate block 1
|
||||||
// - Assert bit is NOT set (ThresholdDefined)
|
// - Assert bit is NOT set (ThresholdDefined)
|
||||||
|
//
|
||||||
// - Generate enough blocks to reach first state transition
|
// - Generate enough blocks to reach first state transition
|
||||||
// - Assert bit is NOT set for block prior to state transition
|
// - Assert bit is NOT set for block prior to state transition
|
||||||
// - Assert bit is set for block at state transition (ThresholdStarted)
|
// - Assert bit is set for block at state transition (ThresholdStarted)
|
||||||
|
//
|
||||||
// - Generate enough blocks to reach second state transition
|
// - Generate enough blocks to reach second state transition
|
||||||
// - Assert bit is set for block at state transition (ThresholdLockedIn)
|
// - Assert bit is set for block at state transition (ThresholdLockedIn)
|
||||||
|
//
|
||||||
// - Generate enough blocks to reach third state transition
|
// - Generate enough blocks to reach third state transition
|
||||||
// - Assert bit is set for block prior to state transition (ThresholdLockedIn)
|
// - Assert bit is set for block prior to state transition (ThresholdLockedIn)
|
||||||
// - Assert bit is NOT set for block at state transition (ThresholdActive)
|
// - Assert bit is NOT set for block at state transition (ThresholdActive)
|
||||||
|
|
|
@ -95,17 +95,22 @@ func makeTestOutput(r *rpctest.Harness, t *testing.T,
|
||||||
// them.
|
// them.
|
||||||
//
|
//
|
||||||
// Overview:
|
// Overview:
|
||||||
// - Pre soft-fork:
|
|
||||||
// - Transactions with non-final lock-times from the PoV of MTP should be
|
|
||||||
// rejected from the mempool.
|
|
||||||
// - Transactions within non-final MTP based lock-times should be accepted
|
|
||||||
// in valid blocks.
|
|
||||||
//
|
//
|
||||||
// - Post soft-fork:
|
// - Pre soft-fork:
|
||||||
// - Transactions with non-final lock-times from the PoV of MTP should be
|
//
|
||||||
// rejected from the mempool and when found within otherwise valid blocks.
|
// - Transactions with non-final lock-times from the PoV of MTP should be
|
||||||
// - Transactions with final lock-times from the PoV of MTP should be
|
// rejected from the mempool.
|
||||||
// accepted to the mempool and mined in future block.
|
//
|
||||||
|
// - Transactions within non-final MTP based lock-times should be accepted
|
||||||
|
// in valid blocks.
|
||||||
|
//
|
||||||
|
// - Post soft-fork:
|
||||||
|
//
|
||||||
|
// - Transactions with non-final lock-times from the PoV of MTP should be
|
||||||
|
// rejected from the mempool and when found within otherwise valid blocks.
|
||||||
|
//
|
||||||
|
// - Transactions with final lock-times from the PoV of MTP should be
|
||||||
|
// accepted to the mempool and mined in future block.
|
||||||
func TestBIP0113Activation(t *testing.T) {
|
func TestBIP0113Activation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
@ -391,13 +396,13 @@ func assertTxInBlock(r *rpctest.Harness, t *testing.T, blockHash *chainhash.Hash
|
||||||
// 112 and BIP 68 rule-set after the activation of the CSV-package soft-fork.
|
// 112 and BIP 68 rule-set after the activation of the CSV-package soft-fork.
|
||||||
//
|
//
|
||||||
// Overview:
|
// Overview:
|
||||||
// - Pre soft-fork:
|
// - Pre soft-fork:
|
||||||
// - A transaction spending a CSV output validly should be rejected from the
|
// - A transaction spending a CSV output validly should be rejected from the
|
||||||
// mempool, but accepted in a valid generated block including the
|
// mempool, but accepted in a valid generated block including the
|
||||||
// transaction.
|
// transaction.
|
||||||
// - Post soft-fork:
|
// - Post soft-fork:
|
||||||
// - See the cases exercised within the table driven tests towards the end
|
// - See the cases exercised within the table driven tests towards the end
|
||||||
// of this test.
|
// of this test.
|
||||||
func TestBIP0068AndBIP0112Activation(t *testing.T) {
|
func TestBIP0068AndBIP0112Activation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -31,40 +31,40 @@ proceed. Typically, this will involve things such as relaying the transactions
|
||||||
to other peers on the network and notifying the mining process that new
|
to other peers on the network and notifying the mining process that new
|
||||||
transactions are available.
|
transactions are available.
|
||||||
|
|
||||||
Feature Overview
|
# Feature Overview
|
||||||
|
|
||||||
The following is a quick overview of the major features. It is not intended to
|
The following is a quick overview of the major features. It is not intended to
|
||||||
be an exhaustive list.
|
be an exhaustive list.
|
||||||
|
|
||||||
- Maintain a pool of fully validated transactions
|
- Maintain a pool of fully validated transactions
|
||||||
- Reject non-fully-spent duplicate transactions
|
- Reject non-fully-spent duplicate transactions
|
||||||
- Reject coinbase transactions
|
- Reject coinbase transactions
|
||||||
- Reject double spends (both from the chain and other transactions in pool)
|
- Reject double spends (both from the chain and other transactions in pool)
|
||||||
- Reject invalid transactions according to the network consensus rules
|
- Reject invalid transactions according to the network consensus rules
|
||||||
- Full script execution and validation with signature cache support
|
- Full script execution and validation with signature cache support
|
||||||
- Individual transaction query support
|
- Individual transaction query support
|
||||||
- Orphan transaction support (transactions that spend from unknown outputs)
|
- Orphan transaction support (transactions that spend from unknown outputs)
|
||||||
- Configurable limits (see transaction acceptance policy)
|
- Configurable limits (see transaction acceptance policy)
|
||||||
- Automatic addition of orphan transactions that are no longer orphans as new
|
- Automatic addition of orphan transactions that are no longer orphans as new
|
||||||
transactions are added to the pool
|
transactions are added to the pool
|
||||||
- Individual orphan transaction query support
|
- Individual orphan transaction query support
|
||||||
- Configurable transaction acceptance policy
|
- Configurable transaction acceptance policy
|
||||||
- Option to accept or reject standard transactions
|
- Option to accept or reject standard transactions
|
||||||
- Option to accept or reject transactions based on priority calculations
|
- Option to accept or reject transactions based on priority calculations
|
||||||
- Rate limiting of low-fee and free transactions
|
- Rate limiting of low-fee and free transactions
|
||||||
- Non-zero fee threshold
|
- Non-zero fee threshold
|
||||||
- Max signature operations per transaction
|
- Max signature operations per transaction
|
||||||
- Max orphan transaction size
|
- Max orphan transaction size
|
||||||
- Max number of orphan transactions allowed
|
- Max number of orphan transactions allowed
|
||||||
- Additional metadata tracking for each transaction
|
- Additional metadata tracking for each transaction
|
||||||
- Timestamp when the transaction was added to the pool
|
- Timestamp when the transaction was added to the pool
|
||||||
- Most recent block height when the transaction was added to the pool
|
- Most recent block height when the transaction was added to the pool
|
||||||
- The fee the transaction pays
|
- The fee the transaction pays
|
||||||
- The starting priority for the transaction
|
- The starting priority for the transaction
|
||||||
- Manual control of transaction removal
|
- Manual control of transaction removal
|
||||||
- Recursive removal of all dependent transactions
|
- Recursive removal of all dependent transactions
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
Errors returned by this package are either the raw errors provided by underlying
|
Errors returned by this package are either the raw errors provided by underlying
|
||||||
calls or of type mempool.RuleError. Since there are two classes of rules
|
calls or of type mempool.RuleError. Since there are two classes of rules
|
||||||
|
|
|
@ -420,26 +420,26 @@ func NewBlkTmplGenerator(policy *Policy, params *chaincfg.Params,
|
||||||
//
|
//
|
||||||
// Given the above, a block generated by this function is of the following form:
|
// Given the above, a block generated by this function is of the following form:
|
||||||
//
|
//
|
||||||
// ----------------------------------- -- --
|
// ----------------------------------- -- --
|
||||||
// | Coinbase Transaction | | |
|
// | Coinbase Transaction | | |
|
||||||
// |-----------------------------------| | |
|
// |-----------------------------------| | |
|
||||||
// | | | | ----- policy.BlockPrioritySize
|
// | | | | ----- policy.BlockPrioritySize
|
||||||
// | High-priority Transactions | | |
|
// | High-priority Transactions | | |
|
||||||
// | | | |
|
// | | | |
|
||||||
// |-----------------------------------| | --
|
// |-----------------------------------| | --
|
||||||
// | | |
|
// | | |
|
||||||
// | | |
|
// | | |
|
||||||
// | | |--- policy.BlockMaxSize
|
// | | |--- policy.BlockMaxSize
|
||||||
// | Transactions prioritized by fee | |
|
// | Transactions prioritized by fee | |
|
||||||
// | until <= policy.TxMinFreeFee | |
|
// | until <= policy.TxMinFreeFee | |
|
||||||
// | | |
|
// | | |
|
||||||
// | | |
|
// | | |
|
||||||
// | | |
|
// | | |
|
||||||
// |-----------------------------------| |
|
// |-----------------------------------| |
|
||||||
// | Low-fee/Non high-priority (free) | |
|
// | Low-fee/Non high-priority (free) | |
|
||||||
// | transactions (while block size | |
|
// | transactions (while block size | |
|
||||||
// | <= policy.BlockMinSize) | |
|
// | <= policy.BlockMinSize) | |
|
||||||
// ----------------------------------- --
|
// ----------------------------------- --
|
||||||
func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*BlockTemplate, error) {
|
func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*BlockTemplate, error) {
|
||||||
// Extend the most recently known best block.
|
// Extend the most recently known best block.
|
||||||
best := g.chain.BestSnapshot()
|
best := g.chain.BestSnapshot()
|
||||||
|
|
|
@ -27,8 +27,9 @@ type blockProgressLogger struct {
|
||||||
|
|
||||||
// newBlockProgressLogger returns a new block progress logger.
|
// newBlockProgressLogger returns a new block progress logger.
|
||||||
// The progress message is templated as follows:
|
// The progress message is templated as follows:
|
||||||
// {progressAction} {numProcessed} {blocks|block} in the last {timePeriod}
|
//
|
||||||
// ({numTxs}, height {lastBlockHeight}, {lastBlockTimeStamp})
|
// {progressAction} {numProcessed} {blocks|block} in the last {timePeriod}
|
||||||
|
// ({numTxs}, height {lastBlockHeight}, {lastBlockTimeStamp})
|
||||||
func newBlockProgressLogger(progressMessage string, logger btclog.Logger) *blockProgressLogger {
|
func newBlockProgressLogger(progressMessage string, logger btclog.Logger) *blockProgressLogger {
|
||||||
return &blockProgressLogger{
|
return &blockProgressLogger{
|
||||||
lastBlockLogTime: time.Now(),
|
lastBlockLogTime: time.Now(),
|
||||||
|
|
84
peer/doc.go
84
peer/doc.go
|
@ -6,7 +6,7 @@
|
||||||
Package peer provides a common base for creating and managing Bitcoin network
|
Package peer provides a common base for creating and managing Bitcoin network
|
||||||
peers.
|
peers.
|
||||||
|
|
||||||
Overview
|
# Overview
|
||||||
|
|
||||||
This package builds upon the wire package, which provides the fundamental
|
This package builds upon the wire package, which provides the fundamental
|
||||||
primitives necessary to speak the bitcoin wire protocol, in order to simplify
|
primitives necessary to speak the bitcoin wire protocol, in order to simplify
|
||||||
|
@ -16,41 +16,41 @@ Payment Verification (SPV) nodes, proxies, etc.
|
||||||
|
|
||||||
A quick overview of the major features peer provides are as follows:
|
A quick overview of the major features peer provides are as follows:
|
||||||
|
|
||||||
- Provides a basic concurrent safe bitcoin peer for handling bitcoin
|
- Provides a basic concurrent safe bitcoin peer for handling bitcoin
|
||||||
communications via the peer-to-peer protocol
|
communications via the peer-to-peer protocol
|
||||||
- Full duplex reading and writing of bitcoin protocol messages
|
- Full duplex reading and writing of bitcoin protocol messages
|
||||||
- Automatic handling of the initial handshake process including protocol
|
- Automatic handling of the initial handshake process including protocol
|
||||||
version negotiation
|
version negotiation
|
||||||
- Asynchronous message queuing of outbound messages with optional channel for
|
- Asynchronous message queuing of outbound messages with optional channel for
|
||||||
notification when the message is actually sent
|
notification when the message is actually sent
|
||||||
- Flexible peer configuration
|
- Flexible peer configuration
|
||||||
- Caller is responsible for creating outgoing connections and listening for
|
- Caller is responsible for creating outgoing connections and listening for
|
||||||
incoming connections so they have flexibility to establish connections as
|
incoming connections so they have flexibility to establish connections as
|
||||||
they see fit (proxies, etc)
|
they see fit (proxies, etc)
|
||||||
- User agent name and version
|
- User agent name and version
|
||||||
- Bitcoin network
|
- Bitcoin network
|
||||||
- Service support signalling (full nodes, bloom filters, etc)
|
- Service support signalling (full nodes, bloom filters, etc)
|
||||||
- Maximum supported protocol version
|
- Maximum supported protocol version
|
||||||
- Ability to register callbacks for handling bitcoin protocol messages
|
- Ability to register callbacks for handling bitcoin protocol messages
|
||||||
- Inventory message batching and send trickling with known inventory detection
|
- Inventory message batching and send trickling with known inventory detection
|
||||||
and avoidance
|
and avoidance
|
||||||
- Automatic periodic keep-alive pinging and pong responses
|
- Automatic periodic keep-alive pinging and pong responses
|
||||||
- Random nonce generation and self connection detection
|
- Random nonce generation and self connection detection
|
||||||
- Proper handling of bloom filter related commands when the caller does not
|
- Proper handling of bloom filter related commands when the caller does not
|
||||||
specify the related flag to signal support
|
specify the related flag to signal support
|
||||||
- Disconnects the peer when the protocol version is high enough
|
- Disconnects the peer when the protocol version is high enough
|
||||||
- Does not invoke the related callbacks for older protocol versions
|
- Does not invoke the related callbacks for older protocol versions
|
||||||
- Snapshottable peer statistics such as the total number of bytes read and
|
- Snapshottable peer statistics such as the total number of bytes read and
|
||||||
written, the remote address, user agent, and negotiated protocol version
|
written, the remote address, user agent, and negotiated protocol version
|
||||||
- Helper functions pushing addresses, getblocks, getheaders, and reject
|
- Helper functions pushing addresses, getblocks, getheaders, and reject
|
||||||
messages
|
messages
|
||||||
- These could all be sent manually via the standard message output function,
|
- These could all be sent manually via the standard message output function,
|
||||||
but the helpers provide additional nice functionality such as duplicate
|
but the helpers provide additional nice functionality such as duplicate
|
||||||
filtering and address randomization
|
filtering and address randomization
|
||||||
- Ability to wait for shutdown/disconnect
|
- Ability to wait for shutdown/disconnect
|
||||||
- Comprehensive test coverage
|
- Comprehensive test coverage
|
||||||
|
|
||||||
Peer Configuration
|
# Peer Configuration
|
||||||
|
|
||||||
All peer configuration is handled with the Config struct. This allows the
|
All peer configuration is handled with the Config struct. This allows the
|
||||||
caller to specify things such as the user agent name and version, the bitcoin
|
caller to specify things such as the user agent name and version, the bitcoin
|
||||||
|
@ -58,7 +58,7 @@ network to use, which services it supports, and callbacks to invoke when bitcoin
|
||||||
messages are received. See the documentation for each field of the Config
|
messages are received. See the documentation for each field of the Config
|
||||||
struct for more details.
|
struct for more details.
|
||||||
|
|
||||||
Inbound and Outbound Peers
|
# Inbound and Outbound Peers
|
||||||
|
|
||||||
A peer can either be inbound or outbound. The caller is responsible for
|
A peer can either be inbound or outbound. The caller is responsible for
|
||||||
establishing the connection to remote peers and listening for incoming peers.
|
establishing the connection to remote peers and listening for incoming peers.
|
||||||
|
@ -73,7 +73,7 @@ Disconnect to disconnect from the peer and clean up all resources.
|
||||||
WaitForDisconnect can be used to block until peer disconnection and resource
|
WaitForDisconnect can be used to block until peer disconnection and resource
|
||||||
cleanup has completed.
|
cleanup has completed.
|
||||||
|
|
||||||
Callbacks
|
# Callbacks
|
||||||
|
|
||||||
In order to do anything useful with a peer, it is necessary to react to bitcoin
|
In order to do anything useful with a peer, it is necessary to react to bitcoin
|
||||||
messages. This is accomplished by creating an instance of the MessageListeners
|
messages. This is accomplished by creating an instance of the MessageListeners
|
||||||
|
@ -92,7 +92,7 @@ It is often useful to use closures which encapsulate state when specifying the
|
||||||
callback handlers. This provides a clean method for accessing that state when
|
callback handlers. This provides a clean method for accessing that state when
|
||||||
callbacks are invoked.
|
callbacks are invoked.
|
||||||
|
|
||||||
Queuing Messages and Inventory
|
# Queuing Messages and Inventory
|
||||||
|
|
||||||
The QueueMessage function provides the fundamental means to send messages to the
|
The QueueMessage function provides the fundamental means to send messages to the
|
||||||
remote peer. As the name implies, this employs a non-blocking queue. A done
|
remote peer. As the name implies, this employs a non-blocking queue. A done
|
||||||
|
@ -106,7 +106,7 @@ QueueInventory function. It employs batching and trickling along with
|
||||||
intelligent known remote peer inventory detection and avoidance through the use
|
intelligent known remote peer inventory detection and avoidance through the use
|
||||||
of a most-recently used algorithm.
|
of a most-recently used algorithm.
|
||||||
|
|
||||||
Message Sending Helper Functions
|
# Message Sending Helper Functions
|
||||||
|
|
||||||
In addition to the bare QueueMessage function previously described, the
|
In addition to the bare QueueMessage function previously described, the
|
||||||
PushAddrMsg, PushGetBlocksMsg, PushGetHeadersMsg, and PushRejectMsg functions
|
PushAddrMsg, PushGetBlocksMsg, PushGetHeadersMsg, and PushRejectMsg functions
|
||||||
|
@ -128,13 +128,13 @@ appropriate reject message based on the provided parameters as well as
|
||||||
optionally provides a flag to cause it to block until the message is actually
|
optionally provides a flag to cause it to block until the message is actually
|
||||||
sent.
|
sent.
|
||||||
|
|
||||||
Peer Statistics
|
# Peer Statistics
|
||||||
|
|
||||||
A snapshot of the current peer statistics can be obtained with the StatsSnapshot
|
A snapshot of the current peer statistics can be obtained with the StatsSnapshot
|
||||||
function. This includes statistics such as the total number of bytes read and
|
function. This includes statistics such as the total number of bytes read and
|
||||||
written, the remote address, user agent, and negotiated protocol version.
|
written, the remote address, user agent, and negotiated protocol version.
|
||||||
|
|
||||||
Logging
|
# Logging
|
||||||
|
|
||||||
This package provides extensive logging capabilities through the UseLogger
|
This package provides extensive logging capabilities through the UseLogger
|
||||||
function which allows a btclog.Logger to be specified. For example, logging at
|
function which allows a btclog.Logger to be specified. For example, logging at
|
||||||
|
@ -142,7 +142,7 @@ the debug level provides summaries of every message sent and received, and
|
||||||
logging at the trace level provides full dumps of parsed messages as well as the
|
logging at the trace level provides full dumps of parsed messages as well as the
|
||||||
raw message bytes using a format similar to hexdump -C.
|
raw message bytes using a format similar to hexdump -C.
|
||||||
|
|
||||||
Bitcoin Improvement Proposals
|
# Bitcoin Improvement Proposals
|
||||||
|
|
||||||
This package supports all BIPS supported by the wire package.
|
This package supports all BIPS supported by the wire package.
|
||||||
(https://pkg.go.dev/github.com/lbryio/lbcd/wire#hdr-Bitcoin_Improvement_Proposals)
|
(https://pkg.go.dev/github.com/lbryio/lbcd/wire#hdr-Bitcoin_Improvement_Proposals)
|
||||||
|
|
16
peer/peer.go
16
peer/peer.go
|
@ -2096,10 +2096,10 @@ func (p *Peer) writeLocalVersionMsg() error {
|
||||||
// peer. The events should occur in the following order, otherwise an error is
|
// peer. The events should occur in the following order, otherwise an error is
|
||||||
// returned:
|
// returned:
|
||||||
//
|
//
|
||||||
// 1. Remote peer sends their version.
|
// 1. Remote peer sends their version.
|
||||||
// 2. We send our version.
|
// 2. We send our version.
|
||||||
// 3. We send our verack.
|
// 3. We send our verack.
|
||||||
// 4. Remote peer sends their verack.
|
// 4. Remote peer sends their verack.
|
||||||
func (p *Peer) negotiateInboundProtocol() error {
|
func (p *Peer) negotiateInboundProtocol() error {
|
||||||
if err := p.readRemoteVersionMsg(); err != nil {
|
if err := p.readRemoteVersionMsg(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2121,10 +2121,10 @@ func (p *Peer) negotiateInboundProtocol() error {
|
||||||
// peer. The events should occur in the following order, otherwise an error is
|
// peer. The events should occur in the following order, otherwise an error is
|
||||||
// returned:
|
// returned:
|
||||||
//
|
//
|
||||||
// 1. We send our version.
|
// 1. We send our version.
|
||||||
// 2. Remote peer sends their version.
|
// 2. Remote peer sends their version.
|
||||||
// 3. Remote peer sends their verack.
|
// 3. Remote peer sends their verack.
|
||||||
// 4. We send our verack.
|
// 4. We send our verack.
|
||||||
func (p *Peer) negotiateOutboundProtocol() error {
|
func (p *Peer) negotiateOutboundProtocol() error {
|
||||||
if err := p.writeLocalVersionMsg(); err != nil {
|
if err := p.writeLocalVersionMsg(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
/*
|
/*
|
||||||
Package rpcclient implements a websocket-enabled Bitcoin JSON-RPC client.
|
Package rpcclient implements a websocket-enabled Bitcoin JSON-RPC client.
|
||||||
|
|
||||||
Overview
|
# Overview
|
||||||
|
|
||||||
This client provides a robust and easy to use client for interfacing with a
|
This client provides a robust and easy to use client for interfacing with a
|
||||||
Bitcoin RPC server that uses a btcd/bitcoin core compatible Bitcoin JSON-RPC
|
Bitcoin RPC server that uses a btcd/bitcoin core compatible Bitcoin JSON-RPC
|
||||||
|
@ -24,7 +24,7 @@ btcd or btcwallet by default. However, configuration options are provided to
|
||||||
fall back to HTTP POST and disable TLS to support talking with inferior bitcoin
|
fall back to HTTP POST and disable TLS to support talking with inferior bitcoin
|
||||||
core style RPC servers.
|
core style RPC servers.
|
||||||
|
|
||||||
Websockets vs HTTP POST
|
# Websockets vs HTTP POST
|
||||||
|
|
||||||
In HTTP POST-based JSON-RPC, every request creates a new HTTP connection,
|
In HTTP POST-based JSON-RPC, every request creates a new HTTP connection,
|
||||||
issues the call, waits for the response, and closes the connection. This adds
|
issues the call, waits for the response, and closes the connection. This adds
|
||||||
|
@ -40,7 +40,7 @@ can be invoked without having to go through a connect/disconnect cycle for every
|
||||||
call. In addition, the websocket interface provides other nice features such as
|
call. In addition, the websocket interface provides other nice features such as
|
||||||
the ability to register for asynchronous notifications of various events.
|
the ability to register for asynchronous notifications of various events.
|
||||||
|
|
||||||
Synchronous vs Asynchronous API
|
# Synchronous vs Asynchronous API
|
||||||
|
|
||||||
The client provides both a synchronous (blocking) and asynchronous API.
|
The client provides both a synchronous (blocking) and asynchronous API.
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ the Receive method on the returned instance will either return the result
|
||||||
immediately if it has already arrived, or block until it has. This is useful
|
immediately if it has already arrived, or block until it has. This is useful
|
||||||
since it provides the caller with greater control over concurrency.
|
since it provides the caller with greater control over concurrency.
|
||||||
|
|
||||||
Notifications
|
# Notifications
|
||||||
|
|
||||||
The first important part of notifications is to realize that they will only
|
The first important part of notifications is to realize that they will only
|
||||||
work when connected via websockets. This should intuitively make sense
|
work when connected via websockets. This should intuitively make sense
|
||||||
|
@ -67,7 +67,7 @@ All notifications provided by btcd require registration to opt-in. For example,
|
||||||
if you want to be notified when funds are received by a set of addresses, you
|
if you want to be notified when funds are received by a set of addresses, you
|
||||||
register the addresses via the NotifyReceived (or NotifyReceivedAsync) function.
|
register the addresses via the NotifyReceived (or NotifyReceivedAsync) function.
|
||||||
|
|
||||||
Notification Handlers
|
# Notification Handlers
|
||||||
|
|
||||||
Notifications are exposed by the client through the use of callback handlers
|
Notifications are exposed by the client through the use of callback handlers
|
||||||
which are setup via a NotificationHandlers instance that is specified by the
|
which are setup via a NotificationHandlers instance that is specified by the
|
||||||
|
@ -83,7 +83,7 @@ will cause a deadlock as more server responses won't be read until the callback
|
||||||
returns, but the callback would be waiting for a response. Thus, any
|
returns, but the callback would be waiting for a response. Thus, any
|
||||||
additional RPCs must be issued an a completely decoupled manner.
|
additional RPCs must be issued an a completely decoupled manner.
|
||||||
|
|
||||||
Automatic Reconnection
|
# Automatic Reconnection
|
||||||
|
|
||||||
By default, when running in websockets mode, this client will automatically
|
By default, when running in websockets mode, this client will automatically
|
||||||
keep trying to reconnect to the RPC server should the connection be lost. There
|
keep trying to reconnect to the RPC server should the connection be lost. There
|
||||||
|
@ -116,7 +116,7 @@ chain services will be available. Depending on your application, you might only
|
||||||
need chain-related RPCs. In contrast, btcwallet provides pass through treatment
|
need chain-related RPCs. In contrast, btcwallet provides pass through treatment
|
||||||
for chain-related RPCs, so it supports them in addition to wallet-related RPCs.
|
for chain-related RPCs, so it supports them in addition to wallet-related RPCs.
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
There are 3 categories of errors that will be returned throughout this package:
|
There are 3 categories of errors that will be returned throughout this package:
|
||||||
|
|
||||||
|
@ -144,35 +144,35 @@ The third category of errors, that is errors returned by the server, can be
|
||||||
detected by type asserting the error in a *btcjson.RPCError. For example, to
|
detected by type asserting the error in a *btcjson.RPCError. For example, to
|
||||||
detect if a command is unimplemented by the remote RPC server:
|
detect if a command is unimplemented by the remote RPC server:
|
||||||
|
|
||||||
amount, err := client.GetBalance("")
|
amount, err := client.GetBalance("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if jerr, ok := err.(*btcjson.RPCError); ok {
|
if jerr, ok := err.(*btcjson.RPCError); ok {
|
||||||
switch jerr.Code {
|
switch jerr.Code {
|
||||||
case btcjson.ErrRPCUnimplemented:
|
case btcjson.ErrRPCUnimplemented:
|
||||||
// Handle not implemented error
|
// Handle not implemented error
|
||||||
|
|
||||||
// Handle other specific errors you care about
|
// Handle other specific errors you care about
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log or otherwise handle the error knowing it was not one returned
|
// Log or otherwise handle the error knowing it was not one returned
|
||||||
// from the remote RPC server.
|
// from the remote RPC server.
|
||||||
}
|
}
|
||||||
|
|
||||||
Example Usage
|
# Example Usage
|
||||||
|
|
||||||
The following full-blown client examples are in the examples directory:
|
The following full-blown client examples are in the examples directory:
|
||||||
|
|
||||||
- bitcoincorehttp
|
- bitcoincorehttp
|
||||||
Connects to a bitcoin core RPC server using HTTP POST mode with TLS disabled
|
Connects to a bitcoin core RPC server using HTTP POST mode with TLS disabled
|
||||||
and gets the current block count
|
and gets the current block count
|
||||||
- btcdwebsockets
|
- btcdwebsockets
|
||||||
Connects to a btcd RPC server using TLS-secured websockets, registers for
|
Connects to a btcd RPC server using TLS-secured websockets, registers for
|
||||||
block connected and block disconnected notifications, and gets the current
|
block connected and block disconnected notifications, and gets the current
|
||||||
block count
|
block count
|
||||||
- btcwalletwebsockets
|
- btcwalletwebsockets
|
||||||
Connects to a btcwallet RPC server using TLS-secured websockets, registers
|
Connects to a btcwallet RPC server using TLS-secured websockets, registers
|
||||||
for notifications about changes to account balances, and gets a list of
|
for notifications about changes to account balances, and gets a list of
|
||||||
unspent transaction outputs (utxos) the wallet can sign
|
unspent transaction outputs (utxos) the wallet can sign
|
||||||
*/
|
*/
|
||||||
package rpcclient
|
package rpcclient
|
||||||
|
|
|
@ -56,7 +56,8 @@ func (c *Client) DebugLevelAsync(levelSpec string) FutureDebugLevelResult {
|
||||||
// specification.
|
// specification.
|
||||||
//
|
//
|
||||||
// The levelspec can be either a debug level or of the form:
|
// The levelspec can be either a debug level or of the form:
|
||||||
// <subsystem>=<level>,<subsystem2>=<level2>,...
|
//
|
||||||
|
// <subsystem>=<level>,<subsystem2>=<level2>,...
|
||||||
//
|
//
|
||||||
// Additionally, the special keyword 'show' can be used to get a list of the
|
// Additionally, the special keyword 'show' can be used to get a list of the
|
||||||
// available subsystems.
|
// available subsystems.
|
||||||
|
|
|
@ -1016,10 +1016,10 @@ func (c *Client) CreateWalletAsync(name string, opts ...CreateWalletOpt) FutureC
|
||||||
//
|
//
|
||||||
// Optional parameters can be specified using functional-options pattern. The
|
// Optional parameters can be specified using functional-options pattern. The
|
||||||
// following functions are available:
|
// following functions are available:
|
||||||
// * WithCreateWalletDisablePrivateKeys
|
// - WithCreateWalletDisablePrivateKeys
|
||||||
// * WithCreateWalletBlank
|
// - WithCreateWalletBlank
|
||||||
// * WithCreateWalletPassphrase
|
// - WithCreateWalletPassphrase
|
||||||
// * WithCreateWalletAvoidReuse
|
// - WithCreateWalletAvoidReuse
|
||||||
func (c *Client) CreateWallet(name string, opts ...CreateWalletOpt) (*btcjson.CreateWalletResult, error) {
|
func (c *Client) CreateWallet(name string, opts ...CreateWalletOpt) (*btcjson.CreateWalletResult, error) {
|
||||||
return c.CreateWalletAsync(name, opts...).Receive()
|
return c.CreateWalletAsync(name, opts...).Receive()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ overview to provide information on how to use the package.
|
||||||
This package provides data structures and functions to parse and execute
|
This package provides data structures and functions to parse and execute
|
||||||
bitcoin transaction scripts.
|
bitcoin transaction scripts.
|
||||||
|
|
||||||
Script Overview
|
# Script Overview
|
||||||
|
|
||||||
Bitcoin transaction scripts are written in a stack-base, FORTH-like language.
|
Bitcoin transaction scripts are written in a stack-base, FORTH-like language.
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ is used to prove the the spender is authorized to perform the transaction.
|
||||||
One benefit of using a scripting language is added flexibility in specifying
|
One benefit of using a scripting language is added flexibility in specifying
|
||||||
what conditions must be met in order to spend bitcoins.
|
what conditions must be met in order to spend bitcoins.
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
Errors returned by this package are of type txscript.Error. This allows the
|
Errors returned by this package are of type txscript.Error. This allows the
|
||||||
caller to programmatically determine the specific error by examining the
|
caller to programmatically determine the specific error by examining the
|
||||||
|
|
|
@ -427,10 +427,10 @@ func (e ErrorCode) String() string {
|
||||||
|
|
||||||
// Error identifies a script-related error. It is used to indicate three
|
// Error identifies a script-related error. It is used to indicate three
|
||||||
// classes of errors:
|
// classes of errors:
|
||||||
// 1) Script execution failures due to violating one of the many requirements
|
// 1. Script execution failures due to violating one of the many requirements
|
||||||
// imposed by the script engine or evaluating to false
|
// imposed by the script engine or evaluating to false
|
||||||
// 2) Improper API usage by callers
|
// 2. Improper API usage by callers
|
||||||
// 3) Internal consistency check failures
|
// 3. Internal consistency check failures
|
||||||
//
|
//
|
||||||
// The caller can use type assertions on the returned errors to access the
|
// The caller can use type assertions on the returned errors to access the
|
||||||
// ErrorCode field to ascertain the specific reason for the error. As an
|
// ErrorCode field to ascertain the specific reason for the error. As an
|
||||||
|
|
|
@ -37,16 +37,17 @@ func (e ErrScriptNotCanonical) Error() string {
|
||||||
// For example, the following would build a 2-of-3 multisig script for usage in
|
// For example, the following would build a 2-of-3 multisig script for usage in
|
||||||
// a pay-to-script-hash (although in this situation MultiSigScript() would be a
|
// a pay-to-script-hash (although in this situation MultiSigScript() would be a
|
||||||
// better choice to generate the script):
|
// better choice to generate the script):
|
||||||
// builder := txscript.NewScriptBuilder()
|
//
|
||||||
// builder.AddOp(txscript.OP_2).AddData(pubKey1).AddData(pubKey2)
|
// builder := txscript.NewScriptBuilder()
|
||||||
// builder.AddData(pubKey3).AddOp(txscript.OP_3)
|
// builder.AddOp(txscript.OP_2).AddData(pubKey1).AddData(pubKey2)
|
||||||
// builder.AddOp(txscript.OP_CHECKMULTISIG)
|
// builder.AddData(pubKey3).AddOp(txscript.OP_3)
|
||||||
// script, err := builder.Script()
|
// builder.AddOp(txscript.OP_CHECKMULTISIG)
|
||||||
// if err != nil {
|
// script, err := builder.Script()
|
||||||
// // Handle the error.
|
// if err != nil {
|
||||||
// return
|
// // Handle the error.
|
||||||
// }
|
// return
|
||||||
// fmt.Printf("Final multi-sig script: %x\n", script)
|
// }
|
||||||
|
// fmt.Printf("Final multi-sig script: %x\n", script)
|
||||||
type ScriptBuilder struct {
|
type ScriptBuilder struct {
|
||||||
script []byte
|
script []byte
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -89,18 +89,19 @@ func checkMinimalDataEncoding(v []byte) error {
|
||||||
// Bytes returns the number serialized as a little endian with a sign bit.
|
// Bytes returns the number serialized as a little endian with a sign bit.
|
||||||
//
|
//
|
||||||
// Example encodings:
|
// Example encodings:
|
||||||
// 127 -> [0x7f]
|
//
|
||||||
// -127 -> [0xff]
|
// 127 -> [0x7f]
|
||||||
// 128 -> [0x80 0x00]
|
// -127 -> [0xff]
|
||||||
// -128 -> [0x80 0x80]
|
// 128 -> [0x80 0x00]
|
||||||
// 129 -> [0x81 0x00]
|
// -128 -> [0x80 0x80]
|
||||||
// -129 -> [0x81 0x80]
|
// 129 -> [0x81 0x00]
|
||||||
// 256 -> [0x00 0x01]
|
// -129 -> [0x81 0x80]
|
||||||
// -256 -> [0x00 0x81]
|
// 256 -> [0x00 0x01]
|
||||||
// 32767 -> [0xff 0x7f]
|
// -256 -> [0x00 0x81]
|
||||||
// -32767 -> [0xff 0xff]
|
// 32767 -> [0xff 0x7f]
|
||||||
// 32768 -> [0x00 0x80 0x00]
|
// -32767 -> [0xff 0xff]
|
||||||
// -32768 -> [0x00 0x80 0x80]
|
// 32768 -> [0x00 0x80 0x00]
|
||||||
|
// -32768 -> [0x00 0x80 0x80]
|
||||||
func (n scriptNum) Bytes() []byte {
|
func (n scriptNum) Bytes() []byte {
|
||||||
// Zero encodes as an empty byte slice.
|
// Zero encodes as an empty byte slice.
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
|
20
wire/doc.go
20
wire/doc.go
|
@ -14,7 +14,7 @@ supported bitcoin messages to and from the wire. This package does not deal
|
||||||
with the specifics of message handling such as what to do when a message is
|
with the specifics of message handling such as what to do when a message is
|
||||||
received. This provides the caller with a high level of flexibility.
|
received. This provides the caller with a high level of flexibility.
|
||||||
|
|
||||||
Bitcoin Message Overview
|
# Bitcoin Message Overview
|
||||||
|
|
||||||
The bitcoin protocol consists of exchanging messages between peers. Each
|
The bitcoin protocol consists of exchanging messages between peers. Each
|
||||||
message is preceded by a header which identifies information about it such as
|
message is preceded by a header which identifies information about it such as
|
||||||
|
@ -30,7 +30,7 @@ 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
|
wire using bitcoin encoding are handled so the caller doesn't have to concern
|
||||||
themselves with the specifics.
|
themselves with the specifics.
|
||||||
|
|
||||||
Message Interaction
|
# Message Interaction
|
||||||
|
|
||||||
The following provides a quick summary of how the bitcoin messages are intended
|
The following provides a quick summary of how the bitcoin messages are intended
|
||||||
to interact with one another. As stated above, these interactions are not
|
to interact with one another. As stated above, these interactions are not
|
||||||
|
@ -62,13 +62,13 @@ interactions in no particular order.
|
||||||
in BIP0031. The BIP0031Version constant can be used to detect a recent
|
in BIP0031. The BIP0031Version constant can be used to detect a recent
|
||||||
enough protocol version for this purpose (version > BIP0031Version).
|
enough protocol version for this purpose (version > BIP0031Version).
|
||||||
|
|
||||||
Common Parameters
|
# Common Parameters
|
||||||
|
|
||||||
There are several common parameters that arise when using this package to read
|
There are several common parameters that arise when using this package to read
|
||||||
and write bitcoin messages. The following sections provide a quick overview of
|
and write bitcoin messages. The following sections provide a quick overview of
|
||||||
these parameters so the next sections can build on them.
|
these parameters so the next sections can build on them.
|
||||||
|
|
||||||
Protocol Version
|
# Protocol Version
|
||||||
|
|
||||||
The protocol version should be negotiated with the remote peer at a higher
|
The protocol version should be negotiated with the remote peer at a higher
|
||||||
level than this package via the version (MsgVersion) message exchange, however,
|
level than this package via the version (MsgVersion) message exchange, however,
|
||||||
|
@ -77,7 +77,7 @@ latest protocol version this package supports and is typically the value to use
|
||||||
for all outbound connections before a potentially lower protocol version is
|
for all outbound connections before a potentially lower protocol version is
|
||||||
negotiated.
|
negotiated.
|
||||||
|
|
||||||
Bitcoin Network
|
# Bitcoin Network
|
||||||
|
|
||||||
The bitcoin network is a magic number which is used to identify the start of a
|
The bitcoin network is a magic number which is used to identify the start of a
|
||||||
message and which bitcoin network the message applies to. This package provides
|
message and which bitcoin network the message applies to. This package provides
|
||||||
|
@ -88,7 +88,7 @@ the following constants:
|
||||||
wire.TestNet3 (Test network version 3)
|
wire.TestNet3 (Test network version 3)
|
||||||
wire.SimNet (Simulation test network)
|
wire.SimNet (Simulation test network)
|
||||||
|
|
||||||
Determining Message Type
|
# Determining Message Type
|
||||||
|
|
||||||
As discussed in the bitcoin message overview section, this package reads
|
As discussed in the bitcoin message overview section, this package reads
|
||||||
and writes bitcoin messages using a generic interface named Message. In
|
and writes bitcoin messages using a generic interface named Message. In
|
||||||
|
@ -106,7 +106,7 @@ switch or type assertion. An example of a type switch follows:
|
||||||
fmt.Printf("Number of tx in block: %v", msg.Header.TxnCount)
|
fmt.Printf("Number of tx in block: %v", msg.Header.TxnCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
Reading Messages
|
# Reading Messages
|
||||||
|
|
||||||
In order to unmarshall bitcoin messages from the wire, use the ReadMessage
|
In order to unmarshall bitcoin messages from the wire, use the ReadMessage
|
||||||
function. It accepts any io.Reader, but typically this will be a net.Conn to
|
function. It accepts any io.Reader, but typically this will be a net.Conn to
|
||||||
|
@ -121,7 +121,7 @@ a remote node running a bitcoin peer. Example syntax is:
|
||||||
// Log and handle the error
|
// Log and handle the error
|
||||||
}
|
}
|
||||||
|
|
||||||
Writing Messages
|
# Writing Messages
|
||||||
|
|
||||||
In order to marshall bitcoin messages to the wire, use the WriteMessage
|
In order to marshall bitcoin messages to the wire, use the WriteMessage
|
||||||
function. It accepts any io.Writer, but typically this will be a net.Conn to
|
function. It accepts any io.Writer, but typically this will be a net.Conn to
|
||||||
|
@ -139,7 +139,7 @@ from a remote peer is:
|
||||||
// Log and handle the error
|
// Log and handle the error
|
||||||
}
|
}
|
||||||
|
|
||||||
Errors
|
# Errors
|
||||||
|
|
||||||
Errors returned by this package are either the raw errors provided by underlying
|
Errors returned by this package are either the raw errors provided by underlying
|
||||||
calls to read/write from streams such as io.EOF, io.ErrUnexpectedEOF, and
|
calls to read/write from streams such as io.EOF, io.ErrUnexpectedEOF, and
|
||||||
|
@ -147,7 +147,7 @@ io.ErrShortWrite, or of type wire.MessageError. This allows the caller to
|
||||||
differentiate between general IO errors and malformed messages through type
|
differentiate between general IO errors and malformed messages through type
|
||||||
assertions.
|
assertions.
|
||||||
|
|
||||||
Bitcoin Improvement Proposals
|
# Bitcoin Improvement Proposals
|
||||||
|
|
||||||
This package includes spec changes outlined by the following BIPs:
|
This package includes spec changes outlined by the following BIPs:
|
||||||
|
|
||||||
|
|
|
@ -114,16 +114,18 @@ const (
|
||||||
// transaction from one that would require a different parsing logic.
|
// transaction from one that would require a different parsing logic.
|
||||||
//
|
//
|
||||||
// Position of FLAG in a bitcoin tx message:
|
// Position of FLAG in a bitcoin tx message:
|
||||||
// ┌─────────┬────────────────────┬─────────────┬─────┐
|
//
|
||||||
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
|
// ┌─────────┬────────────────────┬─────────────┬─────┐
|
||||||
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
|
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
|
||||||
// └─────────┴────────────────────┴─────────────┴─────┘
|
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
|
||||||
|
// └─────────┴────────────────────┴─────────────┴─────┘
|
||||||
//
|
//
|
||||||
// Zooming into the FLAG field:
|
// Zooming into the FLAG field:
|
||||||
// ┌── FLAG ─────────────┬────────┐
|
//
|
||||||
// │ TxFlagMarker (0x00) │ TxFlag │
|
// ┌── FLAG ─────────────┬────────┐
|
||||||
// │ 1 byte │ 1 byte │
|
// │ TxFlagMarker (0x00) │ TxFlag │
|
||||||
// └─────────────────────┴────────┘
|
// │ 1 byte │ 1 byte │
|
||||||
|
// └─────────────────────┴────────┘
|
||||||
const TxFlagMarker = 0x00
|
const TxFlagMarker = 0x00
|
||||||
|
|
||||||
// TxFlag is the second byte of the FLAG field in a bitcoin tx message.
|
// TxFlag is the second byte of the FLAG field in a bitcoin tx message.
|
||||||
|
|
Loading…
Add table
Reference in a new issue