Commit graph

3531 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
1bf564d963 Fix #138 by dynamically updating heights of peers
In order to avoid prior situations of stalled syncs due to
outdated peer height data, we now update block heights up peers in
real-time as we learn of their announced
blocks.

Updates happen when:
   * A peer sends us an orphan block. We update based on
     the height embedded in the scriptSig for the coinbase tx
   * When a peer sends us an inv for a block we already know
     of
   * When peers announce new blocks. Subsequent
     announcements that lost the announcement race are
     recognized and peer heights are updated accordingly

Additionally, the `getpeerinfo` command has been modified
to include both the starting height, and current height of
connected peers.

Docs have been updated with `getpeerinfo` extension.
2015-04-01 17:22:45 -07:00
Alex Akselrod
7c46f213e1 Fix #340 and DropAfterBlockBySha/NewestSha bug.
- Delete spent TX in setclearSpentData when unspent by block
  disconnect on reorg; return an error when there's more than
  one record to delete in the spent TX as that should never
  happen.

- Test spent TX deletion when reorg causes block disconnect.

- Test for correct NewestSha results after DropAfterBlockBySha.

- Fix DropAfterBlockBySha to update info for NewestSha.

- Updated copyright statements in modified files
2015-03-30 16:35:38 -05:00
Alex Akselrod
ead39153af Fix #303 and #346 and change addrindex sort order
Fix #303 by changing the addrindex key prefix to 3 characters so that
it's easy to check length when dropping the index. To drop the old
index, check to make sure we aren't dropping any entries that end in
"sx" or "tx" as those aren't part of the addrindex. Update test to
deal with the new prefix length.

Fix #346 by changing the pointers in the mempool's addrindex map to
wire.ShaHash 32-byte values. This lets them be deleted even if the
transaction data changes places in memory upon expanding the maps.

Change the way addrindex uint32s are stored to big-endian in order to
sort the transactions on disk in chronological/dependency order.

Change the "searchrawtransactions" RPC call to return transactions
from the database before the memory pool so that they're returned in
order. This commit DOES NOT do topological sorting of the memory pool
transactions to ensure they're returned in dependency order. This may
be a good idea for a future enhancement.

Add addrindex versioning to automatically drop the old/incompatible
version of the index and rebuild with the new sort method and key
prefix.
2015-03-23 13:05:54 -04:00
David Hill
ccc3a9b979 Do a little addrindex database cleanup.
- Use explicit index values for byte slices
- Fix a bug in FetchTxsForAddr that allocated an extra 10 bytes
  for each address index
- Add missing iterator release in error path
- Check for iterator errors.
2015-03-14 22:09:51 -04:00
David Hill
369b352452 txscript: Add new flag ScriptVerifyLowS
The ScriptVerifyLowS flag defines that script signatures must
comply with the DER format as well as have an S value less than
or equal to the half order.
2015-03-14 13:40:03 -04:00
David Hill
9523345814 txscript: Add new flag ScriptVerifyCleanStack
The ScriptVerifyCleanStack flag requires that only a single
stack element remains after evaluation and that when interpreted
as a bool, it must be true.  This is BIP0062, rule 6.

This mimics Bitcoin Core commit b6e03cc59208305681745ad06f2056ffe6690597
2015-03-13 15:54:17 -04:00
Dave Collins
d3aebcaed3 btcctl: Support - argument to read from stdin.
This commit modifies the argument handling for btcctl to treat a
parameter that is a single dash as an indicator to read that paramter from
stdin instead.

This change allows commands, such as the submitblock, to accept data piped
from stdin for any parameter.  This, in turn, allows large arguments, such
as blocks, which can often be too big for a single argument due to
Operating System limitations to be submitted by putting them into a file
and redirecting stdin.

For example:

btcctl submitblock - <block.hex
cat block.hex | btcctl submitblock -

