Commit graph

2217 commits

Author SHA1 Message Date
Javed Khan
78e2c8401b Added new cmds importaddress, importpubkey 2015-02-07 11:09:13 +05:30
Josh Rickmar
fc8dae49e4 Make profiling easier to follow with static dispatch.
For example, when performing a heap profile, this:

         .          .    125:   fetchFunc := db.FetchUnSpentTxByShaList
         .          .    126:   if includeSpent {
         .          .    127:           fetchFunc = db.FetchTxByShaList
         .          .    128:   }
         .     9.11MB    129:   txReplyList := fetchFunc(txList)

Now becomes this:

         .          .    125:   var txReplyList []*database.TxListReply
         .          .    126:   if includeSpent {
         .          .    127:           txReplyList = db.FetchTxByShaList(txList)
         .          .    128:   } else {
         .     8.75MB    129:           txReplyList = db.FetchUnSpentTxByShaList(txList)
         .          .    130:   }

And it's clear where the majority of our allocations are coming from.
2015-02-06 22:14:13 -06:00
Dave Collins
2713c8528d Consistency and general cleanup in btcec.
This commit contains various modifications for code and comment
consistency in the btcec package:
- Call out references at the top and reference them by their identifier in
  the other comments
- Remove a TODO that no longer applies
- Add comments to the fields in the KoblitzCurve struct and reorder them
  slightly
- Make comments wrap to 80
- Cleanup code that was far exceeding col 80 (only function declarations
  typically do this)
- Extend block comments to use as much of the 80 cols as available
- Add a bit more explanation in a couple of places
- Update copyright year on secp256k1.go
- Fix a couple of typos in the comments
2015-02-06 16:55:34 -06:00
Dave Collins
4b84bd52dd Move the btcec benchmarks into the main package.
The benchmarks are still only compiled when running 'go test' so this has
no effect on regular usage.  This is being done because benchmarks often
need access to internal state.

Normal tests are kept in a separate package since they also serve to
exercise the public API, and by intentionally making it more difficult to
reach into the internals, it helps ensure the public API is sanely usable.

Since the benchmarks can now access the internals directly, this commit
also removes the functions which exposed the internals to the test package
from internal_test.go which were only used by the benchmarks.

Also, it removes a duplicate benchmark.
2015-02-06 16:53:29 -06:00
Dave Collins
86b4b12585 Correct btcd README to require Go 1.3. 2015-02-06 16:00:53 -06:00
Dave Collins
555778e9d5 Don't ignore errs setting consts in btcec init.
This commit converts the initialization of the constants to use a function
which panics on error instead of just ignoring the error.  This is
acceptable since they are hard-coded constants and should never fail.
2015-02-06 12:57:06 -06:00
Dave Collins
2b25107317 Add generation code for the endomorphism vectors.
This commit adds code which generates the linearly independent vectors
used by the secp256k1 endomorphism code.  These value are hard-coded into
the curve already, but having the code used to generate them is handy
should any future curves be added which can also make use of the same
class of endomorphism.
2015-02-06 12:45:49 -06:00
Dave Collins
e7c7c3399f Update btcec path import paths to new location. 2015-02-06 10:54:32 -06:00
Dave Collins
8134f68a4b Update TravisCI to ignore false positive in btcec.
Also correct format verb found by go vet.
2015-02-06 10:51:13 -06:00
Dave Collins
c360543fa9 Merge btcec repo into btcec directory. 2015-02-06 10:25:25 -06:00
Dave Collins
87968edb1d Import btcec repo into btcec directory. 2015-02-06 10:09:24 -06:00
Josh Rickmar
316d92d613 Update Go versions for Travis.
Also use Travis' container-based build infrastructure.
2015-02-06 10:02:09 -05:00
Dave Collins
c6bc8ac1eb Update btcnet path import paths to new location. 2015-02-05 23:24:53 -06:00
Dave Collins
76d84d4b40 Merge btcnet repo into chaincfg directory. 2015-02-05 21:54:45 -06:00
Dave Collins
40df138193 Import btcnet repo into chaincfg directory.
This commit contains the entire btcnet repository along with several
changes needed to move all of the files into the chaincfg directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcnet test files have been changed to the
  new location
- All references to btcnet as the package name have been changed to
  chaincfg
- The coveralls badge has been removed since it unfortunately doesn't
  support coverage of sub-packages

This is ongoing work toward #214.
2015-02-05 21:53:44 -06:00
Dave Collins
2e5bb96eea Correct a few instances of missed pkg name changes. 2015-02-05 17:54:04 -06:00
Olaoluwa Osuntokun
1b57f5bf87 Change searchrawtransaction to be compatible with bitcoind
* Pluralise `searchrawtransaction` -> `searchrawtransactions`
 * Change the `verbose` parameter from a bool to an int.
