Commit Graph

148 Commits

Author SHA1 Message Date
Dave Collins
ee4a0e2e2a
multi: Use dcrec/edwards/v2 module.
This updates the following modules to use the dcrec/edwards/v2 module:

- chaincfg/v2
- dcrutil/v2
- txscript/v2
2019-10-08 10:43:08 -05:00
Dave Collins
cebab1ef64
multi: Use secp256k1/v2 module.
This updates the following modules to use the secp256k1/v2 module:

- blockchain
- chaincfg/v2
- dcrutil/v2
- hdkeychain/v2
- mempool/v3
- txscript/v2
- main

The hdkeychain/v3 and txscript/v2 modules both use types from secp256k1
in their public API.

Consequently, in order avoid forcing them to bump their major versions,
secp256k1/v1.0.3 was released with the types redefined in terms of the
secp256k1/v2 module so callers still using v1 of the module that are not
ready to upgrade to the v2 module yet can interoperate by updating to
the latest patch version.
2019-10-08 10:14:13 -05:00
Dave Collins
3e2208f8c1
build: Replace TravisCI with CI via Github actions. 2019-09-20 19:59:04 -05:00
Aaron Campbell
8be96a8729 multi: Correct typos.
Correct typos found by reading code, ispell, and creative grepping.
2019-08-22 10:20:03 -05:00
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
25c14e046a
main: Update to use all new major module versions.
This updates all code in the main module to use the latest major modules
versions to pull in the latest updates.

A more general high level overview of the changes is provided below,
however, there is one semantic change worth calling out independently.

The verifymessage RPC will now return an error when provided with
an address that is not for the current active network and the RPC server
version has been bumped accordingly.

Previously, it would return false which indicated the signature is
invalid, even when the provided signature was actually valid for the
other network.  Said behavior was not really incorrect since the
address, signature, and message combination is in fact invalid for the
current active network, however, that result could be somewhat
misleading since a false result could easily be interpreted to mean the
signature is actually invalid altogether which is distinct from the case
of the address being for a different network.  Therefore, it is
preferable to explicitly return an error in the case of an address on
the wrong network to cleanly separate these cases.

The following is a high level overview of the changes:

- Replace all calls to removed blockchain merkle root, pow, subsidy, and
  coinbase funcs with their standalone module equivalents
  - Introduce a new local func named calcTxTreeMerkleRoot that accepts
    dcrutil.Tx as before and defers to the new standalone func
- Update block locator handling to match the new signature required by
  the peer/v2 module
  - Introduce a new local func named chainBlockLocatorToHashes which
    performs the necessary conversion
- Update all references to old v1 chaincfg params global instances to
  use the new v2 functions
- Modify all cases that parse addresses to provide the now required
  current network params
  - Include address params with the wsClientFilter
- Replace removed v1 chaincfg constants with local constants
- Create subsidy cache during server init and pass it to the relevant
  subsystems
  - blockManagerConfig
  - BlkTmplGenerator
  - rpcServer
  - VotingWallet
- Update mining code that creates the block one coinbase transaction to
  create the output scripts as defined in the v2 params
- Replace old v2 dcrjson constant references with new types module
- Fix various comment typos
- Update fees module to use the latest major module versions and bump it v2
2019-08-13 11:22:37 -05:00
Nicola Larosa
1149d54cb9 multi: Use crypto/blake256.
This updates the code to make use of the new crypto/blake256 module instead of
github.com/dchest/blake256.

* change the references in the chaincfg/chainhash and gcs modules
* update chaincfg/chainhash to use the new Sum256 API
* remove references to dchest/blake256 from all go.sum files
2019-08-07 18:54:55 -05:00
Nicola Larosa
2fa28e2a43 crypto/blake256: Add module with zero alloc funcs. 2019-08-07 10:00:01 -05:00
Dave Collins
7dc2016569
chaincfg: Add subsidy params accessor funcs.
This defines several new functions on the Params struct which return
some subsidy-related parameters.

The new functions are:

- BaseSubsidyValue
- SubsidyReductionMultiplier
- SubsidyReductionDivisor
- SubsidyReductionIntervalBlocks
- WorkSubsidyProportion
- StakeSubsidyProportion
- TreasurySubsidyProportion

This will allow the parameters to be used directly as input to an
interface in the future.
2019-08-05 00:25:40 -05:00
Dave Collins
3569affd05
chaincfg: Add stake params accessor funcs.
This defines several new functions on the Params struct which return
some stake-related parameters.

The new functions are:

- VotesPerBlock
- StakeValidationBeginHeight
- StakeEnableHeight
- TicketExpiryBlocks

