Commit Graph

5759 Commits

Author SHA1 Message Date
Ryan Staudt
df2e172ee8 mempool: Add maybeAcceptTransaction AgendaFlags.
This updates the mempool maybeAcceptTransaction method to accept agenda
flags rather than just a boolean indicating if the treasury is active.

This allows for accommodating future agendas without having to add
additional boolean fields for each agenda.

This is useful in particular since maybeAcceptTransaction makes use of
the blockchain.CheckTransaction function to perform validation checks on
transactions, which includes checks which depend on whether or not an
agenda is active.
2021-07-28 06:41:27 -05:00
Ryan Staudt
87128cd43f multi: Update ProcessOrphans to use AgendaFlags.
This updates the mempool ProcessOrphans method to accept agenda flags
rather than just a boolean indicating if the treasury is active.

This allows for accommodating future agendas without having to add
additional boolean fields for each agenda.
2021-07-28 06:41:27 -05:00
Ryan Staudt
c2e6094447 multi: Update block ntfns to contain AgendaFlags.
This updates the blockchain BlockConnectedNtfnsData and
BlockDisconnectedNtfnsData types to contain agenda flags rather than
just a boolean indicating if the treasury is active.

This allows for accommodating future agendas without having to add
additional boolean fields for each agenda.
2021-07-28 06:41:27 -05:00
Ryan Staudt
93902730c1 blockchain: Add IsTreasuryEnabled to AgendaFlags.
This adds an IsTreasuryEnabled method to the AgendaFlags type that
returns whether the flags indicate that the treasury agenda is enabled.
This is useful since checking the flags directly is pretty verbose,
especially when using the type outside of the blockchain package.

This also updates existing references to the AgendaFlags type to use
the IsTreasuryEnabled function.
2021-07-28 06:41:27 -05:00
Dave Collins
4d81fc1b6e
multi: Address some linter complaints. 2021-07-26 20:51:03 -05:00
Ryan Staudt
789275465e blockchain: Remove serializeUtxoEntry error.
This removes the error returned from serializeUtxoEntry since that
function never actually returns an error.
2021-07-24 23:16:39 -05:00
Dave Collins
2cafabefde
config: Correct dir create failure error message.
This corrects the error message when the home directory fails to be
created since the %w verb only works with fmt.Errorf.
2021-07-24 23:04:08 -05:00
briancolecoinmetrics
22f37e40a4
contrib: Bump Dockerfile.alpine to alpine:3.14.0.
Alpine 3.10 is EOL, and 3.14 is current.
2021-07-20 03:39:25 -05:00
Dave Collins
c9521b468f
rpcclient: Cancel client context on shutdown.
This introduces a child context with cancellation to the manual Connect
method and cancels it when the client is manually stopped via Shutdown
to ensure callers are still able to shutdown the client via that method
when using manual connections in addition to when using automatic ones.
2021-07-14 22:24:35 -05:00
Dave Collins
6da5735192
server: Correct tx not found ban reason.
This corrects the ban reason string when too many transactions are
advertised and then claimed as not found to display the number of
transactions as intended.
2021-07-14 22:23:58 -05:00
Dave Collins
e917dcb795
rpcserver: Add more strict request origin check.
This makes the CORS policy for websocket clients more strict by ensuring
any requests from other domains are rejected.  It is worth noting that,
in practice, the current less strict mechanism is secure due to both the
use of a self-signed TLS certificate and the requirement for
authentication to issue any commands, but further hardening is still
desirable.
2021-07-07 20:48:34 -05:00
Dave Collins
2e8efe15a3
docs: Update JSON-RPC API for max request limits. 2021-06-30 12:39:02 -05:00
Dave Collins
611e50a698
rpcserver: Impose additional read limits.
This imposes additional per-connection read limits on the RPC server to
help further harden it against potential abuse in non-standard
configurations on poorly-configured networks.

In practice, these changes will not have any noticeable effect for the
vast majority of nodes since the RPC server is not publicly accessible
by default and requires authentication.

Nevertheless, it can still be useful to apply additional read limits for
scenarios such as authenticated fuzz testing and poorly-configured
networks that have disabled all other security measures.

The following are the updated per-connection limits:

- 0 B / 8 MiB for pre and post auth HTTP connections
- 4 KiB / 16 MiB for pre and post auth websocket connections
2021-06-30 12:38:36 -05:00
Dave Collins
fc2e1d9142
stake: No standardness code in tests.
This modifies the test code in stake to avoid using standardness code
since it is testing consensus level code which means it needs to be
stable and thus must not change if the policy regarding standardness can
change.
2021-06-30 12:34:42 -05:00
J Fixby
afff2fdbcd
dcrjson: Minor jsonerr.go update. 2021-06-21 03:43:05 -05:00
Ryan Staudt
dbc6eeb56b blockchain: Flush UtxoCache when latch to current.
This forces the UTXO cache to flush to the database when the chain just
latched to current.  This ensures that the full UTXO set is always
flushed to the database when the chain becomes current, which allows for
fetching up-to-date UTXO set stats.

