Commit Graph

440 Commits

Author SHA1 Message Date
Dave Collins
0536ed4db6
blockchain: Combine ErrDoubleSpend & ErrMissingTx.
This replaces the ErrDoubleSpend and ErrMissingTx error codes with a
single error code named ErrMissingTxOut and updates the relevant errors
and expected test results accordingly.

Once upon a time, the code relied on a transaction index, so it was able
to definitively differentiate between a transaction output that
legitimately did not exist and one that had already been spent.

However, since the code now uses a pruned utxoset, it is no longer
possible to reliably differentiate since once all outputs of a
transaction are spent, it is removed from the utxoset completely.
Consequently, a missing transaction could be either because the
transaction never existed or because it is fully spent.

Also, while here, consistently use the LookupEntry function on the
UtxoView instead of directly accessing the internal map as intended.
2018-02-21 14:01:05 -06:00
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
Donald Adu-Poku
a0438c81c3 rpcserver: add batched request support (json 2.0) 2018-02-13 17:12:08 -06:00
Donald Adu-Poku
952b20e216 rpcserver: add sweepaccount to the wallet list of commands. (#1028) 2018-02-13 12:16:24 -05:00
Dave Collins
31f11b26b2
blockchain: Explicit block fetch semantics.
This makes the semantics of block fetching much more explicit by
introducing a new function named fetchMainChainBlockByHash which only
attempts to the load a block from the main chain block cache and then
falls back to the database.  While currently only blocks in the main
chain are in the database, the intention is for future commits to
allow the database to house side chain blocks as well, so having clearly
defined semantics will help make that transition easier to verify.

While here, it also renames {f,F}etchBlockFromHash to {f,F}etchBlockByHash
to be consistent with the naming used by the other existing functions
and updates the comments to better describe the function semantics.
2018-01-31 17:01:30 -06:00
Dave Collins
20a8ccc27b
blockchain: Use hash values in structs.
This modifies the BestState struct in the blockchain package to store
hashes directly instead of pointers to them and updates callers to deal
with the API change in the exported BestState struct.

In general, the preferred approach for hashes moving forward is to store
hash values in complex data structures, particularly those that will be
used for cache entries, and accept pointers to hashes in arguments to
functions.

Some of the reasoning behind making this change is:

- It is generally preferred to avoid storing pointers to data in cache
  objects since doing so can easily lead to storing interior pointers into
  other structs that then can't be GC'd
- Keeping the hash values directly in the structs provides better
  cache locality
2018-01-30 13:37:26 -06:00
Dave Collins
4d20cc1217
stake/multi: Don't return errors for IsX functions.
This modifies the IsSStx, IsSSGen, and IsSSRtx functions to only return
a bool and introduces CheckSStx, CheckSSGen, and CheckSSRtx to return
the actual error as needed by consensus.

This is being done because "is" functions are much nicer to use when
they don't return an error and the callers that use them almost never
care why they aren't of the type, they just want to determine if they
are.  In the few cases where the caller does care, they can use of the
new check functions.

While here, also update the comments to call out what the more common
names for the transaction types are and to add comments to the test
functions for consistency.

Finally, it updates all callers in the repo accordingly.
2018-01-30 10:20:12 -06:00
Dave Collins
cac5c152ae
blockchain: Reconstruct headers from block nodes.
This modifies the block node structure to include extra fields needed to
be able to reconstruct the block header from a node, and exposes a new
function from chain to fetch the block headers which takes advantage of
the new functionality to reconstruct the headers from memory when
possible.  Finally, it updates both the p2p and RPC servers to make use
of the new function.

This is useful since many of the block header fields need to be kept in
order to form the block index anyways and storing the extra fields means
the database does not have to be consulted when headers are requested if
the associated node is still in memory.
2018-01-29 11:41:25 -06:00
Dave Collins
fc102faefa
blockchain: Accept header in CheckProofOfWork.
This modifies the CheckProofOfWork function to accept a block header
instead of an entire block since there is no reason to force the caller
to have access to a full block when only the header is required.
2018-01-19 14:16:51 -06:00
Dave Collins
35b6f066c2
rpcserver: Do not rebroadcast stake transactions.
This modifies the sendrawtransaction handler to avoid adding stake
transactions to the rebroadcast logic since they should not be
perpetually rebroadcast without special handling to remove them under
certain circumstances other than showing up in a block.

This is particularly applicable to votes which are only valid for a
specific block and are time sensitive, but it also applies to ticket
purchases which are only valid for the duration of a stake difficulty
interval, and revocations which could be invalidated in a reorg due to
the associated missed or expired ticket being resurrected in a reorg.
2018-01-17 16:32:07 -06:00
Donald Adu-Poku
36c6c7f46e rpcserver: assert network for validateaddress rpc. 2018-01-09 21:03:04 -06:00
Donald Adu-Poku
69063fa5f3 rpcserver: remove redundant checks in blockTemplateResult. 2017-12-21 19:44:40 -06:00
jolan
fd857d5b53 rpcserver: skip cert create when RPC is disabled 2017-12-16 09:48:40 -06:00
Donald Adu-Poku
3b49d5aafd dcrjson: update handleSendRawTransaction error handling. (#939)
this adds ErrRPCDuplicateTx for rejected duplicate tx errors.
2017-12-08 09:04:53 -05:00
David Hill
fc31a0b39e multi: remove unused funcs and vars 2017-12-07 21:46:25 -06:00
David Hill
b13f5dfbda travis: add ineffassign linter 2017-12-01 09:14:04 -05:00
Donald Adu-Poku
66bf35020a rpc: Add localaddr and relaytxes to getpeerinfo 2017-11-29 22:21:17 +00:00
jolan
664ccfcc63 rpcserver: skip generating certs when nolisten set 2017-11-28 12:47:26 -06:00
Donald Adu-Poku
06468ffcfa rpcserver: avoid nested decodescript p2sh addrs 2017-11-28 17:46:41 +00:00
detailyang
3f3174c987 rpcserver: nil pointer dereference when submit orphan block 2017-10-26 21:21:50 +08:00
David Hill
d27429061b rpcserver: check for error in getwork request. (#898)
This checks the error for UpdateBlockTime.
2017-10-13 14:23:11 -04:00
David Hill
ca452564b3 Use upstream jrick/bitset (#899)
... since no local changes exist.
2017-10-13 09:47:26 -04:00
Josh Rickmar
6842aa006d Merge remaining dcrutil code into a dcrd package.
This merge commit adds the following code from the
github.com/decred/dcrutil package into a new
github.com/decred/dcrd/dcrutil package:

* Address handling
* Amount type
* AppDataDir func
* bitflags functions
* Block wrapper type
* Hash160 func
* Tx wrapper type
* WIF type

as well as all tests for this code.

The old github.com/decred/dcrutil/hdkeychain package has also been
merged and moved to github.com/decred/dcrd/dcrutil/hdkeychain.

dcrd packages have been updated to use the new packages and the dep
files have been updated for this change.
2017-10-11 22:06:36 -04:00
Josh Rickmar
27981a5a7d Move self signed certificate code into certgen package.
Use this package instead of relying on dcrutil certificate generation
functions.
2017-10-10 17:23:38 -04:00
Jonathan Chappelow
1eef90fb73 rpcserver: Fix empty ssgen verbose results. 2017-10-04 04:53:56 -05:00
Donald Adu-Poku
f11fac8134 multi: update stakebase tx vin[0] structure.
modifications to the stakebase tx vin[0] required adding a stakebase
field to Vin and VinPrevOut structs as well as updating the
rpc documentation for the affected calls.
2017-09-23 03:24:55 -05:00
Donald Adu-Poku
c4d1509a12 rpcserver: for searchrawtransactions skip first input for vote tx. 2017-09-23 03:24:55 -05:00
Donald Adu-Poku
fd924aa8f6 rpcserver: return rule error on rejected raw tx 2017-09-14 11:33:29 -05:00
Alex Yocom-Piatt
3384dd195b rpcserver: check whether ticketUtx was found (#824) 2017-08-18 14:27:21 -05:00
Dave Collins
fce24223cd
multi: Separate tx serialization type from version.
Decred's serialized format for transactions split the 32-bit version
field into two 16-bit components such that the upper bits are used to
encode a serialization type and the lower 16 bits are the actual
transaction version.

Unfortunately, when this was done, the in-memory transaction struct was
not also updated to hide this complexity, which means that callers
currently have to understand and take special care when dealing with the
version field of the transaction.

Since the main purpose of the wire package is precisely to hide these
details, this remedies the situation by introducing a new field on the
in-memory transaction struct named SerType which houses the
serialization type and changes the Version field back to having the
desired semantics of actually being the real transaction version.  Also,
since the maximum version can only be a 16-bit value, the Version field
has been changed to a uint16 to properly reflect this.

The serialization and deserialization functions now deal with properly
converting to and from these fields to the actual serialized format as
intended.

Finally, these changes also include a fairly significant amount of
related code cleanup and optimization along with some bug fixes in order
to allow the transaction version to be bumped as intended.

The following is an overview of all changes:
- Introduce new SerType field to MsgTx to specify the serialization type
- Change MsgTx.Version to a uint16 to properly reflect its maximum
  allowed value
- Change the semantics of MsgTx.Version to be the actual transaction
  version as intended
- Update all callers that had special code to deal with the previous
  Version field semantics to use the new semantics
- Switch all of the code that deals with encoding and decoding the
  serialized version field to use more efficient masks and shifts
  instead of binary writes into buffers which cause allocations
- Correct several issues that would prevent producing expected
  serializations for transactions with actual transaction versions that
  are not 1
- Simplify the various serialize functions to use a single func which
  accepts the serialization type to reduce code duplication
- Make serialization type switch usage more consistent with the rest of
  the code base
- Update the utxoview and related code to use uint16s for the
  transaction version as well since it should not care about the
  serialization type due to using its own
- Make code more consistent in how it uses bytes.Buffer
- Clean up several of the comments regarding hashes and add some new
  comments to better describe the serialization types
2017-08-07 14:10:27 -05:00
Donald Adu-Poku
3bf1b0a31e dcrjson: Remove unused cmds & types. 2017-08-05 17:51:48 -05:00
Donald Adu-Poku
db727aeeb6 multi: Update DecodeAddress function signature 2017-07-21 23:41:24 -05:00
David Hill
a9234850e7 remove deadcode 2017-07-17 15:06:47 -05:00
Josh Rickmar
5503effe38 rpcserver: Fix gettxout includemempool handling.
When the includemempool parameter is set to true, transactions in the mempool
should be additionally considered.  However, the previous code used a buggy
implementation which would return an error if this parameter was set and the
transaction was not found in the mempool, without ever querying a mined utxo.
2017-07-01 16:57:55 +00:00
Josh Rickmar
ce4b77d3d9 all: Remove seelog logger.
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-20 10:58:10 -04:00
Alex Yocom-Piatt
9285b49550 dcrjson: add RevokeTicketsCmd (#726) 2017-06-13 12:00:14 -04:00
David Hill
2a2ab090ec dcrjson: getblocksubsidy support. (#679) 2017-05-23 13:09:49 -04:00
Josh Rickmar
0d48ca0105 rpcserver: Bump semver for existsmissedtickets addition. 2017-05-17 12:07:10 -04:00
Josh Rickmar
39734da2e4 rpcserver: Add existsmissedtickets RPC.
This RPC works identically to the existsexpiredtickets RPC but checks
for missed rather than expired tickets.
2017-05-17 10:24:56 -04:00
Josh Rickmar
489e1c4338 dcrjson: Remove accountfetchaddresses support.
This RPC was removed from wallet.
2017-05-04 13:26:22 -04:00
David Hill
ecd27f0d4d rpcserver: Support larger block sizes. 2017-04-28 21:48:27 -05:00
Dave Collins
2dfb055f93
rpcserver: Disable getblocktemplate.
This disables the getblocktemplate RPC handler since it does not at all
work as intended.  Fixing it is going to be a larger effort, so just
disable it until it can be properly implemented.
2017-04-28 11:14:34 -05:00
Dave Collins
b2d479ad38
rpcserver: Return handler errors to RPC client.
Only the first parameter to the rpcInternalError function is returned to
RPC clients, so any errors that originate in the handlers need to be
passed as the first parameter.

The second context parameter is to allow additional context to be added
to errors coming from underlying calls.  There is no additional context
for errors generated by the RPC handlers themselves.
2017-04-28 10:58:44 -05:00
Dave Collins
734684d288
multi: Implement stake difficulty change and vote.
This implements a new stake difficulty algorithm along with a voting
agenda for all networks to change and a comprehensive set of tests.  It
also implements estimation using the new algorithm for the
estimatestakediff RPC.

The following is an overview of the changes:

- Add new agenda to vote on changing the stake difficulty algorithm to
  all networks
  - The version on mainnet is version 4
  - The version on testnet and simnet is version 5
- Modifies the stake difficulty calculation function to calculate the
  difficulty based on the result of the vote
- Modifies the stake difficulty estimation function to calculate the
  difficulty based on the result of the vote
- Makes the stake difficulty estimation function concurrent safe
  - Calls it directly from the RPC server instead of going through block
    manager
  - Removes no longer needed code from the block manager
- Generate new version blocks and reject old version blocks after a
  super majority has been reached
  - New block version on mainnet is version 4
  - New block version on testnet and simnet is version 5
- Add tests for the supply estimation used in the new algorithm
- Add tests for the new algorithm calculations
- Add tests for the estimation based on the new algorithm
2017-04-26 13:00:28 -05:00
Josh Rickmar
f23ca04f95 rpcserver: Use a real value for fee estimates.
More dependencies on the global config in main isn't great but the
actual value in the mempool policy isn't exported at this time.
2017-04-24 18:03:51 -04:00
Dave Collins
05d8456d3e
multi: Rename vote choice IsIgnore to IsAbstain.
This renames the chaincfg parameter for the vote choice which represents
an abstaining vote to be named IsAbstain instead of IsIgnore since that
more accurately describes its intent and behavior.

It also updates the RPC server choice result field for isignore to be
named isabstain to match and bumps the major version accordingly.

Finally, it renames other internal variables which make use of the
choice to include the word abstain as well for clarity and renames a
couple of other internal variables.
2017-04-24 16:17:27 -05:00
Josh Rickmar
ff07aac47f dcrjson: Add getvotechoices/setvotechoice types.
Remove all types for get/setticketvotebits.  These RPCs are being
removed from dcrwallet (which will no longer support saving per-ticket
vote bits).
2017-04-11 12:04:59 -04:00
Marco Peereboom
f5439c31c9 rpcserver: always reply with an RPC error.
Ensure that all errors return an RPC error.  Try to match the type as
well.  Also some miscellaneous clean ups.
2017-04-04 07:47:29 -05:00
David Hill
99d04eea40 Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
David Hill
6d9c4b360e gometalinter: use --vendor to skip ./vendor/
While here, clean up gosimple and unconvert rules, leaving gosimple
disabled due to API changes between go 1.7 and 1.8.
2017-03-18 14:22:53 -04:00