This will allow the parameters to be used directly as input to an
interface in the future.
2019-07-28 14:27:27 -05:00
Josh Rickmar
f860883562 chaincfg: Avoid block 1 subsidy codegen explosion.
chaincfg/v2 modified the Params type to contain the required payouts
created by the miner of the block at height 1.  However, it was
discovered that, due to code generation issues of the Go compiler,
this caused the package's weight (measured by
github.com/jondot/goweight) to explode to 7.7 MB.  This appears to be
due to an enormous amount of function calls, all of which could panic,
when building the large slice literal.

This improves the compiled size of the package by using code
generation techniques to optimize the memory layout and code
transformation of the subsidy values each time a params function is
called.  A single string contains all scripts for subsidy payouts
concatenated together, in hex encoding, and a slice contains the index
in the script data and the required payout amount.  This is iterated
in a loop to create a []TokenPayout each time it is needed.

The new size of the compiled package using Go 1.12.7 on OpenBSD/amd64
is 379 kB, a reduction of 7.32 MB, and about 5% of the original size.
2019-07-28 14:19:13 -05:00
Dave Collins
1d133626ba
chaincfg: Run gofmt -s. 2019-06-26 19:27:56 -05:00
David Hill
893aa30dce multi: Use https links where available. 2019-06-18 14:20:06 -05:00
Dave Collins
2968070c7b
chaincfg: Add addr params accessor funcs.
This defines several new functions on the Params struct which return the
magic prefix bytes for addresses.

The new functions are:

- AddrIDPubKeyV0
- AddrIDPubKeyHashECDSAV0
- AddrIDPubKeyHashEd25519V0
- AddrIDPubKeyHashSchnorrV0
- AddrIDScriptHashV0

This will allow the parameters to be used directly as input to an
interface in the future.
2019-06-14 17:55:37 -05:00
Dave Collins
5070857dbe
chaincfg: Use dcrec/edwards/v1.0.0.
This updates the chaincfg module to make use of the recently-tagged
dcrec/edwards v1 module and thereby corrects the dependencies for the
chainec package within the chaincfg/v2 module.
2019-06-13 01:37:13 -05:00
Dave Collins
c1e08e919e
chaincfg: Introduce chaincfg v2 module. 2019-06-12 20:14:34 -05:00
Dave Collins
cba25b056d
chaincfg: Convert global param defs to funcs.
The current network parameter definitions are all package-level globals
which have a few undesirable characteristics:

- They are subject to mutation and thus can easily cause subtle and hard
  to find bugs
- Many of the fields are defined in terms of others, but due to the
  struct being defined at the top level, it's not possible to reference
  other fields within it
- They require a lot of unexported global variable state
- It makes it difficult to introduce a base set of parameters that would
  likely help highlight exactly what the differences are between the
  networks

Consequently, this converts all of the global network parameter
defintions to functions that return a new instance of the relevant
parameters which either directly addresses the aforementioned point, or
at the very least, allows them to be addresses in future commits.

The following is a high level overview of the changes:

- Move all default definitions into functions that return a new instance
  of the relevant params
- Move global defintions of variables used in the structs into the
  relevant funcs
- Improve consistency in the tests for each set of network params
- Update example in README.md
- Update example doc.go
2019-06-12 20:14:34 -05:00
Dave Collins
b863fd5875
chaincfg: Use scripts in block one token payouts.
This modifies the definitions for the required payouts in block one to
define required scripts instead of an address string as well as specify
the required script version and updates all of the network params
accordingly.

This is being done because addresses are a non-consensus construct that
essentially provide a human-readable method of specifying the actual
underlying cryptographic primitives.  Thus, the consensus rules
themselves must not directly rely on the ability to interpret and parse
addresses.

It is important to note that, once the blockchain code is updated to
make use of the changes this introduces, it is technically a fork since
the code will be more restrictive, but since it only applies to block
one, it's irrelevant because:

- It's buried under years of blocks
- The actual ledger of block one is unchanged
2019-06-12 20:14:33 -05:00
Dave Collins
0f368c29c8
chaincfg: Concrete genesis hash in Params struct.
This modifies the Params struct to store the genesis hash directly
instead of a pointer to it.  This makes it more consistent with the rest
of the code base and avoids the need for a separate variable.
2019-06-12 20:14:32 -05:00
Dave Collins
85a0e66eea
chaincfg: Move regnet code to regnet files.
This moves the various code that is specific to regnet to the
regnetparams.go file to keep the information housed together.  Along the
same lines, it moves the tests specific to the regnet params to
regnetparams_test.go.

