Commit Graph

570 Commits

Author SHA1 Message Date
Dave Collins
318d81bc90
multi: Wrap errors for better errors.Is/As support.
This updates all remaining cases of unwrapped errors in fmt.Errorf calls
to wrap the underlying errors with the %w format verb to ensure they
work nicely with errors.Is and errors.As.
2023-08-25 16:31:11 -05:00
Dave Collins
70b399c9e4
build: Add dupword linter.
This adds the dupword linter to the list of linters and addresses a few
false positives it complains about.
2023-08-25 12:35:55 -05:00
Dave Collins
fc54d98b1e
multi: Remove a bunch of dup words in comments. 2023-08-23 14:13:51 -05:00
Dave Collins
7fe6d93b51
multi: Avoid range capture for Go 1.22 changes.
Go 1.22 is introducing a change to the way the range statement works
that is not entirely backward compatible.  In particular, the loop
variable is changing from one instance per loop to one instance per
iteration.

The existing semantics are well known and in order to ensure correct
behavior and avoid potential races that would otherwise result, the
current code typically opts for using ranges with an index and creating
a local that points into the array when the range variable needs to be
used as a pointer.

In addition, there are a few remaining cases that use the common
alternative approach of capturing the range variable through self
assignment.

Both approaches will work correctly when compiled with Go 1.22 as well
as older version of Go so long as the module versions are not bumped.

However, once the modules are updated to allow support of all features
introduced by go 1.22, the second approach of capturing the range
variable would no longer be needed and as a result would very likely
need to be removed to avoid vet/linter issues.  Unfortunately, the
consequence of that change would mean building the code with older
versions of Go would start to produce incorrect code.

The first approach of using a range index that is predominantly used
throughout the code does not have that potential pitfall as it works
equally well for all of the aforementioned cases.

Thus, in order to avoid any potential issues before they ever even have
a chance to arise, this updates the few remaining instances of the
second approach to the first one or to otherwise rework the code to
avoid the need altogether.
2023-07-31 11:36:52 -05:00
Dave Collins
38e1840e40
build: Add nilerr linter.
This adds the nilerr linter to the list of linters and addresses a few
false positives it complains about.
2023-07-24 12:18:37 -05:00
Dave Collins
3dc80cf238
build: Add CI support for test and module cache.
This makes use of the github actions cache to save and restore the Go
test and module caches.  This should result in faster CI runs since most
changes only affect a small number of tests.

It also updates the RPC integration tests to ensure the logs directory
is not in the source code dir so the go testing cache can be used.

Next, it renames the txscript module's data dir to testdata so go does
not treat it like a package.

Finally, it adds a script that stabilizes the timestamps on all files in
testdata directories when running the github action.  This is necessary
because the go testing cache logic uses the timestamps of all input
files when determining whether or not a test needs to be rerun and
github clones a fresh repo on every run which causes the timestamps of
the test data to change.
2023-06-19 14:18:30 -05:00
Dave Collins
19f8ff985b
txscript: Prepare v4.1.0.
This updates the txscript module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
txscript/v4.1.0.

The updated direct dependencies in this commit are as follows:

- github.com/dchest/siphash@v1.2.3
- github.com/decred/base58@v1.0.5
- github.com/decred/dcrd/chaincfg/chainhash@v1.0.4
- github.com/decred/dcrd/chaincfg@3.2.0
- github.com/decred/dcrd/crypto/blake256@v1.0.1
- github.com/decred/dcrd/crypto/ripemd160@v1.0.2
- github.com/decred/dcrd/dcrec@v1.0.1
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.3
- github.com/decred/dcrd/dcrec/secp256k1/v4@v4.2.0
- github.com/decred/dcrd/wire@v1.6.0

The updated indirect dependencies in this commit are as follows:

- github.com/agl/ed25519@v0.0.0-20170116200512-5312a6153412
- github.com/klauspost/cpuid/v2@v2.0.9
- lukechampine.com/blake3@v1.2.1