btcctl sendrawtransaction - <tx.hex
cat tx.hex | btcctl sendrawtransaction -
2015-03-13 11:15:26 -05:00
Dave Collins
279308288c blockchain: Provide new IsCoinBaseTx function.
This commit adds a new function to the blockchain package named
IsCoinBaseTx which performs the same function as IsCoinBase except it
takes raw wire transactions as opposed to the higher level util
transactions.

While here, it also adds a file for benchmarks along with a couple of
benchmarks for the IsCoinBase and IsCoinBaseTx functions.

Finally, the function was very slightly optimized:

BenchmarkIsCoinBaseOld  100000000  10.7 ns/op  0 B/op  0 allocs/op
BenchmarkIsCoinBaseNew  200000000  6.05 ns/op  0 B/op  0 allocs/op
2015-03-10 13:55:24 -05:00
David Hill
54d7951084 Process orphans on block acceptance.
For every transaction in a newly accepted block, process the orphan
pool moving now no longer orphan transactions to the mempool.

Previously, no longer orphan transactions would remain in the orphan
pool.
2015-03-10 14:15:55 -04:00
David Hill
ad35a5dc48 Have calcPriority determine the tx size. 2015-03-10 00:19:23 -04:00
David Hill
436fb8203c txscript: Increase maximum allowed nulldata bytes
This change increases the maximum allowed bytes allowed in pushed
data to be considered a nulldata transaction.  This matches the current
value the reference implementation uses by default.
2015-03-09 23:40:46 -04:00
David Hill
db8fa6f850 Add id and timeoffset to getpeerinfo. 2015-03-09 23:27:53 -04:00
Dave Collins
62432a6f90 wire: Add func to get pkscript locs from a tx.
This commit provides a new function named PkScriptLocs on the MsgTx type
which can be used to efficiently retrieve a list of offsets for the public
key scripts for the serialized form of the transaction.

This is useful for certain applications which store fully serialized
transactions and want to be able to quickly index into the serialized
transaction to extract a give public key script directly thereby avoiding
the need to deserialize the entire transaction.
2015-03-09 22:09:09 -05:00
Dave Collins
def0ef6af6 Use network adjusted time for finalized tx check.
This commit modifies finalized transaction check used by the memory pool
and block templates to use the network adjusted time instead of the
unadjusted local time.  This helps keep the transactions accepted to the
memory pool, and hence allowed to relay, more consistent across nodes.
2015-03-09 22:03:58 -05:00
Dave Collins
e0bb106646 Update golang.org/x/crypto imports to new location (round 2). 2015-03-03 21:25:53 -06:00
Dave Collins
a765bbff5a Update golang.org/x/crypto import paths to new location. 2015-03-03 21:10:38 -06:00
Jimmy Song
f54ffd8c76 Added some unit tests to addrmgr. 2015-03-02 12:28:58 -06:00
Dave Collins
cfefe14153 Prepare for release 0.10.0-beta. 2015-03-01 20:18:11 -06:00
Dave Collins
28269d2598 rpcserver: Use default values for getnetworkhashps.
When the fields in the command for the getnetworkhashps RPC don't have the
fields set, use the intended default values.

Since the btcjson package sets these fields to the default values when a
command is unmarshaled from the wire, this typically isn't necessary.
However, when the RPC server calls the handler internally with optional
command fields set to nil, as is the case in getmininginfo, the defaults
need to be set as well.
2015-02-28 20:49:37 -06:00
Josh Rickmar
5ac0f1247d Fix return types for handleGetNetworkHashPS. 2015-02-28 21:40:13 -05:00
Dave Collins
2c80b44024 Update release script to correct btcctl location. 2015-02-28 03:39:20 -06:00
Dave Collins
2dc8a8a9ee Add 0.10.0 deps to deps.txt. 2015-02-28 03:08:44 -06:00
Dave Collins
ac4879dde2 Add checkpoint at block height 343185. 2015-02-27 12:34:42 -06:00
David Hill
c153596542 Update Travis to test against golang 1.4.2 2015-02-27 13:28:06 -05:00
David Hill
8412cde46f btcjson: Fix a bug in btcjson v2
btcjson v2 switched an optional field to mandatory which resulted
in a nil deference.  This switches it back to optional.
2015-02-26 19:35:46 -05:00
David Hill
d9cba7ca6a txscript: export StandardVerifyFlags
By exporting StandardVerifyFlags, clients can ensure they create
transactions that btcd will accept into its mempool.

