Commit Graph

4365 Commits

Author SHA1 Message Date
Dave Collins
d1be5fec67
indexers: Remove unused func. 2019-04-02 10:50:51 -05:00
Donald Adu-Poku
e9b2b4854f mining: fix scheduled template regen.
This fixes a case where a block with five votes
immediately triggers a regen (as it should) but also
schedules another regen in a second.
2019-04-01 16:38:54 -05:00
Dave Collins
e570fb8d75
txscript: Remove checks for impossible conditions.
This removes a couple of checks for impossible conditions found by the
staticcheck linter.  In the case of executeOpcode, bytes are always >= 0
and, similarly for SigCache.Add, uint are always >= 0.
2019-04-01 14:34:51 -05:00
Dave Collins
51852570e2
main: Convert signal handling to use context.
This converts the signal handling and dcrdMain function to use a context
with cancellation instead of a separate interrupt channel.  It does not
really make much of a difference yet, but the intent is to simplify the
various subsystems in future commits by refactoring them to make use of
the context versus manually handling start and stop in each subsystem.
2019-04-01 14:09:07 -05:00
Dave Collins
074d50f49b
main/rpctest: Update for hdkeychain/v2.
This updates the rpctest package and main module to use version 2 of the
hdkeychain module.

The following is a summary of changes:

- Update all imports to use hdkeychain/v2
- Update module requirements to include new module and remove no longer
  needed old versions
- Add an override for the v2 module so CI always builds with the latest
  code
2019-04-01 13:19:52 -05:00
Dave Collins
b39c637145
server: Remove unused dynamicTickDuration func. 2019-04-01 12:49:38 -05:00
Dave Collins
20caedc344
server: Remove unused ScheduleShutdown func. 2019-04-01 12:49:34 -05:00
Dave Collins
733b3588d6
main: Rework windows service sod notification.
The way that shutdown is handled was modified long ago, but it appears
that the windows service code was not updated fully for the changes.  In
particular, the server instance is no longer used by the service at all.
Rather the only information needed is the parsed configuration in order
to log the start of day details.

Consequently, this reworks the windows service start of day code to read
a buffered channel that receives the parsed configuration instead of the
server and modifies the dcrdMain function to no longer require the
channel to be specified in order to simplify it for eventual context
handling.
2019-04-01 11:38:38 -05:00
Dave Collins
6875c3fde9
mining: Improve template key handling.
This factors out the code which deals with generating a unique block
template key to a separate function, modifies it to only be comprised of
the merkle root + timestamp, and renames the associated variables
accordingly.  The separate function is useful because work submission
will ultimately need to create the same key.

The rationale for switching to only using the merkle root + timestamp is
as follows:

- It is more efficient to use smaller keys
- The combination is guaranteed to be unique for every template so long
  as there are no more than one per second generated with the exact same
  txns (which is already the case with the inclusion of the stake merkle
  root in the key too)
- There are future plans to combine the stake root and merkle roots into
  the merkle root field and repurpose the stake root

Finally, the naming is also being changed from ID to key because the
name templateID already has a distinct meaning in the rpcserver code in
how it applies to long polling clients and it is better to avoid
potential confusion.
2019-04-01 11:12:30 -05:00
Dave Collins
903be52b17
mining: Remove unnecessary notify goroutine.
This modifies the code which notifies subscribed clients about a new
block template to avoid creating an unnecessary goroutine since the
channel is single use and intentionally buffered to ensure the sender
can't block.
2019-04-01 10:35:30 -05:00
David Hill
056cdd9cb4 mempool: drop container/list for simple FIFO 2019-03-31 19:42:23 -05:00
Donald Adu-Poku
8f5019e083 multi: add BgBlkTmplGenerator.
BgBlkTmplGenerator represents the background process that
generates block templates and notifies all subscribed clients
on template regeneration. It generates new templates based
on mempool activity for vote and non-vote transactions and
the time elapsed since last template regeneration.

