Commit graph

3525 commits

Author SHA1 Message Date
David Hill
4cb933d035 travis: test against latest patch release. 2017-01-11 15:54:27 -05:00
David Hill
ab0f30c00d mining: drop getwork support.
Since the Midstate is no longer needed, switch to using
crypto/sha256.
2017-01-11 13:51:57 -05:00
Alex
5ce0ed6009 Port getheaders JSON-RPC command from dcrd 2017-01-10 19:47:28 -07:00
Alex
7c44b6472f Port getheaders JSON-RPC command from dcrd 2017-01-10 19:11:18 -07:00
Chris Pacia
765ca28711 Add MerkleBlock deadline to CmdGetData 2017-01-10 12:29:43 -06:00
David Hill
4f12c97d0f Drop btcsuite/go-flags in favor of upstream 2017-01-09 14:10:18 -06:00
Alex
9f962b60d6 Add version command to JSON-RPC API for API versioning 2016-12-22 14:48:53 -05:00
Alex
0519b86a9d Add version command to JSON-RPC API for API versioning 2016-12-22 12:38:38 -05:00
Alex Bosworth
602232500e Update rpcserver.go
correct comment typo
2016-12-13 13:49:52 -08:00
David de Kloet
7a4cc89bbc goclean.sh: Make it more robust
Fail fast if glide or gometalinter isn't available.
And also fail if running glide or gometalinter fails.

Before goclean.sh could pass even if glide or gometalinter wasn't
available at all. It seems that even though we use `set -ex`, their
failure was hidden either inside the $() or behind the pipe.
2016-12-09 23:06:51 +01:00
David de Kloet
4021ae2f6e server.go: Optimize newAddressFunc
Change the order of conditions to avoid calling fmt.Sprintf
unnecessarily.
2016-12-08 22:55:43 +01:00
Dave Collins
f65788d0a1
integration: Add BIP0009 state transition tests
This adds tests which exercise the BIP0009 state transitions using the
newly available soft fork status information in the getblockchaininfo
RPC.

The following is an overview of the tests added:
- Assert the chain height is 0 and the state is ThresholdDefined
- Generate 1 fewer blocks than needed to reach the first state
  transition
  - Assert chain height is expected and state is still ThresholdDefined
- Generate 1 more block to reach the first state transition
  - Assert chain height is expected and state moved to ThresholdStarted
- Generate enough blocks to reach the next state transition window, but
  only signal support in 1 fewer than the required number to achieve
  ThresholdLockedIn
- Assert chain height is expected and state is still ThresholdStarted
- Generate enough blocks to reach the next state transition window with
  only the exact number of blocks required to achieve locked in status
  signalling support
- Assert chain height is expected and state moved to ThresholdLockedIn
- Generate 1 fewer blocks than needed to reach the next state transition
- Assert chain height is expected and state is still ThresholdLockedIn
- Generate 1 more block to reach the next state transition
- Assert chain height is expected and state moved to ThresholdActive

In addition, it updates the existing BIP0009 mining tests to include
extra assertions that the chain height is at the expected height in
addition to checking that the bits are correctly set according to the
expected state.
2016-12-07 10:41:40 -06:00
Dave Collins
cb05e9b9cf
rpctest: Prevent race during teardown. 2016-12-07 10:41:35 -06:00
John C. Vernaleo
7903290fd9 Remove -v from go test.
This caused unhelpful clutter in travis output.

Closes #106
2016-12-07 10:14:06 -05:00
John C. Vernaleo
53edcec224 Remove -v from go test.
This caused unhelpful clutter in travis output.

Closes #877
2016-12-07 10:10:06 -05:00
Olaoluwa Osuntokun
7b0380cdd3
rpcserver: implement the getblockchaininfo RPC call 2016-12-06 16:24:51 -08:00
Olaoluwa Osuntokun
ec1c93ecc0
btcjson: update the fields of GetBlockChainInfoResult
This commit updates the fields of GetBlockChainInfoResult to reflect
the current state of the RPC as widely implemented by other full-node
implementations.
2016-12-06 16:24:43 -08:00
David de Kloet
c5751b75a9 wire: Treat NetAddress more like immutable
Replace assignments to individual fields of wire.NetAddress with
creating the entire object at once, as one would do if the type was
immutable.

