Commit Graph

78 Commits

Author SHA1 Message Date
Aaron Campbell
03678bb754 multi: Correct typos.
Correct typos found by reading code and creative grepping.
2019-08-16 17:37:58 -05:00
Dave Collins
41f1139e3b
txscript: Unexport IsStakeOutput
This unexports the previously deprecated isStakeOutput function and
updates all callers in the module accordingly.
2019-06-24 15:13:32 -05:00
Dave Collins
6dea351b42
txscript: Remove third GetPreciseSigOpCount param.
This removes the previously deprecated and unused third parameter of the
GetPreciseSigOpCount function.
2019-06-24 15:13:31 -05:00
Dave Collins
16b9f67d4f
txscript: Unexport HasP2SHScriptSigStakeOpCodes.
This unexports the previously deprecated HasP2SHScriptSigStakeOpCodes
function and updates all callers in the module accordingly.
2019-06-24 15:13:31 -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
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
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
f93c1de13f
txscript: Implement efficient opcode data removal.
This introduces a new function named removeOpcodeByDataRaw which accepts
the raw scripts and data to remove versus requiring the parsed opcodes
to both significantly optimize it as well as make it more flexible for
working with raw scripts.

There are several places in the rest of the code that currently only
have access to the parsed opcodes, so this only introduces the function
for use in the future and deprecates the existing one.

Note that, in practice, the script will never actually contain the data
that is intended to be removed since the function is only used during
signature verification to remove the signature itself which would
require some incredibly non-standard code to create.

Thus, as an optimization, it avoids allocating a new script unless there
is actually a match that needs to be removed.

Finally, it updates the tests to use the new function.
2019-03-26 14:55:35 -05:00
Dave Collins
67d73853b2
txscript: Make canonicalPush accept raw opcode.
This renames the canonicalPush function to isCanonicalPush and converts
it to accept an opcode as a byte and the associate data as a byte slice
instead of the internal parse opcode data struct in order to make it
more flexible for raw script analysis.

It also updates all callers and tests accordingly.
2019-03-26 14:51:45 -05:00
Dave Collins
bb365f221f
txscript: Optimize IsUnspendable.
This converts the IsUnspendable function to make use of a combination of
raw script analysis and the new tokenizer instead of the far less
efficient parseScript thereby significantly optimizing the function.

It is important to note that this new implementation intentionally has a
semantic difference from the existing implementation in that it will now
report scripts that are larger than the max allowed script size are
unspendable as well.

Finally, the comment is modified to explicitly call out the script
version semantics.

The following is a before and after comparison of analyzing a large
script:

benchmark                old ns/op    new ns/op    delta
-----------------------------------------------------------
BenchmarkIsUnspendable   149899       860          -99.43%

benchmark                old allocs   new allocs   delta
-----------------------------------------------------------
BenchmarkIsUnspendable   1            0            -100.00%

benchmark                old bytes    new bytes    delta
-----------------------------------------------------------
BenchmarkIsUnspendable   466945       0            -100.00%
2019-03-26 14:51:44 -05:00
Dave Collins
5a4d9c9b5a
txscript: Remove unused getSigOpCount function. 2019-03-26 14:51:37 -05:00
Dave Collins
7d8ce2d27b
txscript: Remove unused isPushOnly function. 2019-03-26 14:51:37 -05:00
Dave Collins
efd7e2f572
txscript: Remove unused isScriptHash function. 2019-03-26 14:51:14 -05:00
Dave Collins
a1b24adf27
txscript: Optimize GetPreciseSigOpCount.
This converts the GetPreciseSigOpCount function to use a combination of
raw script analysis and the new tokenizer instead of the far less
efficient parseScript thereby significantly optimizing the function.

In particular it uses the recently converted isScriptHashScript,
IsPushOnlyScript, and countSigOpsV0 functions along with the recently
added finalOpcodeData functions.