The full list of updated dependencies since the previous txscript/v4.0.0
release are the same as above.

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2023-06-08 10:59:58 -05:00
Jonathan Chappelow
32b3ad1f33 txscript: remove obsolete requireMinimal comment
The requireMinimal flag for MakeScriptNum was removed in
84b65d049b but the description was left
in the comment for MakeScriptNum.  This removes that part of the docs.

Also expand on range error and fix code reference. In
d8306ee602, the error for out-of-range
changed from ErrNumberTooBig to ErrNumOutOfRange.
2022-09-29 11:18:51 -05:00
Dave Collins
ad02d8f300
multi: Go 1.19 doc comment formatting.
This modifies the entire repository to use the new formatting of doc
comments in the upcoming Go 1.19 release.

The primary motivating factors for this are:

- Builds check that files are formatted per gofmt and that will no
  longer be true as of Go 1.19 without these changes
- Separating all the updates into a single commit ensures these
  documentation only formatting changes do not clutter up diffs that
  actually change code

For the most part, the changes are just the automated changes suggested
by the Go 1.19 version of gofmt, but there are also a few cases where
the comments were reworded a bit to play nicely with the new formatting
requirements.

For example, the new version of gofmt reformats and collapses nested
lists where as the existing version does not.  Thus, instances of nested
lists have been changed to either eliminate them or use mixed markers
which produce expect results.
2022-07-30 04:08:58 -05:00
Dave Collins
7d59dd3b69
multi: Support module graph prune and lazy load.
This bumps the go directive for all of the modules provided by the
repository to 1.17 which will allow the new module graph pruning and
lazy loading capabilities introduced in Go 1.17 to be used once the
updated modules are released.

This means that, as described by the documentation, the go.mod files for
each module now include a separate require block that includes all of
the indirect dependencies
2022-03-25 07:20:01 -05:00
Dave Collins
bf841fe588
txscript: Reduce checkmultisig allocs.
Profiling allocations during an initial chain sync shows that a large
portion of the allocations due to the CHECKMULTISIG opcode are the
result of generating the list of public keys and signatures.

This eliminates those allocations as follows:

- Use slices into fixed-size stack-based backing arrays for the typical
  number of public keys and signatures
- Make the slice of signature info contiguous instead of pointers which
  not only eliminates the associated allocations, but also provides
  better cache locality
2022-03-17 05:23:13 -05:00
Dave Collins
9969b8f306
txscript: Support min int64 script num encoding.
This modifies the encoding logic for script numbers to support encoding
min int64s.  This was previously not supported since the type was not
public and it is not possible to achieve a min int64 within the context
of the script system itself due to the strict limits it imposes.

However, now that script numbers are exported for external use and
callers are not bound by the aforementioned strictness, it should be
possible to encode the entire range for completeness.

In practice, callers should never realistically need to encode the value
since the purpose of the type is to create encoded numbers for scripts
and the value in question will be rejected upon any attempt to use it as
a number when verifying scripts given it is out of range.
2022-01-01 03:14:42 -06:00
Dave Collins
1961854e1e
stdaddr: Limit v0 addr decode to max possible size.
This modifies DecodeAddressV0 to reject any attempts to decode strings
that are larger than the max possible size early since there is no
reason to waste time and memory doing the base 58 decode when it is
guaranteed to be invalid anyway.

It also adds an associated test to ensure proper functionality.
2022-01-01 03:09:11 -06:00
Dave Collins
cc74183435
stdscript: Reject multisig neg thresholds.
This modifies the MultiSigScriptV0 convenience func for creating a
multisig script to return an error if the caller improperly calls it
with a negative threshold.
2022-01-01 01:22:07 -06:00
Dave Collins
55fb28cbbd
txscript: Prepare v4.0.0.
This updates the txscript module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
txscript/v4.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/chaincfg/v3@v3.1.0
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.2
- github.com/decred/dcrd/dcrec/secp256k1/v4@v4.0.1
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

The full list of updated direct dependencies since the previous
txscript/v3.0.0 release are as follows:

- github.com/dchest/siphash@v1.2.2
- github.com/decred/base58@v1.0.3
- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/chaincfg/v3@v3.1.0
- github.com/decred/dcrd/crypto/blake256@v1.0.0
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.2
- github.com/decred/dcrd/dcrec/secp256k1/v4@v4.0.1
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

