Commit Graph

4203 Commits

Author SHA1 Message Date
Hamid
bf2ae11be8 wire: Fix MsgCFTypes maximum payload length.
This commit fixes and improves MsgCFTypes maximum payload length.
The counter of FilterType in MsgCFTypes is varInt which for 256
FilterType it has 3 bytes size.
2019-03-25 17:01:20 -05:00
Hamid
9c6dfab8da wire: Accurate calculations of maximum length.
This makes messages maximum payload length calculations accurate.
In wire messages which contain arrays, the array items counter is
variable integer (varInt). Since we limit items count in the
arrays, the maximum size of these counters is limited, this causes
these counters encoded size in all cases be lower than maximum
integer encoded size (MaxVarIntPayload). This commit makes this
calculations accurate and makes them consistent with the rest of
the codebase.
2019-03-25 16:36:32 -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
bccd308af3
build: Tidy module sums (go mod tidy). 2019-03-25 11:37:00 -05:00
Matheus Degiovani
8cbb5ae69d rpctest: Introduce VotingWallet
This adds the VotingWallet struct with accompanying tests. The purpose
of this feature is to allow rpctest-based test suites to create chains
longer than the Stake Validation Height by providing a minimum working
voting wallet that purchases tickets and votes as required.
2019-03-22 15:07:52 -05:00
Hamid
edba35c971 dcrutil: Add tests for NewTxDeep.
This adds tests for NewTxDeep to make sure new MsgTx is deeply copied.
2019-03-21 15:48:40 -05:00
Hamid
9ae4670a7e wire: Add tests for MsgGetCFilter.
This adds standard wire tests for MsgGetCFilter. Summery of all
changes:
- Add standard wire test for MsgGetCFilter.
- Add an extended error checking for checking malformed encoded data
	returns correct errors. For this Message type what has been done
	is similar to what WireErrors is doing but it has been added in a
	different test to be explicit and for documentation purpose.
2019-03-21 15:43:23 -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
Jamie Holdstock
9a2e8e5067 docs: allowHighFees arg has been implemented.
Update the RPC docs which state that the allowHighFees argument of
sendrawtransaction is not implemented.
2019-03-20 09:55:37 -05:00
Dave Collins
c0e74f5ffa
bech32: Correct README links.
Also, add spaces to the end of the example links so the description
appears on the next line for consistency with other packages in the
repo.
2019-03-19 16:07:57 -05:00
Dave Collins
e6c9fddbaf
hdkeychain: Update README.md.
This updates the README.md in hdkeychain to account for changes made in
Decred, correct the NewMaster godoc example link, and format the
examples so the description is on the line after the link for
consistency with other packages in the code base.
2019-03-19 15:08:52 -05:00
Jamie Holdstock
598bd32a11 docs: move json rpc docs to mediawiki. 2019-03-19 17:33:38 +00:00
Dave Collins
f53b715ec8
bech32: Correct README build badge reference. 2019-03-19 10:49:44 -05:00
Matheus Degiovani
9b88dd0973
bech32: Initial Version
This is a port of the github.com/btcsuite/btcutil/bech32 package.

When compared to the original version, it introduces extra tests and
benchmarks and improves upon the performance of the original code in
significant ways, while maintaining the same public interface.
2019-03-19 12:06:47 -03:00
Dave Collins
6c5f65973b
blockchain: Remove unused params from block index. 2019-03-18 19:05:26 -05:00
Hamid
f41b9faeda wire: Add tests for BlockHeader (From)Bytes.
Checking Bytes() and FromBytes() of BlockHeader works correctly.
2019-03-18 11:42:42 -05:00
David Hill
3d2d557614 multi: deprecate DisableLog 2019-03-18 11:16:35 -05:00
David Hill
69bac3189f multi: drop init and just set default log 2019-03-18 11:16:35 -05:00
Dave Collins
0173adf9a4
server: Use lru cache module for addresses.
This updates the server known address cache to make use of the new
generic LRU cache provided by the lru module.
2019-03-18 10:08:51 -05:00
Dave Collins
fa047415fd
peer: Use lru cache module for nonces.
This updates the concrete peer sent nonces LRU cache to make use of the
new generic LRU cache provided by the lru module.

