Commit graph

219 commits

Author SHA1 Message Date
Dave Collins b732eac0be Update websocket import paths to new location. 2015-01-15 17:20:30 -06:00
Dave Collins 58db4a8b7e Update btcutil import paths to new location. 2015-01-15 10:30:38 -06:00
Dave Collins a64ffb820a Correct RPC time handling for getblocktemplate.
This commit modifies the getblocktemplate RPC to correctly handle the
curtime field.

Currently, the RPC server will refuse to serve a block template if the
current time is before the minimum allowed time for a block even though
the real generated block template already accounted for it.

This consists of three changes:
- Remove the unnecessary and incorrect check in the RPC invocation for the
  current time against the min required time since it is already handled
  properly by the block template generation.
- Expose the network time source to the RPC work state and use the
  adjusted time for checking against the maximum allowed time instead of
  the current time.
- Set the returned RPC result curtime field to the time of the generated
  block header.

Fixes #209.
2015-01-08 01:41:50 -06:00
Dave Collins 4b727d2035 Ignore error in script disassembly for RPC results.
This commit modifies the creation of RPC results to ignore errors in
script disassembly since they already contain the error string inline and
the RPC results must still be generated regardless.

This was already done in the decodescript RPC, however the same thing was
not being done in the higher level verbose transaction results.  This
applies to both the createrawtransaction and decoderawtransaction RPCs.

Also, since this was the only thing that could error within those
functions, the error returns and caller checking of now non-existent
errors have been removed.

Fixes #210.
2015-01-07 16:23:23 -06:00
Dave Collins 04d47de262 Allow disabling RPC server TLS for localhost only.
This commit introduces a new flag, --notls, which can be used to disable
TLS for the RPC server.  However, the flag can only be used when the RPC
server is bound to localhost interfaces.  This is intended to prevent the
situation where someone decides they want to expose the RPC server to the
web for remote management/access, but forgot they have TLS disabled.
2015-01-02 11:17:23 -06:00
Dave Collins 33546047e3 Use correct error name in handleGetRawTransaction.
This commit corrects the error check from the createTxRawResult call in
handleGetRawTransaction.  It was previously given a different name which
resulted in the wrong error being checked.

Fixes #196.
2014-12-21 21:49:21 -06:00
Josh Rickmar 1d0c09a852 Require TLS 1.2 minimum.
This prevents a downgrade attack to the vulnerable SSLv3.  While here,
go ahead and require at least TLS 1.2 since TLS 1.0 and 1.1 have their
own set of issues and it's only a matter of time before those would
need to be completely avoided as well.

ok @davecgh
2014-12-15 13:53:14 -05:00
Dave Collins 888884a399 Use .haveTransaction in new getmempool RPC code.
The mempool is already locked and the exported version locks it, so the
unexported version is needed.
2014-11-17 15:46:42 -06:00
Dave Collins 1973aa5fd5 A few nitpicks with recent getrawmempool updates.
This commit addresses a few nitpicks in the recent getrawmppol update
which populates the starting and current priority fields.

In particular:

- Move the new calcInputValueAge function before the function which
  invokes it so it is consistent with the rest of the mempool code
- Double space after periods for consistency
- Correct the comments for calcInputValueAge to indiciate that inputs
  which are in the the memory pool count as zero toward the value age
  rather than the incorrect claim that that the overal input value age is
  zero when one of them does
- Rename endingPriority to currentPriority to match the RPC field and its
  actual function
- Make the comment about using zero when input transactions can't be found
  for some reason more accurate since there can be (and frequently is)
  more than one input transaction
2014-11-17 00:31:14 -06:00
Olaoluwa Osuntokun a49b0d05b3 Add the starting+current priority to getrawmempool. 2014-11-16 23:58:33 -06:00
Dave Collins c3065d32f4 Make use of the new btcchain MedianTimeSource.
This commit uses the new MedianTimeSource API in btcchain to create a
median time source which is stored in the server and is fed time samples
from all remote nodes that are connected.  It also modifies all call sites
which now require the the time source to pass it in.
2014-10-09 10:44:22 -05:00
Jonathan Gillham 1bbd1e9cba Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint after btcwire API change. 2014-10-01 16:34:30 +01:00
ortutay 139d9cb447 Implement verifymessage RPC. 2014-08-22 16:58:02 -07:00
David Hill e720e398a1 Mark getchaintips RPC command as unimplemented. 2014-08-12 11:33:07 -04:00
Josh Rickmar 790a4f5a6e Return nil for some spent gettxout outputs.
This change modifies the behavior of the gettxout RPC to match the
behavior of the reference client.  If a transaction output is spent by
a mined transaction, the handler will now return nil (JSON null).