The behavior before these changes is that the UTXO cache will not be
forced to flush to the database until a block is connected AFTER the
chain is already latched to current.  Therefore, if you fetch UTXO stats
when the chain is current but the next block has not been connected yet,
the UTXO stats may not be up to date.
2021-06-21 03:42:27 -05:00
Dave Collins
f98e374037
txscript: Explicit consensus any kind p2sh tests.
This adds explicit test cases for the consensus-specific
isAnyKindOfScriptHash method of the engine instead of using the script
class tests which are only intended for use by standardness code
2021-06-15 13:01:26 -05:00
Dave Collins
b782928ed1
txscript: Explicit consensus p2sh tests.
This adds explicit test cases for the consensus-specific
IsPayToScriptHash func instead of using the script class tests which are
only intended for use by standardness code.
2021-06-15 13:01:26 -05:00
Dave Collins
06cd8b0b37
txscript: Remove unused PushedData.
This removes PushedData along with its associated test and benchmark
from txscript since it is no longer used by anything and hasn't been for
quite some time due to the introduction of the zero allocation script
tokenizer which allows it to be done by callers more efficiently.
2021-06-15 13:01:25 -05:00
Dave Collins
6256460fa5
txscript: Remove unused IsStakeChangeScript.
This removes IsStakeChangeScriptScript from txscript since it is no
longer used as it was only used by the new treasury code from stake
which should have been using its internal consensus funcs as is now the
case.
2021-06-15 13:01:25 -05:00
Dave Collins
8aa2e53b97
txscript: Remove unused IsPubKeyHashScript.
This removes IsPubKeyHashScript from txscript since it is no longer used
as it was only used by the new treasury code from stake which should
have been using its internal consensus funcs as is now the case.
2021-06-15 13:01:24 -05:00
Dave Collins
a94c027208
txscript: Separate short form script parsing.
This separates the test code related to parsing scripts using the
human-readable short form used throughout the tests into a separate file
so it can more easily be copied into other packages where it might be
useful for the tests as well.  Allowing it to be copied is preferred to
making it part of the public API of some package since it is an ad-hoc
format and it is not possible to access test-specific code across
package boundaries without making it part of the actual public API.
2021-06-15 13:01:24 -05:00
Dave Collins
fe45e796ca
txscript: Move stake votebits script to consensus.
This moves the GenerateSSGenVotes method to script.go since it is used
in consensus code and therefore should not be in standard.go which is
only intended for standardness code.

It also moves the associated test to script_test.go to match and does
some other misc cleanup such as improving the comments and tests for
consistency.
2021-06-15 13:01:23 -05:00
Dave Collins
4a07fd6499
txscript: Move stake blockref script to consensus.
This moves the GenerateSSGenBlockRef method to script.go since it is
used in consensus code and therefore should not be in standard.go which
is only intended for standardness code.

It also moves the associated test to script_test.go to match and does
some other misc cleanup such as improving the comments and tests for
consistency.
2021-06-15 13:01:23 -05:00
Dave Collins
4161a26e50
txscript: Move contains stake opcode to consensus.
This moves the ContainsStakeOpCodes method to script.go since it is used
in consensus code and therefore should not be in standard.go which is
only intended for standardness code.
2021-06-15 13:01:20 -05:00
Dave Collins
e279168276
docs: Update JSON-RPC API for script version.
This updates the JSON-RPC API docs to include the version field as part
of the scriptPubKey object for the RPCs that involve it.
2021-06-15 12:50:02 -05:00
Dave Collins
df10132d7e
rpcserver: Set script version in raw tx results.
This ensures the recently-added script version field of
types.ScriptPubKeyResult is set in the various RPCs that produce raw
transaction results.  Namely, getrawtransaction, decoderawtransaction,
searchrawtransaction, and getblock (with the verbose tx flag set).