In some places this replaces the creation of a NetAddress with a
high-precision timestamp with a call to a 'constructor' that converts
the timestamp to single second precision. For consistency, the tests
have also been changed to use single-precision timestamps.

Lastly, the number of allocations in readNetAddress have been reduced by
reading the services directly into the NetAddress instead of first into
a temporary variable.
2016-12-06 20:48:02 +01:00
Dave Collins
712399c0db
blockchain: Correct startup threshold state warns.
The thresholdState and deploymentState functions expect the block node
for the block prior to which the threshold state is calculated, however
the startup code which checked the threshold states was using the
current best node instead of its parent.

While here, also update the comments and rename a couple of variables to
help make this fact more clear.
2016-12-03 13:42:26 -06:00
Dave Collins
bc576b13b4
txscript: Only do CSV txver check if enabled.
The CSV consensus rules dictate that the opcode fails when the
transaction version is not at least version 2, however that only applies
if the disable flag is not set in the sequence.

This is not an issue at the current time because we do not yet enforce
CSV at a consensus level, however, I noticed this discrepancy when doing
a thorough audit of the CSV paths due to the ongoing work to add full
consensus-enforced CSV support.

As a result, this must be merged prior to enabling consensus enforcement
for CSV or it would open up the potential for a hard fork.
2016-12-03 12:33:57 -06:00
Dave Collins
318c4760c0
blockchain: Only enforce BIP0030 prior to BIP0034.
This modifies the code to only enforce the fairly expensive BIP0030
(duplicate transcactions) checks when the chain has not yet reached the
BIP0034 activation height (and is not one of the 2 special historical
blocks that break the rule and prompted BIP0034 to being with) since
that BIP made it impossible to create duplicate coinbases and thus
removed the possibility of creating transactions that overwrite older
ones.

This is a rather large optimization because the check is expensive due
to involving a ton of cache misses in the utxoset.  For example, the
following are times it took to perform the BIP0030 check on blocks
425490 - 425502 and a system with a relatively old Hitachi spinner HDD:

block 425490: 674.5857ms
block 425491: 726.5923ms
block 425492: 827.6051ms
block 425493: 680.0863ms
block 425494: 722.0917ms
block 425495: 700.0889ms
block 425496: 647.5823ms
block 425497: 445.0565ms
block 425498: 602.5765ms
block 425499: 375.0476ms
block 425500: 771.0979ms
block 425501: 461.5586ms
block 425502: 603.0766ms

As can be seen from these numbers, this reduces the block validation
time by an average of just over half a second for the given
representative data set and hardware.

Signed-off-by: Dave Collins <davec@conformal.com>
2016-12-02 15:18:07 -06:00
David Hill
2e93ea6ca6 btcjson: Add versionHex to getblock[header] results
rpcserver:  Set versionHex in responses.
2016-12-02 12:49:02 -05:00
Dave Collins
9cdc1b8afd
blockchain: Remove isMajorityVersion code.
Now that all softforking is done via BIP0009 versionbits, replace the
old isMajorityVersion deployment mechanism with hard coded historical
block heights at which they became active.

Since the activation heights vary per network, this adds new parameters
to the chaincfg.Params struct for them and sets the correct heights at
which each softfork became active on each chain.

It should be noted that this is a technically hard fork since the
behavior of alternate chain history is different with these hard-coded
activation heights as opposed to the old isMajorityVersion code.  In
particular, an alternate chain history could activate one of the soft
forks earlier than these hard-coded heights which means the old code
would reject blocks which violate the new soft fork rules whereas this
new code would not.