It also removes the nor longer necessary specialized implementation.
2019-03-18 10:08:45 -05:00
Dave Collins
eb1368a3c4
peer: Use lru cache module for inventory.
This updates the concrete peer known inventory LRU cache to make use of
the new generic LRU cache provided by the lru module.

It also removes the nor longer necessary specialized implementation.
2019-03-18 10:08:35 -05:00
Dave Collins
334820db6d
docs: Update for lru module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new lru module.
2019-03-18 10:08:29 -05:00
Dave Collins
15d7a9b7f1
lru: Implement a new module with generic LRU cache.
This implements a new module named lru which provides a concurrency safe
least-recently-used cache with nearly early O(1) lookups, inserts, and
deletions.  The cache is limited to a maximum number of items with
eviction for the oldest entry when the limit is exceeded.

This will allow the various concrete implementations to be updated to
make use of this shared module instead of duplicating code.  There is no
additional performance hit to making use of this generic version because
the internal list already causes the item to be boxed anyway, so the
addition of the interface for the type does not cause an additional
alloc.

This can be seen by comparing this generic implementation to the
existing concrete nonce implementation in peer:

BenchmarkCache   	 1 allocs/op
BenchmarkLruNonceList    1 allocs/op

It also includes comprehensive tests, a benchmark, full package
documentation, and a basic usage example.
2019-03-18 10:08:21 -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
David Hill
a9c87c67cb fees: drop unused chaincfg 2019-03-17 15:16:14 -05:00
Dave Collins
f1c519a8e5
server: Update for deprecated peer chaincfg.
This updates peer.Config in the server to set the new Net parameter
instead of the now deprecated ChainParams parameter.
2019-03-16 21:11:02 -05:00
Dave Collins
5473e7907f
peer: Deprecate dependency on chaincfg.
The only way the chain params are used by the peer is to ascertain the
network magic to use on the wire (the Net field), so rather than
requiring an entire chain params instance, it is desirable to reduce the
scope such that the caller only needs to specify the specific value the
module peer needs.

To that end, this introduces a new field named Net on the config struct
which the caller can optionally specify in the same vain as the chain
params could previously optionally be specified.

The ultimate goal is to remove the chaincfg dependency altogether,
however, since removing the public ChainParams field is a breaking API
change, the field is deprecated and, in order to maintain API
compatibility, some additional semantics around handling of the
optionalality of the new Net field are introduced.

In particular, the Net field is chosen as follows:

- Use the value specified by the caller directly when set
- Fallback to the network associated with the chain params when set
- Fallback to the test network if neither are set

Finally, it updates the example and tests to specify the network
directly and adds a new test which explicitly tests the new fallback
semantics.
2019-03-16 21:10:59 -05:00
Dave Collins
837b289343
peer: Consolidate tests into package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for export_test.go to bridge.
2019-03-16 20:55:28 -05:00
Dave Collins
bd9629caeb
dcrutil: Consolidate tests into package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for internal_test.go to bridge.
2019-03-16 20:41:23 -05:00
Dave Collins
3f87a3e8cb
dcrutil: Reduce global refs in addr unit tests.
This modifies the test code for the address unit tests to prefer using
local references over accessing the global parameters directly from the
chaincfg package.  It is a good idea to avoid global references as much
as possible in general for several reasons, but the primary goal of this
change is to help reduce the tight coupling and therefore simplify
refactors.
2019-03-16 20:26:31 -05:00
Dave Collins
cc484f03d5
dcrutil: Lookup params by addr prefix in chaincfg.
This modifies the code that looks up the params by a given network
prefix to make use of the new function provided by chaincfg in order to
ensure that it works with all registered networks as the package was
intended.
2019-03-16 19:54:44 -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
88601411f3
blockchain: Explicit script ver in coinbase checks.
This modifies the function which ensures the first block coinbase pays to
the outputs required by the chain params to explicitly require script
version 0 rather than using the DefaultScriptVersion from txscript which
is subject to change and could therefore easily inadvertently cause an
unintentional consensus break.