Note that this is a duplicate of the types.Vout.Version field.
2021-06-15 12:49:59 -05:00
Ryan Staudt
a72516b93b stake: Remove stale TODOs from CheckSSRtx.
This removes TODO comments in CheckSSRtx that are no longer needed since
the checks that are referred to are already handled in validate.go (in
the checkRevocationInputs and checkTicketRedeemerCommitments functions).
2021-06-14 12:04:55 -05:00
Ryan Staudt
761aa2b90b stake: Remove stale TODOs from CheckSSGenVotes.
This removes TODO comments in CheckSSGenVotes that are no longer needed
since the checks that are referred to are already handled in validate.go
(in the checkVoteInputs and checkTicketRedeemerCommitments functions).
2021-06-14 12:04:55 -05:00
Ryan Staudt
d4d7daa07c stake: Fix CheckSSRtx function comment.
This updates the CheckSSRtx function comment to refer to the correct
output indexes from the input ticket transaction.  It also updates the
comment to refer to SSRtx outputs rather than SSGen outputs.
2021-06-14 12:04:55 -05:00
Ryan Staudt
a89f1847bc stake: Fix CheckSSGenVotes function comment.
This updates the CheckSSGenVotes function comment to refer to the
correct output indexes from the input ticket transaction.
2021-06-14 12:04:55 -05:00
Ryan Staudt
ca67a293f4 stake: Fix MaxOutputsPerSSRtx comment. 2021-06-14 12:04:55 -05:00
Ryan Staudt
d8b7bb0cb0 blockchain: Fix comment formatting in generator. 2021-06-14 12:04:55 -05:00
Ryan Staudt
81ec47f2a2 rpcserver: Fix createrawssrtx comments.
This updates a couple of comments within createrawssrtx to properly
refer to SSRtx outputs/transactions rather than SSGen.
2021-06-14 12:04:55 -05:00
Ryan Staudt
79b6fbc427 stake: Comment on max SSGen outputs with treasury.
This adds a comment to MaxOutputsPerSSGen indicating that if the
treasury agenda is active, an OP_RETURN TV (treasury vote) output is
additionally included in the last position when voting on a treasury
spend.

The MaxOutputsPerSSGen value does NOT account for this output, and
should technically be increased by 1, but since the treasury agenda is
already active this cannot be updated without a consensus vote.
2021-06-14 12:04:38 -05:00
Dave Collins
d4084ec0e0
gcs: No standardness code in consensus.
This modifies the version 2 block filters in gcs to avoid using
standardness code since they are part of consensus code through header
commitments and therefore must not change even though the policy
regarding standardness can change.

It accomplishes the change by making use of the consensus-specific
script identification methods available via the stake package.
2021-06-14 11:58:11 -05:00
Dave Collins
87c9ccfb5d
blockchain: No standardness code in consensus.
This modifies the treasury code in blockchain which enforces the
treasury generation spending maturity to avoid using standardness code
since it is consensus level code which means it must not change even
though the policy regarding standardness can change.
2021-06-12 08:56:50 -05:00
Dave Collins
c69eb0a58e
stake: Add is treasury gen script.
This adds a method to stake which allow treasury generation scripts that
are enforced by consensus to be identified via a consensus-specific
method versus relying on the policy-based variant that is subject to
change.

This is consistent with the other consensus-enforced stake-related
scripts exported from the package.
2021-06-10 15:26:01 -05:00
Dave Collins
35a99aff86
blockchain: Remove unneeded OP_TADD maturity check.
This removes the unnecessary OP_TADD coinbase maturity check because
OP_TADD is not a spendable utxo and therefore it can never have a
maturity applied to it.  Recall that treasurybase and treasury add stake
transactions are the only place an OP_TADD is valid and in both cases
they result in increasing the balance of the treasury account and are
never directly spendable.
2021-06-10 15:21:16 -05:00
Dave Collins
2e3d5309c8
stake: Do not use standardness code in consensus.
This modifies the treasury code in stake to avoid using standardness
code since it is consensus level code which mean it must not change even
though the policy regarding standardness can change.

The consensus-specific methods are all already available in the stake
package, so the code is merely updated to use them instead.

An overview of the changes follows:

- Introduce an exported constant for the max data carrier size allowed
  in stake transactions set to match the current standardness value
  since that is now part of consensus for them
- Modify the calls to txscript.GetScriptClass used for determining null
  data scripts to use consensus-specific IsNullDataScript method
- Use the consensus-specific methods for the following:
  - IsStakeChangeScript
  - isPubKeyHashScript
  - isScriptHashScript
2021-06-10 15:16:23 -05:00
Dave Collins
742ba9ad1b
blockchain: Use scripts in tickets address query.
This modifies the TicketsWithAddress query method in blockchain to
accept the more specific stdaddr.StakeAddress since only stake-capable
addresses can be used in tickets and modifies the logic to compare the
expected voting rights script and associated script version directly
instead of extracting and comparing encoded addresses.  It also updates
the callers and plumbing in rpcserver accordingly as well as adds a test
for the new non-stake address error in the RPC handler.