This also adds a template pool to the background block
generator for recreating submitted blocks.
2019-03-30 16:08:43 -05:00
Dave Collins
c1cf192f03
docs: Update for hdkeychain v2 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version
2019-03-29 11:40:35 -05:00
Dave Collins
1a0b0b662f
release: Introduce hdkeychain v2 module. 2019-03-29 11:40:27 -05:00
Dave Collins
71b02b9d89
hdkeychain: Use mock net params in tests.
This implements a mock network params struct that implements the new
interface and modifies the test code to make use of the mock params
instead of chaincfg.  This completely decouples the tests, with the
exception of the example code, from chaincfg and therefore any updates
to it such as introducing new test networks will not require changes to
the tests.
2019-03-29 11:26:40 -05:00
Dave Collins
a8960587fa
hdkeychain: Introduce NetworkParams interface.
This introduces a new interface named NetworkParams and updates the
functions that currently take a pointer to a chaincfg.Params struct to
accept the interface instead.

This removes the tight coupling between the two packages at the API
boundary and allows callers to easily provide custom values without
having to create and register and entire chaincfg network as previous
required.

Finally, the README.md is updated accordingly.
2019-03-29 11:26:40 -05:00
Dave Collins
4ea06ed7df
hdkeychain: Don't rely on global state.
This refactors the the extended key internals to keep track of the
public and private network ids instead of a version slice in order to
remove the need to rely on global state for looking up the extended
public key ID for the network.

Since the public and private network ids are 8 bytes and the version
slice was 24 bytes, this also has the nice side effect of slightly
optimizing the performance, particularly in the private to public case,
as shown by the following benchmark comparison:

benchmark                 old ns/op   new ns/op   delta
--------------------------------------------------------
BenchmarkDeriveHardened   5795        5600        -3.36%
BenchmarkDeriveNormal     6585        6263        -4.89%
BenchmarkPrivToPub        137         118         -13.87%
BenchmarkDeserialize      17618       17618       +0.00%
BenchmarkSerialize        21672       21061       -2.82%

benchmark                 old bytes   new bytes   delta
--------------------------------------------------------
BenchmarkDeriveHardened   1552        1536        -1.03%
BenchmarkDeriveNormal     1601        1585        -1.00%
BenchmarkPrivToPub        128         112         -12.50%
BenchmarkDeserialize      1640        1624        -0.98%
BenchmarkSerialize        1712        1712        +0.00%
2019-03-29 11:26:39 -05:00
Dave Collins
da25049c71
hdkeychain: Require network on decode extended key.
This modifies NewKeyFromString to accept the required network parameters
for the provided encoded extended key and introduces a new error to
indicate the provide extended key is for the wrong network.

This means that NewKeyFromString will now return ErrWrongNetwork if the
extended key being decoded is not for the provided network.  This
differs from the previous behavior relied on globally-registered
networks in chaincfg to determine which network the encoded key was for
followed by requiring the caller to check upon if the key was for the
specific network it desired upon return.

Finally, it removes the no longer necessary IsForNet method and updates
the documentation accordingly.
2019-03-29 11:26:39 -05:00
Dave Collins
e1125f00fa
hdkeychain: Use locally-scoped netparams in tests.
This modifies the tests to use locals for the network parameter
references to make it easier to mock the parameters in the future.
2019-03-29 11:26:38 -05:00
Dave Collins
6aa6a73591
hdkeychain: Remove SetNet method.
This removes the SetNet method from the ExtendedKey struct since its use
in practice could lead to subtle bugs due to the fact that changing the
network after keys have already been derived and then deriving more keys
will not result in the same derivation as starting with the target
network to begin with.  It is better to simply avoid the possibility of
misuse.

It also removes the related tests.
2019-03-29 11:26:38 -05:00
Dave Collins
a347b76ab3
hdkeychain: Remove Address method.
This removes the Address method from the ExtendedKey struct since
ultimately there will be multiple address types and therefore it no
longer makes sense to return an address which probably isn't the one the
caller actually needs.  Instead, the caller can make use of the ECPubKey
method to obtain the public key and create the desired address from
there.

It also removes the related tests, updates the example to show the
address conversion process for a standard pay-to-pubkey-hash address,
and updates the README.md and doc.go files accordingly.
2019-03-29 11:26:37 -05:00
Dave Collins
3e33f259aa
hdkeychain: Consolidate tests into package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and makes it
more consistent with the rest of the code base.
2019-03-29 11:26:36 -05:00
Dave Collins
3d41c62006
hdkeychain: Correct docs key examples.
This corrects the serialized extended key examples in the package
documentation.  This appears to have been missed when porting the code.
2019-03-29 11:26:36 -05:00
Dave Collins
b05edc64a9
hdkeychain: Correct benchmark extended key.
This corrects the master extended private key used in the benchmarks for
Decred.  This appears to have been missed when porting the code.
2019-03-29 11:26:35 -05:00
Dave Collins
23d73d37ca
release: Freeze version 1 hdkeychain module.
This serves as the final release of version 1 of the hdkeychain module.
All future releases will be moving to version 2 of the module.