It also improves the error message while here.
2019-03-16 14:06:55 -05:00
Dave Collins
f4250ab9c0
blockchain: Deprecate BlockOneCoinbasePaysTokens.
This deprecates the exported BlockOneCoinbasePaysTokens function in
favor of an unexported variant.  This is being done since it is only
intended to be an internal function and thus should not be exported.

However, since unexporting the function is a break to the API, it
requires a major version bump to the blockchain module.  Therefore, the
exported function is retained and simply redefined in terms of the now
unexported definition.
2019-03-16 12:59:41 -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
Matheus Degiovani
18383aa1c2 rpctest: Add NodesConnected
This allows package users to check whether two nodes are connected.
2019-03-15 14:07:26 -05:00
Matheus Degiovani
aa8ca126da rpctest: Add RemoveNode
This allows users of this package to remove the connections between
nodes, so that situations such as reorgs can be simulated.
2019-03-15 14:07:26 -05:00
Dave Collins
6351f12ce7
main: Write memprofile on shutdown.
This modifies the --memprofile flag to write the memory profile on
shutdown as opposed to arbitrarily writing it after 20 minutes.
2019-03-12 10:43:11 -05:00
Dave Collins
8c477528f1
txscript: Introduce constant for max CSV bytes.
As is already well commented in the code, the sequence number parameter
of the CHECKSEQUENCEVERIFY opcode requires 5 bytes instead of the
standard 4 bytes allowed by math opcodes.  This introduces a constant
for the value instead of hardcoding 5 to increase readability and
potentially allow the value to be exported in the future.
2019-03-12 10:26:04 -05:00
Dave Collins
b19842a4c4
txscript: Introduce constant for max CLTV bytes.
As is already well commented in the code, the locktime parameter of the
CHECKLOCKTIMEVERIFY opcode requires 5 bytes instead of the standard 4
bytes allowed by math opcodes.  This introduces a constant for the value
instead of hardcoding 5 to increase readability and potentially allow
the value to be exported in the future.
2019-03-12 10:13:06 -05:00
Dave Collins
a729ce27e0
txscript: Tighten standardness pubkey checks.
This tightens the multisig and pay-to-pubkey standard script
identification functions to use the same strict pubkey requirements as
the consensus rules since standardness rules are generally intended to
be more restrictive than the consensus rules which implies they are at a
minimum at least as restrictive.

The tests are also updated to deal with the additional restriction
accordingly.
2019-03-11 19:33:27 -05:00
Jamie Holdstock
9a5161ce9e rpcserver: Add difficultyratio to getblockchaininfo.
Add DifficultyRatio to GetBlockChainInfoResult, and bump the minor rpc
version accordingly. This is to maintain consistency with GetDifficulty
RPC. Also deprecate the existing Difficuly field in
GetBlockChainInfoResult, to be removed in a future major version bump.
2019-03-11 00:44:17 -05:00
David Hill
602255adbc blockmanager: remove useless requestedEverBlocks 2019-03-10 13:42:47 -05:00
David Hill
7df505a369 blockmanager: remove unused requestedEverTxns 2019-03-10 13:42:47 -05:00
Hamid
bbada7521a wire: Fix maximum payload length of MsgAddr.
This fixes the calculation of the maximum payload size of MsgAddr.
The number of address in encoded MsgAddr is VarInt which its size for
the maximum size of allowed address is lower than MaxVarIntPayload.
2019-03-10 12:41:28 -05:00
David Hill
d25931fd35
multi: preallocate memory. 2019-03-09 16:43:48 -06:00
Dave Collins
03c9bbf1e5
txscript: Consistent checksigaltverify handling.
This introduces a new error named ErrCheckSigAltVerify and modifies the
opcodeCheckSigAltVerify handler to use the abstractVerify function along
with the new error.  This makes the handling consistent with all other
signature checking verification opcode handlers and ensures the error
both can be programmatically detected as well as be uniquely identified
as compared to a generic verify failure.
2019-03-08 20:36:04 -06:00
J Fixby
eb7e76f568 TravisCI: Set ./run_tests.sh executable perms. 2019-03-08 17:37:15 -06:00