However, all of the soft forks this refers to were activated so far in
the chain history there is there is no way a reorg that long could
happen and checkpoints reject alternate chains before the most recent
checkpoint anyways.  Furthermore, the same change was made in Bitcoin
Core so this needs to be changed to be consistent anyways.
2016-11-30 14:26:13 -06:00
Dave Collins
bfbaff9fae
integration: Add BIP9 mining tests. 2016-11-30 13:52:23 -06:00
Dave Collins
25520b40ad
rpctest: Update for removal of wire.BlockVersion
This adds constant for the block version to the rpctest package since it
is no longer available via the wire package due to the new BIP0009 code.
2016-11-30 13:52:20 -06:00
Dave Collins
c440584efc
Implement infrastructure for BIP0009.
This commit adds all of the infrastructure needed to support BIP0009
soft forks.

The following is an overview of the changes:

- Add new configuration options to the chaincfg package which allows the
  rule deployments to be defined per chain
- Implement code to calculate the threshold state as required by BIP0009
  - Use threshold state caches that are stored to the database in order
    to accelerate startup time
  - Remove caches that are invalid due to definition changes in the
    params including additions, deletions, and changes to existing
    entries
- Detect and warn when a new unknown rule is about to activate or has
  been activated in the block connection code
- Detect and warn when 50% of the last 100 blocks have unexpected
  versions.
- Remove the latest block version from wire since it no longer applies
- Add a version parameter to the wire.NewBlockHeader function since the
  default is no longer available
- Update the miner block template generation code to use the calculated
  block version based on the currently defined rule deployments and
  their threshold states as of the previous block
- Add tests for new error type
- Add tests for threshold state cache
2016-11-30 13:51:59 -06:00
Steven Roose
95e6de00b8 btcd: fix error in mempool response inv counting 2016-11-25 10:30:24 +01:00
Dave Collins
afec1bd124
build: Give linters longer and cleanup goclean.sh.
This modifies the goclean.sh script to expand the deadline for the
linters to run to 4 minutes and ensures the comments match reality.
2016-11-21 09:33:32 -06:00
David de Kloet
34b9721494 docs: Clarify model commit message summary
Add a paragraph about prefixing commit message summaries with the
package/subsystem that they're changing to
code_contribution_guidelines.md.
2016-11-21 09:02:40 -06:00
dskloet
e1b2ceca80 addrmgr: Remove unused param from GetAddress()
addrmgr.GetAddress() had a parameter `class string` originally intended
to support looking up addresses according to some type of filter such as
IPv4, IPv6, and only those which support specific wire.ServiceFlags
(full nodes, nodes that support bloom filters, nodes that support
segwit, etc). But currently the parameter is unused and also has an
inappropriate type `string`.

If it would ever be used, it's easy to add back and should then get an
appropriate type such as something that allows bitflags to be set so
that the caller could request combinations such as peers that support
IPv6, are full nodes, and support bloom filters.
2016-11-21 08:56:46 -06:00
Javed Khan
7f237aa5e5 peer: disconnected peer - return non-nil LocalAddr 2016-11-19 15:05:51 -06:00
Dave Collins
1b800b69cf
build: Add unconvert linter to goclean.sh.
This modifies the goclean.sh script to include the unconvert lint tool
in the gometalinter configuration.
2016-11-16 15:20:07 -06:00
Dave Collins
36af96160d Remove unnecessary convs found by unconvert.
This removes all unnecessary typecast conversions as found by the
unconvert linter.
2016-11-16 15:16:16 -06:00
Dave Collins
f9ac1a7786 build: Add gosimple linter to goclean.sh.
This modifies the goclean.sh script to include the gosimple lint tool to
the gometalinter configuration.
2016-11-16 15:07:40 -06:00
Dave Collins
b83f837ad2 Simplify code per gosimple linter.
This simplifies the code based on the recommendations of the gosimple
lint tool.
2016-11-16 15:05:11 -06:00
John C. Vernaleo
5c3e647618 Add gofmt to metalinter.
Fix one issue it caught.