It also modifies the comment to explicitly call out the script version
semantics.

The following is a before and after comparison of analyzing a large
script:

benchmark                       old ns/op    new ns/op    delta
------------------------------------------------------------------
BenchmarkGetPreciseSigOpCount   287939       1077         -99.63%

benchmark                       old allocs   new allocs   delta
------------------------------------------------------------------
BenchmarkGetPreciseSigOpCount   3            0            -100.00%

benchmark                       old bytes    new bytes    delta
------------------------------------------------------------------
BenchmarkGetPreciseSigOpCount   934657       0            -100.00%
2019-03-26 14:51:12 -05:00
Dave Collins
9e8bfd2493
txscript: Optimize IsPushOnlyScript.
This converts the IsPushOnlyScript function to make use of the new
tokenizer instead of the far less efficient parseScript thereby
significantly optimizing the function.

It also deprecates the isPushOnly function that requires opcodes in
favor of the new function and modifies the comment on IsPushOnlyScript
to explicitly call out the script version semantics.

The following is a before and after comparison of analyzing a large
script:

benchmark                    old ns/op    new ns/op    delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   139961       0.66         -100.00%

benchmark                    old allocs   new allocs   delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   1            0            -100.00%

benchmark                    old bytes    new bytes    delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   466944       0            -100.00%
2019-03-26 14:51:09 -05:00
Dave Collins
a598838fb7
txscript: Optimize isAnyKindOfScriptHash.
This converts the isAnyKindOfScriptHash function to analyze the raw
script instead of requiring far less efficient parsed opcodes thereby
significantly optimizing the function.

Since the function relies on isStakeScriptHash to identify a stake
tagged pay-to-script-hash, and is the only consumer of it, this also
converts that function to analyze the raw script and renames it to
isStakeScriptHashScript for more consistent naming.

Finally, the tests are updated accordingly.

The following is a before and after comparison of analyzing a large
script:

benchmark                        old ns/op    new ns/op    delta
-------------------------------------------------------------------
BenchmarkIsAnyKindOfScriptHash   101249       3.83         -100.00%

benchmark                        old allocs   new allocs   delta
-------------------------------------------------------------------
BenchmarkIsAnyKindOfScriptHash   1            0            -100.00%

benchmark                        old bytes    new bytes    delta
-------------------------------------------------------------------
BenchmarkIsAnyKindOfScriptHash   466944       0            -100.00%
2019-03-26 14:51:08 -05:00
Dave Collins
ffa6fb9e9d
txscript: Optimize GetSigOpCount.
This converts the GetSigOpCount function to make use of the new
tokenizer instead of the far less efficient parseScript thereby
significantly optimizing the function.

A new function named countSigOpsV0 which accepts the raw script is
introduced to perform the bulk of the work so it can be reused for
precise signature operation counting as well in a later commit.  It
retains the same semantics in terms of counting the number of signature
operations either up to the first parse error or the end of the script
in the case it parses successfully as required by consensus.

Finally, this also deprecates the getSigOpCount function that requires
opcodes in favor of the new function and modifies the comment on
GetSigOpCount to explicitly call out the script version semantics.

The following is a before and after comparison of analyzing a large
script:

benchmark                old ns/op    new ns/op    delta
-----------------------------------------------------------
BenchmarkGetSigOpCount   163896       1048         -99.36%

benchmark                old allocs   new allocs   delta
-----------------------------------------------------------
BenchmarkGetSigOpCount   1            0            -100.00%

benchmark                old bytes    new bytes    delta
-----------------------------------------------------------
BenchmarkGetSigOpCount   466945       0            -100.00%
2019-03-26 14:51:06 -05:00
Dave Collins
462eea3b82
txscript: Optimize IsMultisigSigScript.
This converts the IsMultisigSigScript function to analyze the raw script
and make use of the new tokenizer instead of the far less efficient
parseScript thereby significantly optimizing the function.