It also unexports the block one ledger definition since it should only
be exposed via the params.
2019-06-12 20:14:31 -05:00
Dave Collins
4dab5d430a
chaincfg: Move simnet code to testnet files.
This moves the various code that is specific to simnet to the
simnetparams.go file to keep the information housed together.  Along the
same lines, it moves the tests specific to the simnet params to
simnetparams_test.go.

It also unexports the block one ledger definition since it should only
be exposed via the params.
2019-06-12 20:14:31 -05:00
Dave Collins
8b333b7eb1
chaincfg: Move testnet3 code to testnet files.
This moves the various code that is specific to testnet to the
testnetparams.go file to keep the information housed together.  Along
the same lines, it moves the tests specific to the testnet params to
testnetparams_test.go.

It also unexports the block one ledger definition since it should only
be exposed via the params.
2019-06-12 20:14:30 -05:00
Dave Collins
52c63f898b
chaincfg: Move mainnet code to mainnet files.
This moves the various code that is specific to mainnet to the
mainnetparams.go file to keep the information housed together.  Along
the same lines, it moves the tests specific to the mainnet params to
mainnetparams_test.go.

It also unexports the block on ledger definition since it should only be
exposed via the params.
2019-06-12 20:14:29 -05:00
Dave Collins
31ee27e63f
chaincfg: Remove all registration capabilities.
This removes all of the global registration capabilities from chaincfg
as part of the overall drive towards removing side effects that alter
the global state when importing packages and providing cleaner module
boundaries by reducing tight coupling betwee them.

For a bit of history, the package was designed back near the time Go
released before anyone had much experience with Go based on some other
early examples in the stdlib which many, including most of the original
authors, have come to realize is not ideal because it essentially alters
global state and has side effects merely by importing the package. This
can cause issues if multiple copies of the same package try to register
themselves.

Also, on a less theoretical note, with the benefit of hindsight and
experience, there isn't really any practical benefit to registering the
networks and allowing custom ones to be registered over just accepting a
params interface into the packages that need them whereas there are
tangible downsides having global registration factories as mentioned.
Accepting interfaces to the relevant functions in the other packages
will also significantly reduce the tight coupling that currently exists
with chaincfg and limit the scope of the needed parameters to
specifically those required by the functions in question.

An overview of the changes is as follows:

- Remove the following functions:
  - Register
  - IsPubKeyAddrID
  - IsPubKeyHashAddrID
  - IsPKHEdwardsAddrID
  - IsPKHSchnorrAddrID
  - IsScriptHashAddrID
  - HDPrivateKeyToPublicKeyID
  - ParamsByNetAddrPrefix
- Remove the following (now unused) errors:
  - ErrDuplicateNet
  - ErrUnknownHDKeyID
  - ErrDuplicateNetAddrPrefix
  - ErrUnknownNetAddrPrefix
- Remove all associated tests
- Update README to call out correct number of default net params
2019-06-12 20:14:29 -05:00
Dave Collins
e739f529e9
chaincfg; Add tests for required unique fields.
This adds a test to ensure that all of the network parameter fields that
are required to be unique are in fact unique for all of the provided
default parameters.

It should be noted that part of this is currently redundant with the
network registration code, however, that is going to be removed.
2019-06-12 20:14:28 -05:00
Dave Collins
ad93e76962
chaincfg: Move DNSSeed stringer next to type def. 2019-06-12 20:14:27 -05:00
Dave Collins
58438ac367
txscript: Remove CPUMinerThreads constant.
This removes the exported CPUMinerThreads constant because it is not a
per-chain parameter and therefore does not belong here.

Further, it is only used in the mining code and since it's an exported
constant, it couldn't be changed without a major version bump and there
is no reason this shouldn't be defined in the mining code itself.
2019-06-12 20:14:27 -05:00
Dave Collins
cc7e6eaa1f
txscript: Remove CheckForDuplicateHashes constant.
This removes the exported CheckForDuplciateHashes constant because it is
not a per-chain parameter and therefore does not belong here.

Further, it is only used in blockchain and since it's an exported
constant, it couldn't be changed without a major version bump, which
would cause everything that relies on it to also bump majors.
2019-06-12 20:14:26 -05:00
Dave Collins
56451af752
txscript: Remove SigHashOptimization constant.
This removes the exported SigHashOptimization constant because it is not
a per-chain parameter and therefore does not belong here.