The following direct dependencies are no longer required as compared to
the previous txscript/v3.0.0 release:

- github.com/decred/dcrd/dcrutil/v3

Finally, all modules in the repository that depend on txscript are
tidied to ensure they are updated to use the latest versions hoisted
forward as a result.
2021-11-18 23:14:01 -06:00
Dave Collins
b1b9a86da0
stdscript: Add extract v0 stake-tagged p2sh bench.
BenchmarkExtractStakeScriptHashV0
---------------------------------
v0_complex_non_standard       226793582   5.253 ns/op
v0_stake_submission_p2sh      372232682   3.233 ns/op
v0_stake_gen_p2sh             305602378   3.979 ns/op
v0_stake_revoke_p2sh          201691552   5.064 ns/op
v0_stake_change_p2sh          209401243   5.687 ns/op
v0_treasury_generation_p2sh   221794405   5.419 ns/op
2021-11-18 23:02:42 -06:00
Dave Collins
2e09c16c56
stdscript: Add v0 stake-tagged p2sh extract.
This adds support for directly extracting the script hash from standard
version 0 stake-tagged pay-to-script-hash scripts along with full test
coverage.

While all of this data can be extracted from each individual type, it
can be more convenient for callers who treat all script hashes as the
same entity which is the case for many applications.
2021-11-18 23:02:33 -06:00
Dave Collins
a81014df3c
stdscript: Add extract v0 stake-tagged p2pkh bench.
BenchmarkExtractStakePubKeyHashV0
---------------------------------
v0_complex_non_standard-16                        229676676   5.139 ns/op
v0_stake_submission_p2pkh-ecdsa-secp256k1-16      335241789   3.531 ns/op
v0_stake_gen_p2pkh-ecdsa-secp256k1-16             268142942   4.517 ns/op
v0_stake_revoke_p2pkh-ecdsa-secp256k1-16          244045095   4.908 ns/op
v0_stake_change_p2pkh-ecdsa-secp256k1-16          220275314   5.441 ns/op
v0_treasury_generation_p2pkh-ecdsa-secp256k1-16   197104339   6.086 ns/op
2021-11-18 23:02:29 -06:00
Dave Collins
d4f5338af0
stdscript: Add v0 stake-tagged p2pkh extract.
This adds support for directly extracting the public key hash from
standard version 0 stake-tagged pay-to-pubkey-hash scripts along with
full test coverage.