Since there have been no changes since the last release version, this
merely removes the hdkeychain override in the root module and updates it
so building the software will still produce binaries based on the v1
module until the v2 module is fully released.
2019-03-29 11:26:35 -05:00
David Hill
99cc7266b6 server: limit getminingstate requests 2019-03-29 01:11:27 -05:00
Dave Collins
1cfba728d8
config: Cleanup and simplify network info parsing.
This simplifies and cleans up the initial network information parsing
which was recently added by replacing the networks map and all of the
unnecessary error handling that introduced with concrete supported
network definitions and directly updating their fields accordingly.

It also avoids a bunch of unnecessary conditional branching by setting
the flags to the results of the conditions directly.

Finally, it corrects the logic for determining if interface is limited
since that is currently only the case when the other interface has no
available listeners.
2019-03-28 23:32:11 -05:00
Donald Adu-Poku
ad3c180abb config: Parse network interfaces.
This adds config helpers for parsing network interface
states based on the config parameters set. Work towards getnetworkinfo implementation.
2019-03-28 22:54:21 -05:00
David Hill
b72b6ca714 server: return on outbound peer creation error 2019-03-28 21:10:43 -05:00
David Hill
06e03bed9f blockmanager: use local var for the request queue
Instead of waiting for a second inv to process what the first inv
may have requested, just send it all at once.  This allows dropping
of a request queue for each server peer.
2019-03-28 21:10:12 -05:00
David Hill
02d888d930 blockchain: drop container/list 2019-03-28 21:09:45 -05:00
Dave Collins
f71b0d246f
txscript: Cleanup opcode removal by data tests.
This converts the test definitions for TestRemoveOpcodeByData to make
use of mustParseShortForm which improves the readability and
construction of the tests as well as makes them more consistent with the
rest of the code base.

It also cleans up the recently added stake tx tests so that they don't
exceed col 80 and sets their names to indicate they are p2pkh and p2sh
forms.
2019-03-28 16:56:33 -05:00
Dave Collins
25deee6195
blockchain: Allow named blocks in chaingen harness.
This introduces two new functions on the chaingen harness, named
AcceptBlock and RejectBlock, which allow ensuring a named block is
accepted or rejected, respectively, and redefines the existing Accepted
and Rejected functions which only deal with the tip block in terms of
the new functions.

It also renames Accepted and Rejected to AcceptTipBlock and
RejectTipBlock, respectively.

The motivation for this change is to make it easier to test future code
which will allow processing of headers and blocks independently as well
as processing blocks out of order so long as their headers are already
known.
2019-03-28 16:55:57 -05:00
David Hill
213be705bc peer: pendingMsgs is a FIFO 2019-03-28 16:54:20 -05:00
David Hill
699c0ad23f peer: invSendQueue is a FIFO 2019-03-28 16:54:20 -05:00
Hamid
8e24235d7a wire: Add tests for MsgGetCFTypes.
This adds standard tests for MsgGetCFTypes to make sure the API
works correctly.
2019-03-28 11:09:24 -05:00
Josh Rickmar
04801db2c5 promptsecret: Add -n flag to prompt multiple times
This is useful for dcrctl commands which take multiple secrets, such as
walletpassphrasechange.
2019-03-28 10:24:53 -05:00
David Hill
d8c1963797 stake: drop txscript.DefaultScriptVersion usage
while here, fix incorrect comment and remove magic bits
2019-03-27 20:49:53 -05:00
Hamid
c6f9186083 dcrutil: Fix NewTxDeepTxIns implementation.
This fixes NewTxDeepTxIns implementation. The current implementation
of NewTxDeepTxIns is wrong and has many issues. This commit fixes
this issues and adds tests for ensuring the API works correctly.
2019-03-26 15:36:14 -05:00
Dave Collins
6adbaa62ab
txscript: Make op callbacks take opcode and data.
This converts the callback function defined on the internal opcode
struct to accept the opcode and data slice instead of a parsed opcode as
the final step towards removing the parsed opcode struct and associated
supporting code altogether.