2015-02-05 15:31:39 -08:00
Olaoluwa Osuntokun
ecdffda748 Add support for an optional address-based transaction index.
* Address index is built up concurrently with the `--addrindex` flag.
* Entire index can be deleted with `--dropaddrindex`.
* New RPC call: `searchrawtransaction`
  * Returns all transacitons related to a particular address
  * Includes mempool transactions
  * Requires `--addrindex` to be activated and fully caught up.
* New `blockLogger` struct has been added to factor our common logging
  code
* Wiki and docs updated with new features.
2015-02-05 14:48:19 -08:00
Olaoluwa Osuntokun
86cbf27f58 Correct duplicated 'blockMsg' comment. 2015-02-05 14:30:43 -08:00
Dave Collins
03433dad6a Update btcwire path import paths to new location. 2015-02-05 15:16:39 -06:00
Dave Collins
d68ac86944 Update btcwire path import paths to new location. 2015-02-05 15:02:20 -06:00
Dave Collins
857a78fcdf Update btcwire path import paths to new location. 2015-02-05 14:57:50 -06:00
Dave Collins
979d67627f Update for recent TravisCI changes.
Also, override the struct tag checking which is broken in the latest go
vet.
2015-02-05 14:07:27 -06:00
Dave Collins
116736ee73 Run gofmt on wire directory. 2015-02-05 13:07:51 -06:00
Dave Collins
4dd7c939ed Update btcwire path import paths to new location. 2015-02-05 12:58:30 -06:00
Dave Collins
cf6fc57f27 Merge btcwire repo into wire directory. 2015-02-05 12:39:50 -06:00
Jimmy Song
6c36218ef3 Optimize ScalarMult with NAF
Use Non-Adjacent Form (NAF) of large numbers to reduce ScalarMult computation times.

Preliminary results indicate around a 8-9% speed improvement according to BenchmarkScalarMult.

The algorithm used is 3.77 from Guide to Elliptical Curve Crytography by Hankerson, et al.

This closes #3
2015-02-05 08:28:51 -06:00
Jimmy Song
95b23c293c Optimize ScalarMult using endomorphism
This implements a speedup to ScalarMult using the endomorphism available to secp256k1.

Note the constants lambda, beta, a1, b1, a2 and b2 are from here:

https://bitcointalk.org/index.php?topic=3238.0

Preliminary tests indicate a speedup of between 17%-20% (BenchScalarMult).

More speedup can probably be achieved once splitK uses something more like what fieldVal uses. Unfortunately, the prime for this math is the order of G (N), not P.

Note the NAF optimization was specifically not done as that's the purview of another issue.

Changed both ScalarMult and ScalarBaseMult to take advantage of curve.N to reduce k.
This results in a 80% speedup to large values of k for ScalarBaseMult.
Note the new test BenchmarkScalarBaseMultLarge is how that speedup number can
be checked.

This closes #1
2015-02-03 14:14:21 -06:00
John C. Vernaleo
d4d2f622b5 Fix bug and inconsistant error msg seen by lint. 2015-02-03 10:02:44 -06:00
Dave Collins
46829e8ddc Update TravisCI to use latest cover paths. 2015-02-03 09:47:09 -06:00
Dave Collins
9535058a7b Rework the pre-computed table generation and load.
This commit reworks the way that the pre-computed table which is used to
accelerate scalar base multiple is generated and loaded to make use of the
go generate infrastructure and greatly reduce the memory needed to compile
as well as speed up the compile.

Previously, the table was being generated using the in-memory
representation directly written into the file.  Since the table has a very
large number of entries, the Go compiler was taking up to nearly 1GB to
compile.  It also took a comparatively long period of time to compile.

Instead, this commit modifies the generated table to be a serialized,
compressed, and base64-encoded byte slice.  At init time, this process is
reversed to create the in-memory representation.  This approach provides
fast compile times with much lower memory needed to compile (16MB versus
1GB).  In addition, the init time cost is extremely low, especially as
compared to computing the entire table.

Finally, the automatic generation wasn't really automatic.  It is now
fully automatic with 'go generate'.
2015-02-01 03:26:51 -06:00
Dave Collins
2eef3720a9 Import btcwire repo into wire directory.
This commit contains the entire btcwire repository along with several
changes needed to move all of the files into the wire directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcwire test files have been changed to the
  new location
- All references to btcwire as the package name have been chagned to
  wire