Not only is this approach more efficient, it also removes the reliance
on address extraction which in turn removes the need for the flag which
specifies whether or not the treasury is active.
2021-06-09 00:29:08 -05:00
Dave Collins
62950c2b8b
stdscript: Add README.md. 2021-06-08 12:20:55 -05:00
Dave Collins
ad89f3d26d
stdscript: Add example of script hash extract.
This adds an example for extracting the script hash from a
pay-to-script-hash script.

This part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:55 -05:00
Dave Collins
0e468b838d
stdscript: Add example for p2pkh extract.
This adds an example for extracting the public key hash from a
p2pkh-ecdsa-secp256k1 script.

This part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:54 -05:00
Dave Collins
7b0e48e250
stdscript: Add example for determining script type.
This adds an example for determining the script type of a public key
script in terms of standardness.

This part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:54 -05:00
Dave Collins
5da74863ff
stdscript: Add v0 atomic swap redeem benchmark.
BenchmarkExtractAtomicSwapDataPushes
------------------------------------
v0_complex_not_atomic_swap    15944958   76.34 ns/op   0 B/op    0 allocs/op
v0_normal_valid_atomic_swap    3660967   335.9 ns/op   96 B/op   1 allocs/op

This part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:54 -05:00
Dave Collins
a52b5aec90
stdscript: Add v0 atomic swap redeem support.
This adds support for identifying if a redeem script is a version 0
atomic swap redeem script for an original pay-to-script-hash script as a
convenience method for consumers of the package.

Note that this is different than most other methods in the package in
that it applies to the redeem script as opposed to the public key script
and consequently there is no new script type introduced nor does the
overall script determination detect it.  This is the case because a
redeem script is the final push of a signature script that is itself a
redemption of a pay-to-script-hash script.

Full test coverage is included.

This is part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:53 -05:00
Dave Collins
bf5e5b4040
stdscript: Add ecdsa multisig creation script.
This adds a convenience method to create a standard version 0 ecdsa
multisignature redemption script that requires a threshold of signatures
from a set of public keys.

Full test coverage is included.

This is part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:53 -05:00
Dave Collins
2b099ba339
stdscript: Add determine script type benchmark.
BenchmarkDetermineScriptType
----------------------------
v0_complex_non_standard                  23581336   49.37 ns/op   0 allocs/op
v0_p2pk-ecdsa-secp256k1_uncomp          168650203   7.077 ns/op   0 allocs/op
v0_p2pk-ed25519                          85811743   14.22 ns/op   0 allocs/op
v0_p2pk-schnorr-secp256k1_comp_even      66687412   17.95 ns/op   0 allocs/op
v0_p2pkh-ecdsa-secp256k1                 79932855   15.51 ns/op   0 allocs/op
v0_p2pkh-ed25519                         49981048   24.53 ns/op   0 allocs/op
v0_p2pkh-schnorr-secp256k1               37498006   32.34 ns/op   0 allocs/op
v0_p2sh                                  52141040   23.39 ns/op   0 allocs/op
v0_multisig_1-of-1_compressed_pubkey     13393005   88.78 ns/op   0 allocs/op
v0_nulldata_no_data_push                 40623846   30.05 ns/op   0 allocs/op
v0_stake_sub_p2pkh-ecdsa-secp256k1       35731618   35.09 ns/op   0 allocs/op
v0_stake_sub_p2sh                        32320881   37.48 ns/op   0 allocs/op
v0_stake_gen_p2pkh-ecdsa-secp256k1       31518481   37.78 ns/op   0 allocs/op
v0_stake_gen_p2sh                        29044929   41.45 ns/op   0 allocs/op
v0_stake_revoke_p2pkh-ecdsa-secp256k1    26891238   40.93 ns/op   0 allocs/op
v0_stake_revoke_p2sh                     25999124   46.65 ns/op   0 allocs/op
v0_stake_change_p2pkh-ecdsa-secp256k1    27856704   44.25 ns/op   0 allocs/op
v0_stake_change_p2sh                     25236273   47.53 ns/op   0 allocs/op
v0_treasury_add                          28225464   42.33 ns/op   0 allocs/op
v0_treasury_gen_p2pkh-ecdsa-secp256k1    22417670   53.44 ns/op   0 allocs/op
v0_treasury_gen_p2sh                     23529964   52.03 ns/op   0 allocs/op

This is part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:52 -05:00
Dave Collins
e31b426a2d
stdscript: Add v0 treasury gen p2sh benchmark.
BenchmarkIsTreasuryGenScriptHashScript
--------------------------------------
v0_complex_non_standard       814816624   1.310 ns/op   0 allocs/op
v0_treasury_generation_p2sh   520297904   2.274 ns/op   0 allocs/op

This is part of a series of commits to fully implement the stdscript
package.
2021-06-08 12:20:52 -05:00