Commit graph

3509 commits

Author SHA1 Message Date
Dave Collins
b661dd3693 Convert block manager block handler to pure FIFO.
Rather than having a separate query channel for the block manager, use the
same channel so the block handler acts as a pure FIFO queue.  This
prevents possible starvation of query related messages.

ok @owainga
2014-03-12 13:26:06 -05:00
Dave Collins
f65ea832de Export a couple of peer-to-peer client errors.
ok @jcvernaleo
2014-03-12 10:11:18 -05:00
David Hill
936b4eaa2d add unit testing for BigToCompact, CompactToBig, and CalcWork 2014-03-11 22:33:56 -04:00
Dave Collins
0e1f6a6628 Export MaxBlockHeaderPayload. 2014-03-11 20:22:32 -05:00
Dave Collins
e5d15b0fa8 Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
Dave Collins
1676ecd7a6 Export CheckConnectBlock function.
This commit makes a slight variant of the existing checkConnectBlock
function available to external callers.  The new exported version checks
if the passed block will connect to the end of the current main chain.

In order to support this, a few other small modifications have been made
to the initial index generation and the existing checkConnectBlock since
it previously made some assumptions about the state of genesis block which
can no longer be assumed due accepting blocks from callers directly.

Also, add a quick test to ensure the new function fails when checking if
the genesis block will connect again when it's already inserted.
2014-03-11 13:18:27 -05:00
Dave Collins
acdce27f9f Defer unlock of orphan mutex in addOrphanBlock.
This was pointed out by saracen on the btcd IRC channel.
2014-03-09 11:05:12 -05:00
Francis Lam
33af740985 Added missing notificationMsg types to notificationHandler 2014-03-04 21:36:48 -05:00
David Hill
b452acdde2 remove link 2014-03-04 13:00:06 -05:00
David Hill
5549b99e19 mention IRC server 2014-03-04 12:58:59 -05:00
Josh Rickmar
27f3d916ec Do not block removing clients if notification manager quit. 2014-03-04 11:31:44 -05:00
Josh Rickmar
a7d5b365b1 Retain order when processing client notifications.
This change modifies the RPC server's notifiation manager from a
struct with requests, protected by a mutux, to two goroutines.  The
first maintains a queue of all notifications and control requests
(registering/unregistering notifications), while the second reads from
the queue and processes notifications and requests one at a time.

Previously, to prevent slowing down block and mempool processing, each
notification would be handled by spawning a new goroutine.  This lead
to cases where notifications would end up being sent to clients in a
different order than they were created.  Adding a queue keeps the
order of notifications originating from the same goroutine, while also
not slowing down processing while waiting for notifications to be
processed and sent.

ok @davecgh
2014-03-04 11:15:25 -05:00
Owain G. Ainsworth
aff33f1e3c Consistently use the peer stringer to print the peer address.
This provides more information than using the address directly.
2014-03-04 15:47:20 +00:00
Dave Collins
2a42cc134f Lower min transaction relay fee to 1000 satoshi.
This mirrors a recent change in the reference implementation.  Since the
vast majority of the network still uses it and transactions which aren't
considered standard won't be relayed, the rules for standard transactions
need to be kept consistent.

Ideally this should be handled via floating fees, but we're rather limited
until we have miner support and a larger network share so the probability
of a transaction being relayed and confirmed is high.

Closes #100.

ok @owainga
2014-03-04 09:40:57 -06:00
Dave Collins
b9c21bd518 Export VarIntSerializeSize function.
This commit exports the VarIntSerializeSize function to provide callers
with an easy method to determine how many bytes it would take to serialize
the passed value as a variable length integer.
2014-03-03 18:43:09 -06:00
Dave Collins
b041971ca8 Export CalcNextRequiredDifficutly function.
This commit exports a new variant of the existing internal
calcNextRequiredDifficulty function which calculates and returns the next
required difficulty for a block after the end of the current best chain
based on the difficulty retarget rules.

In order to support the exported function the internal one was slightly
modified to accept the block timestamp instead of an entire block since
the timestamp is all that is needed and the caller of the exported
function might next have a full block yet.
2014-03-02 18:43:41 -06:00
David Hill
cbb5c5b424 recieve -> receive 2014-03-02 13:28:29 -05:00
Dave Collins
b59a15d07e Export CountP2SHSigOps. 2014-03-01 21:50:11 -06:00
Dave Collins
ec641751a8 Change BuildMerkleTreeStore to accept transactions.
This commit modifies the BuildMerkleTreeStore function to accept a slice
of btcutil.Tx transactions as opposed to a full block.  This allows more
flexibility when calculating merkle roots since a full block may not be
created yet (particularly when generating blocks that need to be solved in
mining).

