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.
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.
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
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.
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.
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.
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.
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.
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.
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%
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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