Further, it is only used in txscript and since it's an exported
constant, it couldn't be changed without a major version bump, which
would cause everything that relies on it to also bump majors.
2019-06-12 20:14:25 -05:00
David Hill
a808730220 dcrec: implement GenerateKey 2019-06-08 04:23:10 -05:00
Dave Collins
99ac29c86b
chaincfg: Rename extended key accessor funcs.
This renames the recently introduced accessor functions for obtaining
the hierarchical deterministic extended private and public key magic
version bytes based on feedback.

Ordinarily this would require a major module version bump, however,
since a new version with the functions has not been released yet, it is
acceptable to rename them without breaking callers.
2019-03-25 13:09:38 -05:00
Dave Collins
ef2be86991
chaincfg: Add extended key accessor funcs.
This defines two new functions named XPrivKeyID and XPubKeyID on the
Params struct which return the hierarchical deterministic extended
private and public key magic version bytes, respectively.

This will allow the parameters to be used directly as input to an
interface in the future.
2019-03-20 11:01:28 -05:00
Dave Collins
0f50fd5f8c
multi: Add go 1.11 directive to all modules.
This adds the go 1.11 directive to all of the modules in order to
clearly mark they build and work with that version.  Go 1.12 modified
the tools such that tidy will automatically add the new version to
modules that do not already have a directive and that would prevent
builds on Go 1.11 through Go 1.11.3 which is not desirable.
2019-03-18 02:02:35 -05:00
Dave Collins
4e477e019b
chaincfg: Introduce params lookup by addr prefix.
This exposes a new function to allow a caller to lookup any registered
parameters that are associated with a given network address prefix.
2019-03-16 19:26:17 -05:00
Dave Collins
9a67655606
chaincfg: Explicit unique net addr prefix.
This modifies the registration process to enforce the already implicit
assumption that the network address prefix is unique per network so that
it is now an explicit requirement.

This is desirable because the address format contains a network
identification byte which is used elsewhere in the code to uniquely
identify which parameters to use.
2019-03-16 15:47:20 -05:00
Dave Collins
2f43533302
chaincfg: Use expected regnet merkle root var.
This uses the expected merkle root variable in the genesis block
definition for the regression test network.  It's the same value so
there is no functional change.
2019-03-15 14:25:27 -05:00
Dave Collins
6abbe31569
chaincfg: Remove unused definition.
This removes the definition for genesisCoinbaseTxLegacy since it is not
used anywhere.
2019-03-15 14:10:56 -05:00
Hamid
e40b33a2b1 chaincfg: Move a test to chainhash package.
This moves a test in chaincfg which belongs to chainhash package.
The test case that has been moved has already been covered in
chainhash test suite, but instead of deleting the test case it has
been moved, so to have a stronger test suite.
2019-03-08 00:28:27 -06:00
David Hill
85443cafa9 multi: cleanup linter warnings 2019-02-13 08:38:25 -05:00
Dave Collins
e052b9cbf2
multi: Remove non-root module replacements.
This modifies all of the modules, with the exception of the root module,
to remove all replacement directives from their go.mod files and update
the requirements and module sums accordingly.

While it is nice to be able to build and test directly from each module
directory and have it pull in the latest untagged changes when
developing, having all of the overrides in each module makes it
infeasible to use the module tools to help maintain the modules and thus
makes it quite difficult to ensure they are all independently accurate
for external consumers.

By maintaining all of the overrides in the root module and invoking all
builds and tests from it, the overrides will apply to ensure the latest
code is being built and tested.

This also modifies the tests script used with in CI to run all of the
tests from the root module accordingly.
2019-02-08 18:01:43 -06:00
Dave Collins
7f75331d6d
chaincfg: Introduce agenda for fixlnseqlocks vote.
This adds a new definition for the upcoming agenda vote to enable the
corrected sequence locks behavior as defined by DCP0004.  It does not
include any code to make decisions or bump the versions.  It is only the
definition.

Also, bump the chaincfg module to v1.3.0 so the new definitions are
available to consumers.
2019-01-28 09:18:44 -06:00
Dave Collins
3542bcc283
chaincfg: Add checkpoints for upcoming release.
This adds a checkpoint to mainnet at height 295940 and testnet at height
83520.

Also, bump the chaincfg module to v1.2.1 so the new checkpoint are
available to consumers.
2018-12-12 16:31:01 -06:00
Dave Collins
1a370d38d6
release: Tidy module files with published versions. 2018-12-12 12:18:11 -06:00
Dave Collins
220d434b6e
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/dcrec/secp256k1@v1.0.1
- github.com/decred/dcrd/dcrjson@v1.1.0
- github.com/decred/dcrd/database@v1.0.3
- github.com/decred/dcrd/blockchain/stake@v1.1.0
- github.com/decred/dcrd/mining@v1.1.0
- github.com/decred/dcrd/certgen@v1.0.2
- github.com/decred/dcrd/connmgr@v1.0.2
- github.com/decred/dcrd/mempool@v1.1.0

