Commit graph

207 commits

Author SHA1 Message Date
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
Dave Collins 342d0a536f Correct error message in handleGetWorkSubmission.
Found by go vet.
2014-05-22 23:48:02 -05:00
Dave Collins b6af0a7a53 Remove extra return statement found by go vet.
The return statement was unreachable and thus this change has no
effect on functionality.
2014-05-22 23:46:41 -05:00
Dave Collins 5b376b3b5e Expose getcurrentnet and getbestblock to HTTP POST.
This commit makes the getcurrentnet and getbestblock RPCs available to
clients making HTTP POST requests.

Closes #127.
2014-05-11 02:21:27 -05:00
Dave Collins 6a325f4c6a Improve getwork interaction with regtest mode.
Ordinarily, getwork will return an error if btcd is not connected to any
other peers.  This commit relaxes that requirement when running in
regression test mode since it is useful for development purposes.

While here, also improve check which returns an error from getwork is not
current to exclude the check when the best chain height is zero since the
code never believes it is current when at height 0.
2014-05-08 19:47:50 -05:00
Dave Collins 47e65634a7 Use btcd pver instead of wire pver in RPC encoding.
Along the same lines as the previous commit, the RPCs that return
serialized data structures should use the max protocol version btcd
supports as opposed to the maximum protocol version etcwire supports.
2014-05-07 11:33:32 -05:00
Dave Collins fd025a7368 Use btcd pver instead of wire pver in getinfo RPC.
The getinfo RPC should return the max protocol version btcd supports as
opposed to the maximum protocol version btcwire supports.  Currently they
are both the same value, so there is no issue.  However, they will not
always be the same.
2014-05-07 10:30:58 -05:00
Dave Collins a4a79387cc Add support for getmininginfo RPC.
Closes #126.
2014-05-04 14:34:25 -05:00
Dave Collins 4178c36dc3 Populate connections field in getinfo RPC.
The JSON object returned from the getinfo RPC contains a connection count
field that was not being populated.
2014-05-03 14:07:08 -05:00
Dave Collins 0a7543516c Update block manager chainstate for all sources.
This commit updates the block manager's local chain state when a block
processed by submitting it directly to the block manager as opposed to
only when it comes from the network.

Also, it modifies the submitblock RPC to use the concurrent safe block
manager process block instead of the unsafe btcchain version.

The combination of these two fixes ensure the internal block manager chain
state is properly synced with the actual btcchain state regardless of how
blocks are added.
2014-05-02 23:02:10 -05:00
Dave Collins 92ca0e92c0 Implement getwork RPC.
This commit adds full support for the getwork RPC which can be used to
support external mining through applications such as cgminer.

Closes #125.
2014-05-01 10:52:28 -05:00
Dave Collins bdaa5f7f8d Set RPC content type to applicaton/json.
Closes #121.
2014-04-24 23:20:13 -05:00
David Hill 8a322e4792 Bypass rate limiter for sendrawtransaction.
ok @davecgh
2014-04-23 07:45:56 -04:00