In order to accomplish this, it first rejects scripts that can't
possibly fit the bill due to the final byte of what would be the redeem
script not being the appropriate opcode or the overall script not having
enough bytes.  Then, it uses a new function that is introduced named
finalOpcodeData that uses the tokenizer to return any data associated
with the final opcode in the signature script (which will be nil for
non-push opcodes or if the script fails to parse) and analyzes it as if
it were a redeem script when it is non nil.

It is also worth noting that this new implementation intentionally has
the same semantic difference from the existing implementation as the
updated IsMultisigScript function in regards to allowing zero pubkeys
whereas previously it incorrectly required at least one pubkey.

Finally, the comment is modified to explicitly call out the script
version semantics.

The following is a before and after comparison of analyzing a large
script that is not a multisig script and both a 1-of-2 multisig public
key script (which should be false) and a signature script comprised of a
pay-to-script-hash 1-of-2 multisig redeem script (which should be true):

benchmark                           old ns/op    new ns/op     delta
-----------------------------------------------------------------------
BenchmarkIsMultisigSigScriptLarge   158149       4             -100.00%
BenchmarkIsMultisigSigScript        3445         202           -94.14%

benchmark                           old allocs   new allocs    delta
-----------------------------------------------------------------------
BenchmarkIsMultisigSigScriptLarge   9            0             -100.00%
BenchmarkIsMultisigSigScript        3            0             -100.00%

benchmark                           old bytes    new bytes     delta
-----------------------------------------------------------------------
BenchmarkIsMultisigSigScriptLarge   533189       0             -100.00%
BenchmarkIsMultisigSigScript        9472         0             -100.00%
2019-03-26 14:51:04 -05:00
Dave Collins
9f2f038842
txscript: Optimize IsPayToScriptHash.
This converts the IsPayToScriptHash function to analyze the raw script
instead of using the far less efficient parseScript thereby
significantly optimizing the function.

In order to accomplish this, it introduces two new functions.  The first
one is named extractScriptHash and works with the raw script bytes to
simultaneously determine if the script is a p2sh script, and in the case
it is, extract and return the hash.  The second new function is named
isScriptHashScript and is defined in terms of the former.

The extract function approach was chosen because it is common for
callers to want to only extract relevant details from a script if the
script is of the specific type.  Extracting those details requires
performing the exact same checks to ensure the script is of the correct
type, so it is more efficient to combine the two into one and define the
type determination in terms of the result so long as the extraction does
not require allocations.

Finally, this also deprecates the isScriptHash function that requires
opcodes in favor of the new functions and modifies the comment on
IsPayToScriptHash to explicitly call out the script version semantics.

The following is a before and after comparison of analyzing a large
script that is not a p2sh script:

benchmark                    old ns/op    new ns/op    delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   139961       0.66         -100.00%

benchmark                    old allocs   new allocs   delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   1            0            -100.00%

benchmark                    old bytes    new bytes    delta
---------------------------------------------------------------
BenchmarkIsPayToScriptHash   466944       0            -100.00%
2019-03-26 14:51:02 -05:00
Dave Collins
082d1ed6b4
txscript: Make isStakeOpcode accept raw opcode.
This converts the isStakeOpcode function to accept an opcode as a byte
instead of the internal opcode data struct in order to make it more
flexible for raw script analysis.

It also updates all callers accordingly.
2019-03-26 14:51:01 -05:00
Dave Collins
0ed8e25a1e
txscript: Make asSmallInt accept raw opcode.
This converts the asSmallInt function to accept an opcode as a byte
instead of the internal opcode data struct in order to make it more
flexible for raw script analysis.

It also updates all callers accordingly.
2019-03-26 14:51:00 -05:00
Dave Collins
44cbc3176c
txscript: Make isSmallInt accept raw opcode.
This converts the isSmallInt function to accept an opcode as a byte
instead of the internal opcode data struct in order to make it more
flexible for raw script analysis.