- The coveralls badge has been removed since it unfortunately doesn't
  support coverage of sub-packages

This is ongoing work toward #214.
2015-01-31 14:59:57 -06:00
Dave Collins
642e3c741a Update TravisCI to goclean script.
This commit causes TravisCI to run several tools on each pull request and
commit to help ensure the code quality remains high.  This includes gofmt,
goimports, golint, go vet, the race detector, and coverage stats.

Also, it instructs TravisCI to use nicer container-based builds.
2015-01-30 22:21:39 -06:00
David Hill
0247ddff18 Use the goleveldb Has() API.
This change converts the leveldb database's ExistsSha() and
ExistsTxSha to use the goleveldb API.  Has() only returns if
the key exists and does not need to read the entire value into
memory resulting in less disk i/o and much less GC.
2015-01-30 19:44:38 -05:00
Dave Collins
624bbb3216 Update btcchain import paths to new location. 2015-01-30 16:25:42 -06:00
Dave Collins
612ff7f813 Update btcchain import paths to new location. 2015-01-30 16:04:26 -06:00
Dave Collins
74ae61f048 Merge btcchain repo into blockchain directory. 2015-01-30 15:54:07 -06:00
Dave Collins
b69a849114 Import btcchain repo into blockchain directory.
This commit contains the entire btcchain repository along with several
changes needed to move all of the files into the blockchain directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcchain test files have been changed to
  the new location
- All references to btcchain as the package name have been changed to
  blockchain
2015-01-30 15:49:59 -06:00
Olaoluwa Osuntokun
c01d175fde Relay inv msgs now include underlying data object
* When an inv is to be sent to the server for relaying, the sender
already has access to the underlying data. So
instead of requiring the relay to look up the data by
hash, the data is now coupled in the request message.
2015-01-30 10:52:07 -08:00
Dave Collins
3b1a15d0d5 Update btcscript import paths to new location. 2015-01-30 12:14:33 -06:00
Dave Collins
3f177c9895 Update btcscript import paths to new location. 2015-01-30 12:08:47 -06:00
Dave Collins
be11f23e14 Merge btcscript repo into txscript directory. 2015-01-30 10:36:49 -06:00
Dave Collins
cbda064842 Import btcscript repo into txscript directory.
This commit contains the entire btcscript repository along with several
changes needed to move all of the files into the txscript directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcscript test files have been changed to the
  new location
- All references to btcscript as the package name have been chagned to
  txscript

This is ongoing work toward #214.
2015-01-30 10:30:16 -06:00
David Hill
115cea2109 Add new flag ScriptVerifySigPushOnly.
The ScriptVerifySigPushOnly flag enforces signature scripts to
only contain pushed data.  This is rule 2 of BIP0062.

Mimics Bitcoin Core commit d752ba86c1872f64a4641cf77008826d32bde65f
2015-01-29 23:57:15 -05:00
Dave Collins
d7dbe25d97 Fix test error verbs found by go vet in the tests. 2015-01-29 16:26:49 -06:00
Dave Collins
7180e2a92b Make NOP1-NOP10 opcode execution non-standard.
This commit makes use of the new ScriptDiscourageUpgradableNops flag to
reject execution of NOP1 through NOP10 for transactions that are
considered standard.

This mirrors the behavior added to Bitcoin Core via pull request 5000.
2015-01-29 15:55:59 -06:00
d
8ebbd3a38e typo:using_bootrap_dat.md -> using_bootstrap_dat.md 2015-01-29 16:14:27 -05:00
Dave Collins
8e6abdb125 Make several of the reg tests more consistent.
This commit modifies various regression tests to make them more consistent
with other tests throughout the code base.

Also, it allows of all the tests to run in parallel.
2015-01-29 14:41:18 -06:00
David Hill
f513518b4f Discourage NOPs reserved for soft-fork upgrades
NOP1 through NOP10 are reserved for future soft-fork upgrades.  When
such an upgrade occurs, the NOP argument will then require verification.
Rejecting transactions that contain these NOPs into the mempool will
discourage those transactions from being mined elsewhere and ensure
btcd will never mine such transactions.  This prevents now
invalid scripts (according to the majority of hashing power) even if the
client has not yet upgraded.

Non-executed upgradable NOPs are still allowed as they will still be
valid post-upgrade.

Mimics Bitcoin Core commit 03914234b3c9c35d66b51d580fe727a0707394ca
2015-01-29 11:36:03 -05:00
Dave Collins
d67a0e207c Update for recent ScriptBuilder API change. 2015-01-29 00:11:19 -06:00