While all of this data can be extracted from each individual type, it
can be more convenient for callers who treat all public key hashes as
the same entity which is the case for many applications.
2021-11-18 23:02:05 -06:00
Dave Collins
c0fe15fa0e
stdaddr: Use txscript for opcode definitions.
This modifies the code to use the opcode definitions in txscript now
that the previous cyclic dependency no longer applies since txscript no
longer depends on stdaddr.
2021-11-18 13:15:06 -06:00
Dave Collins
67d1e95792
txscript: Remove unused ErrTooMuchNullData.
This removes ErrTooMuchNullData and its associated stringer test since
it is no longer used by anything in the repository.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:42 -06:00
Dave Collins
2f193bda49
txscript: Remove unused ErrTooManyRequiredSigs.
This removes ErrTooManyRequiredSigs and its associated stringer test
since it is no longer used by anything in the repository.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:42 -06:00
Dave Collins
bceeecad82
txscript: Remove unused ErrNotMultisigScript.
This removes ErrNotMultisigScript and its associated stringer test since
it is no longer used by anything in the repository.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:41 -06:00
Dave Collins
1555bc4e31
txscript: Remove unused ScriptClass.
This removes ScriptClass and its associated tests since it is no longer
used by anything in the repository and is now available via
stdscript.ScriptType.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:40 -06:00
Dave Collins
ba9df917eb
txscript: Remove unused MaxDataCarrierSize.
This removes MaxDataCarrierSize since it is no longer used by anything
in the repository and is now available via
stdscript.MaxDataCarrierSizeV0.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:40 -06:00
Dave Collins
edc646cb0d
txscript: Remove unused isStandardAltSignatureType.
This removes isStandardAltSignatureType since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:39 -06:00
Dave Collins
f41ce67e6d
txscript: Remove unused extractPubKeyHashAltDetails.
This removes extractPubKeyHashAltDetails since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:39 -06:00
Dave Collins
6260335f9c
txscript: Remove unused isPubKeyHashAltScript.
This removes isPubKeyHashAltScript along with its benchmark since it is
no longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:38 -06:00
Dave Collins
cc494923d4
txscript: Remove unused extractCompressedPubKey.
This removes extractCompressedPubKey since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:37 -06:00
Dave Collins
8565a3b356
txscript: Remove unused extractUncompressedPubKey.
This removes extractUncompressedPubKey since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:37 -06:00
Dave Collins
838adbc717
txscript: Remove unused extractPubKey.
This removes extractPubKey since it is no longer used by anything in the
package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:36 -06:00
Dave Collins
78ebc66740
txscript: Remove unused isPubKeyScript.
This removes isPubKeyScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:35 -06:00
Dave Collins
9e754a3ad1
txscript: Remove unused extractPubKeyAltDetails.
This removes extractPubKeyAltDetails since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:34 -06:00
Dave Collins
2903b61051
txscript: Remove unused isPubKeyAltScript.
This removes isPubKeyAltScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:33 -06:00
Dave Collins
7cb5314b44
txscript: Remove unused extractPubKeyHash.
This removes extractPubKeyHash since it is no longer used by anything in
the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:31 -06:00
Dave Collins
d96ae229b4
txscript: Remove unused isNullDataScript.
This removes isNullDataScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:30 -06:00
Dave Collins
556b21e8db
txscript: Remove unused extractStakePubKeyHash.
This removes extractStakePubKeyHash since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:29 -06:00
Dave Collins
af5329ffb0
txscript: Remove unused extractStakeScriptHash.
This removes extractStakeScriptHash since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:28 -06:00
Dave Collins
c508b538d2
txscript: Remove unused isStakeSubmissionScript.
This removes isStakeSubmissionScript along with its benchmark since it
is no longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:28 -06:00
Dave Collins
89421e5d67
txscript: Remove unused isStakeGenScript.
This removes isStakeGenScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:27 -06:00
Dave Collins
695077bdd2
txscript: Remove unused isStakeRevocationScript.
This removes isStakeRevocationScript along with its benchmark since it
is no longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:27 -06:00
Dave Collins
8fac63e2bf
txscript: Remove unused isPubKeyHashScript.
This removes isPubKeyHashScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:26 -06:00
Dave Collins
cfebbab0de
txscript: Remove unused isStakeChangeScript.
This removes isStakeChangeScript along with its benchmark since it is no
longer used by anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:26 -06:00
Dave Collins
abdf57c628
txscript: Remove unused extractMultisigScriptDetails.
This removes extractMultisigScriptDetails since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:25 -06:00
Dave Collins
d4e3a1624b
txscript: Remove unused isTreasuryAddScript.
This removes isTreasuryAddScript since it is no longer used by anything
in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:24 -06:00
Dave Collins
6114d62e30
txscript: Remove unused pubKeyHashToAddrs.
This removes pubKeyHashToAddrs since it is no longer used by anything in
the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:24 -06:00
Dave Collins
67b9252425
txscript: Remove unused scriptHashToAddrs.
This removes scriptHashToAddrs since it is no longer used by anything in
the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:23 -06:00
Dave Collins
611a7e2a99
txscript: Remove unused ExtractPkScriptAddrs.
This removes ExtractPkScriptAddrs and its associated tests, benchmarks,
and example since it is no longer used by anything in the repository
and is now available via stdscript.ExtractAddrs.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:23 -06:00
Dave Collins
4d09bcb68e
txscript: Remove unused isMultisigScript.
This removes isMultisigScript since it is no longer used by anything in
the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:22 -06:00
Dave Collins
54734a711c
txscript: Remove unused isTreasurySpendScript.
This removes isTreasurySpendScript since it is no longer used by
anything in the package.

This is part of a series of commits to remove all code related to
standard scripts from txscript.
2021-11-18 12:55:21 -06:00