The comment is modified to explicitly call out the script version
semantics.

Finally, it updates all callers accordingly.
2019-03-26 14:50:59 -05:00
Dave Collins
c57dc2d6b0
txscript: Optimize CalcSignatureHash.
This modifies the CalcSignatureHash function to make use of the new
signature hash calculation function that accepts raw scripts without
needing to first parse them.  Consequently, it also doubles as a slight
optimization to the execution time and a significant reduction in the
number of allocations.

In order to convert the CalcScriptHash function and keep the same
semantics, a new function named checkScriptParses is introduced which
will quickly determine if a script can be fully parsed without failure
and return the parse failure in the case it can't.

The following is a before and after comparison of analyzing a large
multiple input transaction:

benchmark              old ns/op    new ns/op   delta
-------------------------------------------------------
BenchmarkCalcSigHash   2792057      2760042     -1.15%

benchmark              old allocs   new allocs  delta
-------------------------------------------------------
BenchmarkCalcSigHash   1691         1068        -36.84%

benchmark              old bytes    new bytes   delta
-------------------------------------------------------
BenchmarkCalcSigHash   521673       438604      -15.92%
2019-03-26 14:50:58 -05:00
Dave Collins
f306a72a16
txscript: Introduce raw script sighash calc func.
This introduces a new function named calcSignatureHashRaw which accepts
the raw script bytes to calculate the script hash versus requiring the
parsed opcode only to unparse them later in order to make it more
flexible for working with raw scripts.

Since there are several places in the rest of the code that currently
only have access to the parsed opcodes, this modifies the existing
calcSignatureHash to first unparse the script before calling the new
function.

Note that the code in the signature hash calculation to remove all
instances of OP_CODESEPARATOR from the script is removed because that is
a holdover from BTC code which does not apply to v0 Decred scripts since
OP_CODESEPARATOR is completely disabled in Decred and thus there can
never actually be one in the script.

Finally, it removes the removeOpcode function and related tests since it
is no longer used.
2019-03-26 14:50:57 -05:00
Dave Collins
e332430021
txscript: Optimize script disasm.
This converts the DisasmString function to make use of the new
zero-allocation script tokenizer instead of the far less efficient
parseScript thereby significantly optimizing the function.

In order to facilitate this, the opcode disassembly functionality is
split into a separate function called disasmOpcode that accepts the
opcode struct and data independently as opposed to requiring a parsed
opcode.  The new function also accepts a pointer to a string builder so
the disassembly can be more efficiently be built.

While here, the comment is modified to explicitly call out the script
version semantics.

The following is a before and after comparison of a large script:

benchmark               old ns/op    new ns/op    delta
----------------------------------------------------------
BenchmarkDisasmString   288729       94157        -67.39%

benchmark               old bytes    new bytes    delta
----------------------------------------------------------
BenchmarkDisasmString   584611       177528       -69.63%
2019-03-26 14:50:57 -05:00
Dave Collins
60d41d1230
txscript: Deprecate HasP2SHScriptSigStakeOpCodes.
This function is only useful for internal consensus purposes within the
script engine and as such should not be exported.
2019-03-26 14:50:52 -05:00
Dave Collins
d8306ee602
txscript: Significantly improve errors.
This converts the majority of script errors from generic errors created
via errors.New and fmt.Errorf to use a concrete type that implements the
error interface with an error code and description.

This allows callers to programmatically detect the type of error via
type assertions and an error code while still allowing the errors to
provide more context.

For example, instead of just having an error the reads "disabled opcode"
as would happen prior to these changes when a disabled opcode is
encountered, the error will now read "attempt to execute disabled opcode
OP_FOO".

While it was previously possible to programmatically detect many errors
due to them being exported, they provided no additional context and
there were also various instances that were just returning errors
created on the spot which callers could not reliably detect without
resorting to looking at the actual error message, which is nearly always
bad practice.