This flag doesn't belong in txscript.  It belongs in a
policy package.  However, this is currently the least worse place.
2015-02-26 15:21:12 -05:00
David Hill
c09ef75ba9 Enable strict encoding verification 2015-02-26 13:58:45 -05:00
David Hill
ff747f8eae Use ScriptVerifyMinimalData
Additionally, drop HasCanoncialPushes as ScriptVerifyMinimalData
offers more complete checks.
2015-02-26 13:13:16 -05:00
Dave Collins
3ed8f363e7 Implement BIP0066 changeover logic for v3 blocks.
This commit implements the changeover logic for version 3 blocks as
described by BIP0066.
2015-02-26 09:54:29 -06:00
Dave Collins
4c53599b67 mempool: Loosen restrictions for resurrected txns.
This modifies the recently added code which rejects free/low-fee
transactions with insufficient priority to ignore resurrected transactions
from disconnected blocks.  It also exempts resurrected transactions from
the free/low-fee rate limiting.
2015-02-25 22:07:12 -06:00
Dave Collins
65eb8020d2 blockchain: Determine script flags sooner.
This commit moves the definition of the flags which are needed to check
transaction scripts higher up the call stack to pave the way for adding
support for v3 blocks.  While here, also spruce up a couple of sections.

There are no functional changes in this commit.
2015-02-25 16:56:34 -06:00
Dave Collins
5a800b9580 Rewrite btcctl to use the new features of btcjson.
This commit contains what is essentially a complete rewrite of the btcctl
utility to make use of the new features provided by the latest version
btcjson and improve several things along the way.  The following
summarizes the changes:

- The supported commands and handling now come directly from btcjson, so
  it is no longer necessary to manually add new commands.  Once a command
  has been registered with btcjson, it will automatically become usable by
  btcctl complete with full error handling (once it is re-compiled of
  course)
- Rather than dumping the entire list of commands on every error, the user
  now must specifically request the list of command via the -l option
- The list of commands is now categorized by chain and wallet and
  alphabetized
- The help flag now only shows the help options instead of also dumping
  all of the commands
- The error display on valid commands with invalid parameters has been
  greatly improved to show the specific parameter number, reason, and
  error code
- When a valid command is specified with invalid parameter, only the usage
  for that specific command is shown now
- It is now possible to use a SOCKS5 proxy for connection
- The output of commands has been improved in the following ways:
  - Strings on commands such as getbestblockhash no longer have quotes
    wrapped around them
  - Fields that are integers no longer show in scientific notation when
    they are large (timestamps for example)

This closes #305 as a side effect.
2015-02-25 16:03:31 -06:00
Dave Collins
c0428f6f9f btcjson: Update searchrawtransactions verbose.
This commit updates the SearchRawTransactionsCmd verbose parameter in the
latest version of btcjson to an integer to match recent changes to the
previous version of btcjson.
2015-02-25 16:03:30 -06:00
Josh Rickmar
859d9a7520 wire: Display correct RandomUint64 test failures. 2015-02-25 15:32:00 -05:00
David Hill
b3342510b7 txscript: sync Bitcoin Core tests. 2015-02-25 12:44:15 -05:00
David Hill
833bb04775 Reject free/low-fee transactions with insufficient priority.
By default, have the mempool reject free and low-fee transactions that
have insufficient priority to be mined in the next block.

Addtionally, add a new configuration option, -norelaypriority, to
disable the check.
2015-02-25 11:27:41 -05:00
Dave Collins
637fbcadec rpcserver: Convert to make use of new btcjson.
This commit converts the RPC server over to use the new features available
in the latest version of btcjson and improve a few things along the way.
This following summarizes the changes:

- All btcjson imports have been updated to the latest package version
- The help has been significantly improved
  - Invoking help with no command specified now provides an alphabetized
    list of all supported commands along with one-line usage
  - The help for each command is automatically generated and provides much
    more explicit information such as the type of each parameter, whether
    or not it's optional or required, etc
  - The websocket-specific commands are now provided when accessing the
    help when connected via websockets
  - Help has been added for all websocket-specific commands and is only
    accessible when connected via websockets
- The error returns and handling of both the standard and websocket
  handlers has been made consistent
- All RPC errors have been converted to the new RPCError type
- Various variables have been renamed for consistency
- Several RPC errors have been improved
- The commands that are marked as unimplemented have been moved into the
  separate map where they belong
- Several comments have been improved
- An unnecessary check has been removed from the createrawtransaction
  handler
- The command parsing has been restructured a bit to pave the way for
  JSON-RPC 2.0 batching support
2015-02-24 23:46:51 -06:00
Dave Collins
c0c48e0efd Improve a couple of JSON-RPC server err conditions.
- When invalid HTTP Basic Access Authentication details are provided to
  the websocket endpoint, return a WWW-Authenticate header just like the
  non-websocket endpoint
- When a connection to the websocket endpoint fails to properly upgrade,
  return a 400 Bad Request HTTP error status code
2015-02-24 20:09:15 -06:00
Dave Collins
7b849ef3eb Improve internal RPC server function order.
This commit reorders the RPC server code to more closely match the
ordering used by the rest of the code base such that functions are
typically defined before they are used and near their call site.
2015-02-24 20:09:14 -06:00
David Hill
5a4312d9ca txscript: Add new flag ScriptVerifyMinimalData
The ScriptVerifyMinimalData enforces that all push operations use the
minimal data push required.  This is part of BIP0062.

This commit mimics Bitcoin Core commit
698c6abb25c1fbbc7fa4ba46b60e9f17d97332ef
2015-02-24 18:06:20 -05:00
Josh Rickmar
63c1172aa8 Automatically register for tx notifications after a rescan.
This changes the behavior of the rescan RPC to automatically set the
client up for transaction notifications for transactions paying to any
rescanned address and spending outputs in the final rescan UTXO set
after a rescanned is performed through the best block in the chain.
2015-02-24 10:42:28 -05:00
Josh Rickmar
951f244f87 Move calcPriority to the file where it's used. 2015-02-24 10:15:15 -05:00
David Hill
f79c72f18a txscript: Remove ScriptCanonicalSignatures
Remove ScriptCanonicalSignatures and use the new
ScriptVerifyDERSignatures flag.  The ScriptVerifyDERSignatures
flag accomplishes the same functionality.
2015-02-23 22:04:15 -05:00
Olaoluwa Osuntokun
bc6be3ba69 Correct documentation for searchrawtransactions
`searchrawtransactions` can return multiple transactions. Previously the documentation erroneously had return examples showing only a single tx for each case. 
  * The documentation previously presented the output for the `non-verbose` case as a single json string, instead of an array of json strings. 
  * Similarly, for the `verbose` mode, the documentation detailed the output as a single json object, instead of an array of json objects.
2015-02-23 09:57:56 -08:00
Dave Collins
d45f4c47a2 Update btcws path import paths to new location. 2015-02-19 13:08:29 -06:00
Dave Collins
467d44cfc3 Update btcws path import paths to new location. 2015-02-19 13:07:25 -06:00
Dave Collins
66f128651d Merge btcws repo into btcjson/btcws directory. 2015-02-19 12:53:23 -06:00
Dave Collins
3e800e154c Import btcws repo into btcjson/btcws directory. 2015-02-19 12:53:08 -06:00
Dave Collins
23ab2bf329 Update btcjson path import paths to new location. 2015-02-19 12:00:51 -06:00
Dave Collins
6d289f602a Update btcjson path import paths to new location. 2015-02-19 11:55:22 -06:00