Previously, the BuildMerkleTreeStore function accepted a btcutil.Block
because originally the block itself cached the transaction hashes and it
was necessary to have access to the block to make use of the cached
transactions.  However, the code has since been improved such that it
caches transaction hashes directly in each btcutil.Tx.  This means the
code can remain as efficient as before while allowing the individual
transacitons to be passed.
2014-03-01 21:16:19 -06:00
Dave Collins
d2bfd3d98b Alphabetize subsystem loggers.
This commit simply alphabetizes the subsystem logger variables, map, and
use switch so the order in the code is consistent with the sorted output
displayed when using --debuglevel.
2014-03-01 16:08:21 -06:00
Dave Collins
82edb203e5 Export MaxSigOpsPerBlock. 2014-02-28 12:24:05 -06:00
Dave Collins
87ecac2072 Export CountSigOps function. 2014-02-28 12:16:56 -06:00
Dave Collins
91e563edaa Add IP address to a few more peer error messages.
This commit adds the peer IP to a few more error messages as originally
noted by #102.
2014-02-28 10:59:35 -06:00
Dave Collins
ce2f68a982 Fix typo on previous commit.
The peer and error were reversed for the regression test error message
case.

Spotted by @dajohi.
2014-02-28 10:55:25 -06:00
Dave Collins
29b790b9c8 Add IP address to peer error messages.
Closes #102.
2014-02-28 10:48:50 -06:00
Dave Collins
178e60a66e Update sample conf regarding debuglevel subsystems.
The debuglevel parameter has accepted subsystems in additional to an
overall level for quite some time, but the sample config file was not
updated to reflect that.

This commit updates the sample config file accordingly.
2014-02-28 09:54:34 -06:00
Dave Collins
f01459c30e Update for recent btcutil Addr interface changes. 2014-02-26 14:06:48 -06:00
Dave Collins
1623818c12 Export a new constant for MaxPrevOutIndex.
This commit exports a new constant for the maximum index a previous
outpoint can contain.
2014-02-25 16:00:03 -06:00
Dave Collins
8c7c1e84a3 Use mtx to control disconnect of websocket client.
This commit changes the websocket client code to use a mutex for
disconnect since it's theoretically possible a non-blocking select on the
quit channel could fall through from two different goroutines thus causing
a second call to close.

ok @jrick.
2014-02-25 12:50:32 -06:00
Dave Collins
a56dfc7ff4 Export CalcBlockSubsidy function. 2014-02-25 00:32:22 -06:00
Josh Rickmar
bb4cba51cd Switch to new transaction notifications.
This change removes the processedtx notification, replacing it with
recvtx, and the spenttx notification, replacing it with redeemingtx.
Both new transactions return the full serialized transaction (encoded
in hexadecimal) rather than details about the transaction.

The old txmined notification has also been completely removed as it is
unreliable due to transaction malleability and no code should be
depending on it.
2014-02-24 14:52:09 -05:00
Josh Rickmar
0c6d7bbeae Improve websocket transaction notifications.
This change improves the mechanism by which btcd notifies a websocket
client of transaction relating to watched address and unspent outputs
in the following ways:

1. The old processedtx notification has been replaced with the new
   recvtx notification.  This notification, rather than parsing out
   details used by wallet clients, sends the serialized transaction
   (as hexadecimal) and any block details (if mined) if any transaction
   output sends to one of the websocket client's watched addresses.

2. The old txspent notification has been replaced with the new
   redeemingtx notification.  This notification, rather than parsing
   out details used by wallet clients, sends the serialized transaction
   (as hexadecimal) and any block details (if mined) if any transaction
   input spends a watched output.

3. When processing notifications for transaction outputs, if any output
   spends to a client's watched address, a corresponding spent request
   is automatically registered.

4. Transaction notifications originating from mempool now include both
   transaction inputs and outputs, rather than only processing

5. When processing notifications for transaction inputs, a client's
   output spent request is only removed if the transaction being
   processed has also been mined into a block.  In combination with the
   4th change, this results in two redeemingtx notifications for
   transactions which first appear in mempool and are subsequently mined
   into a block.
2014-02-24 13:17:57 -05:00
Dave Collins
1c052a01d8 Reject blocks with high precision timestamps.
This commit adds an additional sanity check to ensure the block that is
being processed does not contain a timestamp with a precision higher than
one second.  This is necessary because the consensus rules only deal with
whole seconds in the time comparisons whereas the internal data structures
make use of Go time.Time values which support up to nanosecond precision.

Also, add a test to ensure the new functionality works as expected.