Also, while here, export the MaxStackSize and MaxScriptSize constants
since they can be useful for consumers of the package and perform some
minor cleanup of some of the tests.
2018-07-01 15:04:59 -05:00
Dave Collins
dd0bfb639c
txscript: Cleanup P2SH and stake opcode handling.
This slightly cleans up the handling for pay-to-script-hash scripts and
related stake opcode checking as follows:

- Move the isScriptHash and isAnyKindOfScriptHash functions to script.go
  since they are required by consensus and therefore do not belong in
  standard.go which is reserved for standardness only rules
- Introduce a new function named isStakeOpcode and use it throughout
  versus repeating the specific logic in multiple places
- Use the stake opcode constants instead of magic numbers in the
  aforementioned new function
- Introduce a new function named isStakeScriptHash which specifically
  determines if a script is of the special stake p2sh form
- Update isAnyKindOfScriptHash to make use of the original isScriptHash
  function instead of repeating the logic and the newly introduced
  isStakeScriptHash function
2018-07-01 14:58:16 -05:00
Dave Collins
f6be618a1b
txscript: Move sig hash logic to separate file.
This moves the logic to calculate the signature hash and the associated
test to separate files.  Since there will ultimately be a new signature
algorithm, it makes sense to separate all logic related to signature
hashes for better code organization.

It contains no functional changes.
2018-04-30 08:54:07 -05:00
Dave Collins
1ca1017813
txscript: Allow external signature hash calc.
This modifies the exported CalcSignatureHash function to accept a script
as bytes instead of an array of parsed opcodes which are not available
to callers outside of the package.

While here, it also adds a proper comment for the exported function
since it is intended for more than testing as the previous comment
claimed.

Finally, it updates the tests to use a valid script instead of the
previous impossible to achieve constructed series of parsed opcodes.
2017-12-21 14:28:22 -06:00
David Hill
b13f5dfbda travis: add ineffassign linter 2017-12-01 09:14:04 -05:00
David Hill
64119dfabb txscript: remove unneeded API 2017-08-17 15:42:04 -04:00
David Hill
99d04eea40 Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
Dave Collins
c162fbde71
multi: Upstream chainhash abstraction sync
Contains the following commits:

- 711f33450c
- b6b1e55d1e
  - Reverted because Travis is already at a more recent version
- bd4e64d1d4

Also, the merge commit contains the necessary decred-specific
alterations, converts all other references to sha to hash to keep with
the spirit of the merged commits, and various other cleanup intended to
bring the code bases more in line with one another.
2016-11-16 12:48:40 -06:00
cjepson
2889b79b0e Merge btcd commit '644570487f379e9856ae4025181ecc6293d86711'
Merges in btcd commit 644570487f.
2016-09-23 12:11:31 -04:00
Dave Collins
b6d426241d blockchain: Rework to use new db interface.
This commit is the first stage of several that are planned to convert
the blockchain package into a concurrent safe package that will
ultimately allow support for multi-peer download and concurrent chain
processing.  The goal is to update btcd proper after each step so it can
take advantage of the enhancements as they are developed.

In addition to the aforementioned benefit, this staged approach has been
chosen since it is absolutely critical to maintain consensus.
Separating the changes into several stages makes it easier for reviewers
to logically follow what is happening and therefore helps prevent
consensus bugs.  Naturally there are significant automated tests to help
prevent consensus issues as well.

The main focus of this stage is to convert the blockchain package to use
the new database interface and implement the chain-related functionality
which it no longer handles.  It also aims to improve efficiency in
various areas by making use of the new database and chain capabilities.

The following is an overview of the chain changes:

- Update to use the new database interface
- Add chain-related functionality that the old database used to handle
  - Main chain structure and state
  - Transaction spend tracking