In addition, it serves as a base for tagging releases of the following
module versions that have previous been bumped since the last release,
but not yet tagged:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain@v1.1.0
- github.com/decred/dcrd/hdkeychain@v1.1.1
- github.com/decred/dcrd/peer@v1.1.0
- github.com/decred/dcrd/rpcclient@v1.1.0

Finally, it updates all of the dependencies for every module accordingly,
adds a few missing overrides for transitive dependencies, and tidies up
some of the go module sum files.
2018-12-10 11:18:00 -06:00
Dave Collins
527399b852
chaincfg: Unexport internal errors.
These errors are only used internally and thus should not be exported.

While here, it also removes the completely unused VoteBitsNotFound
error.

It should be noted that this is a breaking change to the API and thus
will need a v2 major version bump of the chaincfg module to be published
before the changes can be externally consumed.
2018-10-10 17:56:16 -05:00
Dave Collins
15f7f61e32
multi: Latest consensus active from simnet genesis.
This modifies simnet to include the latest consensus changes that have
been successfully voted into mainnet to date starting from its genesis
block.  This means it is no longer necessary to vote those changes in to
simnet first before making use of them.

The changes entail removing the deployment entries for those votes,
updating the mining templates to start from version 5, which matches the
current mainnet version, and modifying the various sections in
blockchain which make decisions accordingly.

The chaincfg and blockchain modules are affected, but since their
version has already been bumped since their last release tags, they are
not bumped again.
2018-10-10 15:58:53 -05:00
Dave Collins
47ade78c1a
multi: Resurrect regression network.
This resurrects the regression test network that was removed before
initial launch although it really should not have been.  The simulation
test network and the regression test network do not serve the same
purpose.  Specifically, the regression test network is intended for unit
tests, RPC server tests, and consensus tests.  On the other hand, the
simulation test network is intended for private use within a group of
individuals doing simulation testing and full integration tests between
different applications such as wallets, voting service providers, mining
pools, block explorers, and other services that build on Decred.

Keeping the concerns separate will allow the simulation test network to
be modified in ways such as activating consensus changes that have been
successfully voted into mainnet without also needing to vote them in on
the simulation test network while still preserving the ability for the
unit tests to properly test the voting semantics and handling to help
prevent regressions.

In addition to resurrecting the regression test network, this also fully
fleshes out new values for the various addresses prefixes (Rk, Rs, Re,
etc), HD key prefixes (rprv, rpub), and treasury multisig details.

As a part of resurrecting the network, a new CLI flag `--regnet` is
added to allow the RPC test harness connect to a running instance, the
areas of the code which involve votes have been modified to allow the
votes to apply to the new network, and tests have been added to the
relevant modules.

This bumps the affected module versions as follows:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/hdkeychain@v1.1.1

The blockchain module is also affected, but since its version has
already been bumped since the last release tag, it is not bumped again.

Finally, this does not include switching unit tests or the RPC test
harness over the new network since that will be done in a separate
commit.
2018-10-09 18:52:13 -05:00
Dave Collins
36f61d8ebd build: Tidy module sums (go mod tidy). 2018-08-16 20:03:27 -05:00
Dave Collins
9536f0c88f
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/addrmgr@v1.0.2
- github.com/decred/dcrd/wire@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.1.1
- github.com/decred/dcrd/connmgr@v1.0.1
- github.com/decred/dcrd/dcrutil@v1.1.1
- github.com/decred/dcrd/database@v1.0.1
- github.com/decred/dcrd/hdkeychain@v1.1.0
- github.com/decred/dcrd/txscript@v1.0.1
- github.com/decred/dcrd/blockchain/stake@v1.0.1
- github.com/decred/dcrd/gcs@v1.0.1
- github.com/decred/dcrd/blockchain@v1.0.1
- github.com/decred/dcrd/mining@v1.0.1
- github.com/decred/dcrd/mempool@v1.0.1
- github.com/decred/dcrd/peer@v1.0.1
- github.com/decred/dcrd/rpcclient@v1.0.1

It also updates all of the dependencies for every module accordingly and
adds a few missing overrides for transitive dependencies.
2018-08-09 14:30:22 -05:00
Dave Collins
8fda21512f
multi: Remove testnet version 2 defs and refs.
This removes all definitions and references to the no longer available
testnet2 network.
2018-08-08 08:10:22 -05:00