This depends on PR#97
2016-11-16 16:01:47 -05:00
John C. Vernaleo
441bb918ec Modify goclean to use gometalint like btcd 2016-11-16 15:00:41 -06:00
David Hill
b134beb3b7 txscript: reduce allocs in calcSignatureHash 2016-11-16 12:28:22 -06:00
David Hill
187355448a wire: reduce allocs in BlockHash() 2016-11-16 11:29:09 -06:00
David Hill
807d344fe9 Unassign some TODO's 2016-11-15 17:47:33 -06:00
David Hill
d9a674e1b7 btcjson: add ErrRPCClientNodeNotAdded 2016-11-14 18:44:38 -05:00
Steven Roose
7cc630b335 docs: Change error in heading 2016-11-12 14:52:47 +01:00
Dave Collins
0d4546c965
server: Return error on address lookup fails.
This corrects an issue introduced by commit
e8f63bc295 where a failure to lookup a
hostname could lead to a panic in certain circumstances.  An error is
now returned in that case as expected.
2016-11-11 20:54:25 -06:00
Dave Collins
089611a61b
peer: No error log on unexpected EOF.
This modifies the error handling path in the peer read loop such that it
will no longer log an error when the error is io.ErrUnexpectedEOF.  This
is being done because that error is almost always the result of a peer
being remotely disconnected and thus it isn't useful information to log.

However, since it might actually be due to a malformed message, a reject
message is still queued up to be sent back to the peer (which will
simply be discarded if the peer disconnected) before it is disconnected.

While it would be ideal to only log if it's not due to a disconnect, and
the code already attempts to handle that, it's not 100% possible to
detect upon the read returning an error without attempting to read again
which will not happen until the next loop iteration.
2016-11-10 19:00:37 -06:00
Olaoluwa Osuntokun
e8f63bc295
connmgr: switch to using net.Addr interface throughout for addresses
This commit modifies the `ConnManager` to use the `net.Add` interface
through the package instead of a plain string to represent and
manipulate addresses. This change makes the package much more general as
users of the package can possibly utilize custom implementations of the
`net.Addr` interface to establish connections.

More precisely, the `ConnReq` struct has been modified to use a net.Addr
instance explicitly, and the `DialFunc` type has also been modified to
take a `net.Addr` directly. This latter change gives functions that
adhere to the `DialFunc` type more flexibility as to exactly how the
connection is established.

Additionally, the `connmgr.Config.GetNewAddress` configuration option
now directly returns a `net.Addr. This change allows the `connmgr` to be
decoupled from all DNS queries which allows callers to preferentially
select more secure methods like performing DNS lookups over a Tor proxy.
2016-11-10 11:22:36 -08:00
Olaoluwa Osuntokun
c6e1d711da review: fix typos 2016-11-09 11:13:10 -08:00
Olaoluwa Osuntokun
01050a2f82
add support for getblockchaininfo 2016-11-06 16:07:47 -08:00
Dave Collins
df33d4340e
server: Ensure callbacks use the server peer.
This modifies the signatures of all serverPeer callbacks that are
provided as peer.Listeners to use _ for the first parameter name which
ensures the passed peer can't be used within the function and updates
all references to the server peer.

This helps ensure any overridden methods that might be defined on a
serverPeer will be invoked where directly calling methods on the passed
peer would not.

Also, while here, add a comment to the OnFeeFilter function.
2016-11-04 13:38:13 -05:00
Dave Collins
b65881c137
connmgr: Add tests for new inbound listener logic. 2016-11-04 13:14:50 -05:00
Dave Collins
d98430d8ca
connmgr: Implement inbound connection handling.
This modifies the connection manager to provide support for accepting
inbound connections on a caller-provided set of listeners and notify the
caller via a callback.

This is only the minimum work necessary to get inbound support into the
connection manager.  The intention for future commits is to move more
connection-related logic such as limiting the maximum number of overall
connections and banned peer tracking into the connection manager.
2016-11-04 13:14:44 -05:00