- Implement a new pruned unspent transaction output (utxo) set
  - Provides efficient direct access to the unspent transaction outputs
  - Uses a domain specific compression algorithm that understands the
    standard transaction scripts in order to significantly compress them
  - Removes reliance on the transaction index and paves the way toward
    eventually enabling block pruning
- Modify the New function to accept a Config struct instead of
  inidividual parameters
- Replace the old TxStore type with a new UtxoViewpoint type that makes
  use of the new pruned utxo set
- Convert code to treat the new UtxoViewpoint as a rolling view that is
  used between connects and disconnects to improve efficiency
- Make best chain state always set when the chain instance is created
  - Remove now unnecessary logic for dealing with unset best state
- Make all exported functions concurrent safe
  - Currently using a single chain state lock as it provides a straight
    forward and easy to review path forward however this can be improved
    with more fine grained locking
- Optimize various cases where full blocks were being loaded when only
  the header is needed to help reduce the I/O load
- Add the ability for callers to get a snapshot of the current best
  chain stats in a concurrent safe fashion
  - Does not block callers while new blocks are being processed
- Make error messages that reference transaction outputs consistently
  use <transaction hash>:<output index>
- Introduce a new AssertError type an convert internal consistency
  checks to use it
- Update tests and examples to reflect the changes
- Add a full suite of tests to ensure correct functionality of the new
  code

The following is an overview of the btcd changes:

- Update to use the new database and chain interfaces
- Temporarily remove all code related to the transaction index
- Temporarily remove all code related to the address index
- Convert all code that uses transaction stores to use the new utxo
  view
- Rework several calls that required the block manager for safe
  concurrency to use the chain package directly now that it is
  concurrent safe
- Change all calls to obtain the best hash to use the new best state
  snapshot capability from the chain package
- Remove workaround for limits on fetching height ranges since the new
  database interface no longer imposes them
- Correct the gettxout RPC handler to return the best chain hash as
  opposed the hash the txout was found in
- Optimize various RPC handlers:
  - Change several of the RPC handlers to use the new chain snapshot
    capability to avoid needlessly loading data
  - Update several handlers to use new functionality to avoid accessing
    the block manager so they are able to return the data without
    blocking when the server is busy processing blocks
  - Update non-verbose getblock to avoid deserialization and
    serialization overhead
  - Update getblockheader to request the block height directly from
    chain and only load the header
  - Update getdifficulty to use the new cached data from chain
  - Update getmininginfo to use the new cached data from chain
  - Update non-verbose getrawtransaction to avoid deserialization and
    serialization overhead
  - Update gettxout to use the new utxo store versus loading
    full transactions using the transaction index

The following is an overview of the utility changes:
- Update addblock to use the new database and chain interfaces
- Update findcheckpoint to use the new database and chain interfaces
- Remove the dropafter utility which is no longer supported