ok @owainga
2014-02-24 10:42:50 -06:00
Dave Collins
13e0b0e7b9 Limit generated timestamps to one second precision.
This commit changes all cases which generate default timestamps to
time.Now to limit the timestamp to one second precision.  The code which
serializes and deserializes timestamps already does this, but it is useful
to make sure defaults don't exceed the precision of the protocol either.

With this change there is less chance that developers using defaults will
end up with structures that have a higher time precision than what will
ultimately be sent across the wire.
2014-02-24 09:55:02 -06:00
Dave Collins
bfef4e4a31 Make regtest subsidy halving interval 150.
This commit moves the subsidy halving interval to the chain params so it
can be configured per network.  With that change it sets the regression
test halving interval to 150 to match the regression test params of the
reference implementation.

This was pointed out by @flammit.
2014-02-23 14:32:56 -06:00
Dave Collins
b25bf566b0 Rename findLatestKnownCheckpoint.
The name findLatestKnownCheckpoint is confusing and doesn't really convey
the fact the purpose of the function is to the find the checkpoint prior
to the current known block.

Therefore, rename the function to findPreviousCheckpoint for clarity.

Also, update some comments to follow suit.
2014-02-21 15:16:41 -06:00
Dave Collins
50b6e10b57 Reject blocks that fork before previous checkpoint.
This commit adds an additional check to the block acceptance rules which
prevents new blocks that fork the main chain before the previous known
good checkpoint.  This prevents storage of new, otherwise valid, blocks
from building off of old blocks which are likely at a much easier
difficulty and therefore could be used to waste cache and disk space.

Note this is slightly different than the other existing check which
prevents blocks with a timestamp before the timestamp of the latest known
good checkpoint since that check effectively prevents old side chain
blocks that already existed (per the claimed timestamp).

ok drahn@
2014-02-21 15:11:22 -06:00
Dave Collins
da1fcc6dbd Tighten the check for pay-to-pubkey scripts.
This commit tightens the check for a pay-to-pubkey script by ensuring the
length of the pubkey is one of the two valid values of 33 or 65.  This
mirrors the checks in the multisig script type check as well.

ok @owainga
2014-02-21 12:18:43 -06:00
Josh Rickmar
a3ccc25e5a Return errors for any sendrawtransaction rejection.
This changes the implementation of the sendrawtransaction RPC handler
to match bitcoind behavior by always returning a rejection error for
any error processing or accepting the tx by the mempool.  Previously,
if the tx was rejected for a rule error rather than an actual failure,
a client would still receive the tx sha as a result with no error.
2014-02-21 09:03:04 -05:00
Dave Collins
982f282e10 Go fmt. 2014-02-21 02:10:38 -06:00
Owain G. Ainsworth
88f3c73ad1 Add MultiSigScript to provide a canonical script for a multisig transaction. 2014-02-21 00:20:24 +00:00
Dave Collins
40cdacde23 Prepare for release 0.7.0. 2014-02-20 15:51:40 -06:00
Owain G. Ainsworth
2b0b512a83 Add support for pay to pubkey addresses to PayToAddrScript
Based on some initial code from @davecgh, finished by me.
2014-02-20 19:26:34 +00:00
Owain G. Ainsworth
5171cb803c Convert builder.Push* to builder.Add* we think this is clearer.
Also, shorter!  Discussed with @davecgh.
2014-02-20 18:42:58 +00:00
Owain G. Ainsworth
1566366346 convert internal script generation to use ScriptBuilder.
Also, unexport the functions to generate script types. Everything should
(and is) be using PayToAddrScript() with an address type instead of
throwing bytes around.

discussed with #@davecgh
2014-02-20 17:52:46 +00:00
Dave Collins
cff7f9704b Fix a few comment typos. 2014-02-20 11:20:53 -06:00
John C. Vernaleo
21b974e271 Fix missing ) in comment. 2014-02-20 10:52:06 -05:00
Dave Collins
5a660e95f9 Add 100% test coverage for new ScriptBuilder code. 2014-02-20 02:47:52 -06:00
Dave Collins
50173b865b Allow push of 0 via new ScriptBuilder PushInt64.
Nothing was being pushed for 0 to the new ScriptBuilder due to the fact Go
big integers when set to 0 have no bytes.
2014-02-20 01:48:37 -06:00
Dave Collins
264c89099f Make non-canoncial data pushes non-standard.
This commit makes use of the new btcscript.HasCanonicalPushes to enforce
canonical data pushes for transactions that are considered standard.

A canonical data push is one where the fewest number of bytes possible to
encode the size of the data being pushed is used.  This includes using the
small integer opcodes for single byte data that can be represented
directly.
2014-02-20 01:25:29 -06:00