It also updates all of the callbacks and tests accordingly and finally
removes the now unused parsedOpcode struct.
2019-03-26 14:55:46 -05:00
Dave Collins
5059be93f0
txscript: Make executeOpcode take opcode and data.
This converts the executeOpcode function defined on the engine to accept
an opcode and data slice instead of a parsed opcode as a step towards
removing the parsed opcode struct and associated supporting code altogether.

It also updates all callers accordingly.
2019-03-26 14:55:45 -05:00
Dave Collins
fcb1f3a7a1
txscript: Remove unused parseScriptTemplate func.
Also remove tests associated with the func accordingly.
2019-03-26 14:55:45 -05:00
Dave Collins
ceb58f4767
txscript: Remove unused parsedOpcode.bytes func. 2019-03-26 14:55:44 -05:00
Dave Collins
861032aa1e
txscript: Remove unused unparseScript func.
Also remove tests associated with unparsing opcodes accordingly.
2019-03-26 14:55:43 -05:00
Dave Collins
cef80862d6
txscript: Remove unused parseScript func. 2019-03-26 14:55:43 -05:00
Dave Collins
d72f6d3003
txscript: Rename calcSignatureHashRaw func.
This renames the calcSignatureHashRaw to calcSignatureHash now that the
old version has been removed.
2019-03-26 14:55:42 -05:00
Dave Collins
2e082a8004
txscript: Remove unused calcSignatureHash func. 2019-03-26 14:55:41 -05:00
Dave Collins
c598f59151
txscript: Rename removeOpcodeByDataRaw func.
This renames the removeOpcodeByDataRaw to removeOpcodeByData now that
the old version has been removed.
2019-03-26 14:55:41 -05:00
Dave Collins
bd040aea02
txscript: Remove unused removeOpcodeByData func. 2019-03-26 14:55:40 -05:00
Dave Collins
75c48ea8c7
txscript: Refactor engine to use raw scripts.
This refactors the script engine to store and step through raw scripts
by making using of the new zero-allocation script tokenizer as opposed
to the less efficient method of storing and stepping through parsed
opcodes.  It also improves several aspects while refactoring such as
optimizing the disassembly trace, showing all scripts in the trace in
the case of execution failure, and providing additional comments
describing the purpose of each field in the engine.

It should be noted that this is a step towards removing the parsed
opcode struct and associated supporting code altogether, however, in
order to ease the review process, this retains the struct and all
function signatures for opcode execution which make use of an individual
parsed opcode.  Those will be updated in future commits.

The following is an overview of the changes:

- Modify internal engine scripts slice to use raw scripts instead of
  parsed opcodes
- Introduce a tokenizer to the engine to track the current script
- Remove no longer needed script offset parameter from the engine since
  that is tracked by the tokenizer
- Add an opcode index counter for disassembly purposes to the engine
- Update check for valid program counter to only consider the script
  index
  - Update tests for bad program counter accordingly
- Rework the NewEngine function
  - Store the raw scripts
  - Setup the initial tokenizer
  - Explicitly check against version 0 instead of DefaultScriptVersion
    which would break consensus if changed
  - Check the scripts parse according to version 0 semantics to retain
    current consensus rules
  - Improve comments throughout
- Rework the Step function
  - Use the tokenizer and raw scripts
  - Create a parsed opcode on the fly for now to retain existing
    opcode execution function signatures
  - Improve comments throughout
- Update the Execute function
  - Explicitly check against version 0 instead of DefaultScriptVersion
    which would break consensus if changed
  - Improve the disassembly tracing in the case of error
- Update the CheckErrorCondition function
  - Modify clean stack error message to make sense in all cases
  - Improve the comments
- Update the DisasmPC and DisasmScript functions on the engine
  - Use the tokenizer
  - Optimize construction via the use of strings.Builder
- Modify the subScript function to return the raw script bytes since the
  parsed opcodes are no longer stored
- Update the various signature checking opcodes to use the raw opcode
  data removal and signature hash calculation functions since the
  subscript is now a raw script
  - opcodeCheckSig
  - opcodeCheckMultiSig
  - opcodeCheckSigAlt
2019-03-26 14:55:39 -05:00