NOTE: The transaction index and address index will be reimplemented in
another commit.
2016-08-18 15:42:18 -04:00
Dave Collins
bd4e64d1d4 chainhash: Abstract hash logic to new package. (#729)
This is mostly a backport of some of the same modifications made in
Decred along with a few additional things cleaned up.  In particular,
this updates the code to make use of the new chainhash package.

Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.

The following is an overview of the changes:

- Remove the wire.ShaHash type
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
  - wire.BlockHeader.BlockSha -> BlockHash
  - wire.MsgBlock.BlockSha -> BlockHash
  - wire.MsgBlock.TxShas -> TxHashes
  - wire.MsgTx.TxSha -> TxHash
  - blockchain.ShaHashToBig -> HashToBig
  - peer.ShaFunc -> peer.HashFunc
- Rename all variables that included sha in their name to include hash
  instead
- Update for function name changes in other dependent packages such as
  btcutil
- Update copyright dates on all modified files
- Update glide.lock file to use the required version of btcutil
2016-08-08 14:04:33 -05:00
Dave Collins
2030b4d057 multi: Fix several misspellings in the comments.
Contains the following upstream commits:
- ef9c50be57
- eb882f39f8

In addition to merging the fixes in the commits, this also fixes a few
more misspellings that were introduced in the new Decred code.
2016-05-30 12:24:21 -05:00
Dave Collins
28f5ce5e44 Sync upstream through Sep 28, 2015.
This sync includes a new service flag named SFNodeBloom that a node is
required to use to indicate that it supports bloom filtering.  This
includes a protocol version bump to 2 and a wire version bump to 0.1.0.

dcrd:
The SFNodeBloom flag is set by default.  A new configuration option
--nopeerbloomfilters has been added to to disable bloom filtering.

Also, it corrects an issue with the mining state message where it was
using the network protocol version instead of having its own version.
2016-05-17 14:01:54 -05:00
Dave Collins
885070a4df Sync upstream through Sep 2, 2015. 2016-05-17 12:15:10 -05:00
cjepson
653e13db0e Waste less memory if sighash optimizations are on
Legacy transaction deep copy code mandated by the Bitcoin protocol
caused large amounts of data to be copied needlessly. If the
optimization for SigHashAll is set in chaincfg/params.go, these
extra copies are avoided by directly writing the pkScript and
decorations to a buffer and then hashing to get a witness hash,
while using the cached hash for the prefix.

Fixes #126.
2016-05-16 16:18:04 -04:00
Jonathan Gillham
c24785e90b txscript: Remove unneeded signature hash copies
These copies were likely left over from when MsgTx had no deep copy
functionality.
2016-05-12 14:43:09 -05:00
Dave Collins
644570487f txscript: Reduce script parse opcode allocs. (#677)
This changes the script template parsing function to use a pointer into
the constant global opcode array for parsed opcodes as opposed to making
a copy of the opcode entries which causes unnecessary allocations.

Profiling showed that after roughly 48 hours of operation, this
copy was the culprit of 207 million unnecessary allocations.
2016-04-25 16:17:07 -05:00
David Hill
5fcef8aa56 txscript: New function IsUnspendable
IsUnspendable takes a public key script and returns whether it is
spendable.

Additionally, hook this into the mempool isDust function, since
unspendable outputs can't be spent.

This mimics Bitcoin Core commit 0aad1f13b2430165062bf9436036c1222a8724da
2016-03-22 11:34:32 -04:00
cjepson
df701d8cdf Revert sync merge
The sync merge does not build and needs further testing. It is
being reverted.
2016-03-08 22:16:06 -05:00
Alex Yocom-Piatt
cb9566911c Update comment to match code 2016-03-07 13:39:50 -06:00
Alex Yocom-Piatt
5b2b97e858 Sync to upstream 0280fa0264
Conflicts:
	blockchain/chain.go
	blockchain/checkpoints.go
	blockchain/difficulty.go
	blockchain/internal_test.go
	blockchain/txlookup.go
	blockchain/validate.go
	blockchain/validate_test.go
	blockmanager.go
	chaincfg/params.go
	cmd/dropafter/dropafter.go
	cpuminer.go
	database/db.go
	database/interface_test.go
	database/ldb/block.go
	database/ldb/insertremove_test.go
	database/ldb/leveldb.go
	database/ldb/operational_test.go
	database/ldb/tx.go
	database/memdb/memdb.go
	database/reorg_test.go
	dcrjson/walletsvrcmds.go
	docs/README.md
	docs/json_rpc_api.md
	mempool.go
	mining.go
	peer.go
	rpcserver.go
	rpcserverhelp.go
	rpcwebsocket.go
	sample-dcrd.conf
	txscript/consensus.go
	txscript/script_test.go
	txscript/sign.go
	txscript/standard.go
	wire/blockheader_test.go
	wire/msgtx_test.go
2016-03-07 11:35:24 -06:00
Dave Collins
eb882f39f8 multi: Fix several misspellings in the comments.
This commit corrects several typos in the comments found by misspell.
2016-02-25 11:17:12 -06:00