While here, avoid indexing some slices multiple times, by creating a
local variable instead.
2014-07-24 15:02:07 -05:00
Olaoluwa Osuntokun 293d71e9c3 Implement gettxout rpc.
Use new error type defined in Roasbeef/btcjson@4dc9db809
2014-07-19 13:01:59 -05:00
Dave Collins 000691dc9e Implement BIP0061 reject handling (pver 70002).
This commit implements reject handling as defined by BIP0061 and bumps the
maximum supported protocol version to 70002 accordingly.

As a part of supporting this a new error type named RuleError has been
introduced which encapsulates and underlying error which could be one of
the existing TxRuleError or btcchain.RuleError types.

This allows a single high level type assertion to be used to determine if
the block or transaction was rejected due to a rule error or due to an
unexpected error.  Meanwhile, an appropriate reject error can be created
from the error by pulling the underlying error out and using it.

Also, a check for minimum protocol version of 209 has been added.

Closes #133.
2014-07-14 12:25:11 -05:00
David Hill 2f0cab1a48 Log accepted blocks via submitblock.
ok @davecgh
2014-07-14 11:08:07 -04:00
Dave Collins be7923a4ed Update to account for recent btcchain API changes. 2014-07-11 09:57:03 -05:00
Dave Collins bd7a100ebb Address a few more comments. 2014-07-10 09:43:03 -05:00
Dave Collins ffe0b09890 Seed random generator in RPC server during init.
Rather than reseeding the PRNG used throughout the RPC server on each
call, do it once during init.

Suggested by @jrick
2014-07-10 09:43:02 -05:00
Dave Collins 180f4ac0a2 Implement some BIP0023 getblocktemplate mutations.
This commit implements a portion of the mutations section of BIP0023.
In particular, it adds the mutable, mintime, maxtime, and noncerange keys
to the returned block template along with indicating support for the time,
transactions/add, prevblock, and coinbase/append mutations.  Also, the
addition of the mintime and maxtime fields imply support for the
time/decrement and time/increment mutations.  Further, if the caller
indicates the coinbasevalue capability, the coinbasetxn field will be
omitted thereby implying support for the coinbase and generation
mutations.

Closes #124.
2014-07-10 09:43:01 -05:00
Dave Collins 21050b4751 Implement BIP0023 getblocktemplate block proposals.
This commit implements block proposals as defined by BIP0023.

This is work towards #124.
2014-07-10 09:43:00 -05:00
Dave Collins db20f25ff7 Implement BIP0023 basic pool extensions support.
This commit implements the basic pool extension portion of the getblocktemplate
RPC as defined by BIP0023.

This is work towards #124.
2014-07-10 09:42:59 -05:00
Dave Collins fc5656894d Implement getblocktemplate long poll support.
This commit implements the long polling portion of the getblocktemplate
RPC as defined by BIP0022.  Per the specification, each block template is
returned with a longpollid which can be used in a subsequent
getblocktemplate request to keep the connection open until the server
determines the block template associated with the longpollid should be
replaced with a new one.

This is work towards #124.
2014-07-10 09:42:58 -05:00
Dave Collins eb7ecdcc22 Implement basic getblocktemplate BIP0022 support.
This commit implements the non-optional and template tweaking support for
the getblocktemplate RPC as defined by BIP0022.  This implementation does
not yet include long polling support.

This is work towards #124.
2014-07-10 09:42:57 -05:00
Dave Collins 6248dd5e5d Don't return a double pointer.
This commit has no effect on the effective functionality since Go
automatically deferences pointers, but there is no reason to have a
double indirection when returning the reply for getmininginfo.
2014-07-09 01:34:56 -05:00
Josh Rickmar 9e60210f18 Update for untyped btcutil consts.
ok @davecgh
2014-07-08 11:14:46 -05:00
Tomás Senart 2afc5a0af2 Use lighter atomic counters instead of mutexes
Where appropriate, it makes sense to use lighter weight atomic counters
instead of mutexes.
2014-07-07 13:04:39 -05:00
David Hill 2e029b1c3d Add gettxout to btcctl. 2014-07-04 10:50:57 -04:00
Josh Rickmar 5966a5230d Don't log error if getrawtransaction finds no tx.
ok @davecgh
2014-07-03 10:37:37 -05:00
David Hill 6f17ebc8cb Implement validateaddress.
validateaddress will simply return whether the given address is
valid or not.  For the full implementation, one should query
btcwallet instead.
2014-07-02 23:52:34 -04:00
Tomás Senart cc2c486791 Replace map[a]bool with map[a]struct{}
The later uses no memory storage for values and provides the same
functionality.
2014-07-02 19:06:29 -05:00
Tomás Senart a0f20007c5 golint -min_confidence=0.3 .
This commits removes a number of golint warnings. There is a class of
warnings which I can't fix due to unsufficient knowledge of the domain
at this point. These are listed here:

addrmanager.go:907:1: comment on exported method AddrManager.Attempt
should be of the form "Attempt ..."
addrmanager.go:1048:1: exported function RFC1918 should have comment or
be unexported
addrmanager.go:1058:1: exported function RFC3849 should have comment or
be unexported
addrmanager.go:1065:1: exported function RFC3927 should have comment or
be unexported
addrmanager.go:1073:1: exported function RFC3964 should have comment or
be unexported
addrmanager.go:1081:1: exported function RFC4193 should have comment or
be unexported
addrmanager.go:1089:1: exported function RFC4380 should have comment or
be unexported
addrmanager.go:1097:1: exported function RFC4843 should have comment or
be unexported
addrmanager.go:1105:1: exported function RFC4862 should have comment or
be unexported
addrmanager.go:1113:1: exported function RFC6052 should have comment or
be unexported
addrmanager.go:1121:1: exported function RFC6145 should have comment or
be unexported
addrmanager.go:1128:1: exported function Tor should have comment or be
unexported
addrmanager.go:1143:1: exported function Local should have comment or be
unexported
addrmanager.go:1228:2: exported const InterfacePrio should have comment
(or a comment on this block) or be unexported
discovery.go:26:2: exported var ErrTorInvalidAddressResponse should have
comment or be unexported
limits/limits_unix.go:19:1: exported function SetLimits should have
comment or be unexported
limits/limits_windows.go:7:1: exported function SetLimits should have
comment or be unexported
util/dropafter/dropafter.go:22:6: exported type ShaHash should have
comment or be unexported
util/dropafter/dropafter.go:38:2: exported const ArgSha should have
comment (or a comment on this block) or be unexported
util/dropafter/dropafter.go:128:5: exported var ErrBadShaPrefix should
have comment or be unexported
util/dropafter/dropafter.go:129:5: exported var ErrBadShaLen should have
comment or be unexported
util/dropafter/dropafter.go:130:5: exported var ErrBadShaChar should
have comment or be unexported
util/showblock/showblock.go:24:6: exported type ShaHash should have
comment or be unexported
util/showblock/showblock.go:46:2: exported const ArgSha should have
comment (or a comment on this block) or be unexported
util/showblock/showblock.go:163:1: exported function DumpBlock should
have comment or be unexported
util/showblock/showblock.go:211:5: exported var ErrBadShaPrefix should
have comment or be unexported
util/showblock/showblock.go:212:5: exported var ErrBadShaLen should have
comment or be unexported
util/showblock/showblock.go:213:5: exported var ErrBadShaChar should
have comment or be unexported
2014-07-02 11:01:56 -05:00
Tomás Senart 84fa553b65 Split imports into logical groups 2014-07-02 15:56:41 +02:00
Dave Collins 767caaa6ae Make hex decoding consistent in RPC handlers.
The hex package requires an even number of characters in hex encoded
strings.  Some of the handlers already prepended a zero if necessary to
make this condition true, however other did not.  This commit extends this
functionality to all handlers and also makes the error return consistent.

ok @jrick
2014-07-01 20:39:31 -05:00
Dave Collins 1db0eb4fec Update for recent btcjson changes.
This commit updates the types to match the recent changes to the btcjson
result types.
2014-06-29 16:37:21 -05:00
Dave Collins 0c9c005c33 Modify NewBlockTemplate to accept nil pay addr.
There are certain cases such as getblocktemplate which allow external
callers to be repsonsible for creating their own coinbase to replace the
generated one.  By allowing the pay address to be nil in such cases, the
need to specify mining addresses via --miningaddr can be avoided thereby
leaving the payment address management up to the caller.
2014-06-27 14:16:08 -05:00
Dave Collins d40cff64b0 Expose a close ntfn channel to all RPC handlers.
This commit modifies the RPC server such that all handlers now receive a
channel which will be notified when a client disconnects.  This
notification can then be used to stop long-running operations early when a
client disconnects.

This capability was already present for websocket clients, but this commit
exposes it to standard HTTP clients as well.
2014-06-27 11:58:47 -05:00
Dave Collins 48c6806b24 Update for btcchain ProcessBlock behavior flags.
ok @jrick
2014-06-26 17:18:05 -05:00
Dave Collins 289efbdea9 Update for recent btcjson API changes. 2014-06-16 14:44:36 -05:00
Dave Collins eee338cbe3 Update mining-related RPC handlers for new code.
Now that btcd support CPU mining, update the getgenerate, setgenerate,
gethashespersec, and getmininginfo RPC handlers to return the appropriate
information.

Also, remove the various extra help addenda about btcd not supporting
mining since it is no longer true.
2014-06-12 12:06:26 -05:00
Dave Collins e25b644d3b Implement a built-in concurrent CPU miner.
This commit implements a built-in concurrent CPU miner that can be enabled
with the combination of the --generate and --miningaddr options.  The
--blockminsize, --blockmaxsize, and --blockprioritysize configuration
options wich already existed prior to this commit control the block
template generation and hence affect blocks mined via the new CPU miner.

The following is a quick overview of the changes and design:

- Starting btcd with --generate and no addresses specified via
  --miningaddr will give an error and exit immediately
- Makes use of multiple worker goroutines which independently create block
  templates, solve them, and submit the solved blocks
- The default number of worker threads are based on the number of
  processor cores in the system and can be dynamically changed at
  run-time
- There is a separate speed monitor goroutine used to collate periodic
  updates from the workers to calculate overall hashing speed
- The current mining state, number of workers, and hashes per second can
  be queried
- Updated sample-btcd.conf file has been updated to include the coin
  generation (mining) settings
- Updated doc.go for the new command line options

In addition the old --getworkkey option is now deprecated in favor of the
new --miningaddr option.  This was changed for a few reasons:

- There is no reason to have a separate list of keys for getwork and CPU
  mining
- getwork is deprecated and will be going away in the future so that means
  the --getworkkey flag will also be going away
- Having the work 'key' in the option can be confused with wanting a
  private key while --miningaddr make it a little more clear it is an
  address that is required

Closes #137.

Reviewed by @jrick.
2014-06-12 12:05:32 -05:00
David Hill a992b48705 Add missing rpc commands and mark as unimplemented. 2014-06-11 10:46:19 -04:00
Dave Collins 3266bf6a8d Convert to use gorilla websockets package.
Also, since the new websoscket package allows the message type to be set
independently from the type of the variable, remove the casts between
strings and []byte in the websocket read/write paths.  This avoids extra
copies thereby reducing the garbage generated.

Closes #134.
2014-06-07 01:34:33 -05:00
David Hill bf48a97b0d Use NewReader instead of NewBuffer.
NewReader is slightly faster, but more importantly, ensures that the
data is read-only.
2014-06-05 14:00:22 -04:00
Dave Collins 605eb7f4b4 Add a simulation test network via --simnet param.
This commit, along with recent commits to btcnet and btcwire, expose a new
network that is intended to provide a private network useful for
simulation testing.  To that end, it has the special property that it has
no DNS seeds and will actively ignore all addr and getaddr messages.  It
will also not try to connect to any nodes other than those specified via
--connect.  This allows the network to remain private to the specific
nodes involved in the testing and not simply become another public
testnet.

The network difficulty is also set extremely low like the regression test
network so blocks can be created extremely quickly without requiring a lot
of hashing power.
2014-05-29 15:10:12 -05:00
Dave Collins 252c022644 Convert to default net ports provided by btcnet.
ok @jrick
2014-05-29 12:47:08 -05:00
Josh Rickmar 74303966c0 Updates for btcutil and btcscript's btcnet conversion.
ok @davecgh
2014-05-27 17:44:55 -05:00
Josh Rickmar bcc78565fd Initial pass at updating to btcnet.
This change modifies the params struct to embed a *btcnet.Params,
removing the old parameter fields that are handled by the btcnet
package.

Hardcoded network checks have also been removed in favor of modifying
behavior based on the current active net's parameters.

Not all library packages, notable btcutil and btcchain, have been
updated to use btcnet yet, but with this change, each package can be
updated one at a time since the active net's btcnet.Params are
available at each callsite.

ok @davecgh
2014-05-23 01:02:14 -05:00