Commit graph

3486 commits

Author SHA1 Message Date
Dave Collins
b04b4c27ea Update the TODO section of README.md to latest. 2013-09-30 17:00:23 -05:00
Dave Collins
29ed09cc98 Add IsPushOnlyScript.
This commit adds an exported function, IsPushOnlyScript, which can be used
to tell whether or not a script only pushes data (only contains opcodes
that push data).
2013-09-30 16:54:54 -05:00
Dave Collins
5efc3ea23f Remove a couple of outdated comments. 2013-09-30 16:50:10 -05:00
Dave Collins
baa4c36618 Export ValdiateTransactionScript function.
This function allows the caller to execute and validate all scripts for
the passed transaction (which includes signature verification).
2013-09-30 16:47:37 -05:00
Dave Collins
3c7511a34b Export the CheckTransactionInputs function. 2013-09-30 16:44:01 -05:00
Dave Collins
e576962cb3 Export the CheckTransactionSanity function. 2013-09-30 16:43:10 -05:00
Dave Collins
6695cd15bb Export the IsCoinbase function. 2013-09-30 16:42:28 -05:00
Dave Collins
4eb135618a Export the IsFinalizedTransaction function. 2013-09-30 16:40:19 -05:00
Dave Collins
fc69776371 Expose a transaction store and related functions.
Several of the functions require a map of contextual transaction data to
use as a source for referenced transactions.  This commit exports the
underlying TxData type and creates a new type TxStore, which is a map of
points to the under TxData.  In addition, this commit exposes a new
function, FetchTransactionStore, which returns a transaction store
(TxStore) containing all of the transactions referenced by the passed
transaction, as well as the existing transaction if it already exists.

This paves the way for subsequent commits which will expose some of the
functions which depend on this transaction store.
2013-09-30 16:37:11 -05:00
Dave Collins
ea256aeb5a Update a few comments. 2013-09-29 15:26:25 -05:00
Dave Collins
9880cf4646 Improve chain notification handling.
Previously a new goroutine was launched for each notification in order to
avoid blocking chain from continuing while the notification is being
processed.  This approach had a couple of issues.

First, since goroutines are not guaranteed to execute in any given order,
the notifications were no longer handled in the same order as they were
sent.  For the current code, this is not a problem, but upcoming code that
handles a transaction memory pool, the order needs to be correct.

Second, goroutines are relatively cheap, but it's still quite a bit of
overhead to launch 3-4 goroutines per block.

This commit modifies the handling code to have a single sink executing in
a separate goroutine.  The main handler then adds the notifications to a
queue which is processed by the sink.  This approach retains the
non-blocking behavior of the previous approach, but also keeps the order
correct and, as an additional benefit, is also more efficient.
2013-09-28 22:13:22 -05:00
Dave Collins
f1cd96ceb5 Update a few comments. 2013-09-26 21:06:01 -05:00
Owain G. Ainsworth
b97db056c1 Move the inventory handling from peer into blockmanager.
This removes a horrible case of reach-around from per into the guts of
the blockmaanger to frob the chain. Soon, when we try to deduplicate the
fetching of blocks from multiple peers this will need decisions made in
a central point.

Discussed at length with davec.
2013-09-27 01:51:05 +01:00
Todd T. Fries
790ba87979 reset retrycount upon successful connection 2013-09-26 16:52:05 -05:00
Todd T. Fries
1e77c8e554 update with knits from davec and an additional one from me 2013-09-26 16:45:10 -05:00
Todd T. Fries
568c0044a0 introduce a backoff behavior for peers that are not permitting connections
with help from davec

o implement peer { retrycount int64 ..
o count connect failures per peer
o calculate backoff as 10s * retrycount / 2
2013-09-26 16:26:31 -05:00
Marco Peereboom
e840c8314c catch up with api changes 2013-09-26 10:15:14 -05:00
Dave Collins
2f743b4821 Pre-allocate space for high use slices.
This commit modifies the code to choose sane defaults for the backing
arrays for slices that involve a lot of appends such block locators, hash
processing, and needed transactions.  This is an optimization to avoid
the overhead of growing the backing arrays and copying the data multiple
times in the most common case.  This also prevents a leak in Go GC which
will likely ultimatley be fixed, but the efficiecy gains alone are worth
the change.
2013-09-25 20:20:53 -05:00
Owain G. Ainsworth
0a3e7f682b Avoid the risk of leaking small amounts of memory.
Removing from the bottom of a stack (nipN(depth)) would leak the first
entry in the array by slicing [1:], leaving array[0] dangling an
inaccessible (but unable to be freed until the whole slice is gone). We
left it like this for a while, but best not to leak the memory. Happens
rarely so the performance hit shouldn't matter that much. Do the same
thing for condstack.
2013-09-26 01:53:11 +01:00
Dale Rahn
3640f6d37c Version the leveldb (and keep compatibility with pre-versioned uncompressed databases. 2013-09-25 17:23:34 -04:00
Marco Peereboom
0e98349c98 disable compression, don't use cache and limit open files 2013-09-25 17:23:33 -04:00
Dave Collins
5f971e10e6 Pre-allocate space for slices.
Several of the messages store the parts that have a variable number of
elements as slices.  This commit modifies the code to choose sane defaults
for the backing arrays for the slices so when the entries are actually
appended, a lot of the overhead of growing the backing arrays and copying
the data multiple times is avoided.

Along the same lines, when decoding messages, the actual size is known and
now is pre-allocated instead of dynamically growing the backing array
thereby avoiding some overhead.
2013-09-25 14:38:28 -05:00
Owain G. Ainsworth
a63edcd2dc preallocate a few arrays.
When we do append loops, make an educated guess as to the size and make an array
with that capacity to avoid extra copying.

Doesn't affect the speed of the tests, over 4 runs the difference was lost in
the noise.
2013-09-25 17:38:20 +01:00
Owain G. Ainsworth
87e976a732 Add comment explaining OP_RESERVED behaviour with push ops. 2013-09-25 17:37:36 +01:00
David Hill
18b3e86179 FetchTxAllBySha needs to return err to the caller.
ok drahn@
2013-09-23 15:39:53 -04:00
Dave Collins
a69647b94d Handle notifications from chain in own goroutine.
This change is in response to the recent change in btcchain such that
notifications are no longer sent in their own goroutine.
2013-09-21 09:57:47 -05:00
Dave Collins
d1f1fe0752 Revert "Send notification in their own goroutine."
After discussion with others and thinking about the notification channel
some more, we've decided to leave it up to the caller to quickly handle
notifications.  While it is true that notification should be handled
quickly to not block the chain processing code unnecessarily, launching a
goroutine in chain means the notifications are no longer necessarily in
order.  Also, if the caller is not properly handling the notifications,
the goroutines end up sicking around forever.  By leaving it up to the
caller to quickly handle the notification or launch a goroutine as
necessary for the caller, it provides the flexibility to ensure proper
notification ordering as well as control over other things such as
how to handle backpressure.
2013-09-21 09:23:55 -05:00
Dave Collins
e7f808378e Make max payload for a transaction max block size.
The maximum payload for a transaction is limited to the size of a block
rather than the maximum payload for a given message.
2013-09-19 16:46:14 -05:00
Dale Rahn
00b183a8b5 Remove unreachable statement. ok davec@ 2013-09-19 15:09:18 -04:00
Dave Collins
9c8cd4dee1 Update sample config for recent go-flags fix.
The configuration file can now contain multiple entries for the
configuration options which allow more than one to be specified (addpeer,
connect).
2013-09-19 09:17:15 -05:00
Dave Collins
346ff6f9e2 Filter duplicate getblocks requests.
This commit adds detection and filtering for back-to-back duplicate
getblocks requests.  This is needed because the trigger for requesting
more blocks is receiving an orphan.  When the peer is further behind than
the number of blocks advertised via a single inventory message, the same
orphan block will be sent multiple times.  When the peer receives the
final inventory message, it too contains the orphan that was previously
sent.  This leads to a duplicate getblocks request that must be filtered
to prevent requesting the final series of blocks again.
2013-09-18 13:33:54 -05:00
Dave Collins
0195306ff7 Updated missed function call for lint rename. 2013-09-18 11:25:18 -05:00
Dave Collins
94c795dec4 Add AMGR prefix to log messages for consistency. 2013-09-18 11:21:19 -05:00
Dave Collins
a5cc716940 Address some minor things reported by golint. 2013-09-18 00:36:40 -05:00
Dave Collins
3ca1e82f66 Make go vet happy. 2013-09-18 00:27:47 -05:00
Dave Collins
465327c62d Expand environment variables in datadir.
This commit adds environment variable expansion and path cleaning to the
data directory.  This allows the user to specify data paths in the config
file such as datadir=~/.btcd/data and datadir=$SOMEVAR/btcd.  It also
adds usage instructions and an example to the sample btcd.conf file.
2013-09-18 00:16:57 -05:00
Dave Collins
f2190d21dd Add profile option to sample configuration file. 2013-09-17 17:28:07 -05:00
Dave Collins
eed4c4df9c Add log message for profile server listen port. 2013-09-17 17:15:49 -05:00
Dave Collins
fc0cd75046 gofmt. 2013-09-17 17:04:40 -05:00
Marco Peereboom
68f30c7367 add missing empty string test, pointed out by davec 2013-09-17 17:46:03 -04:00
Marco Peereboom
ada49f1413 Add a flag to enable live profiling.
The profile information can be seen with a browser on e.g.
http://localhost:6060/debug/pprof/
Alternatively, one can use the pprof tool as described at
http://golang.org/pkg/net/http/pprof/

ok davec
2013-09-17 17:40:27 -04:00
Dave Collins
7609ff396a Comment multi-peer connect while code is under dev. 2013-09-17 10:58:16 -05:00
Dave Collins
92a8605b24 Continue work on addrmgr and multi-peer.
- Remove leftover debug log prints
- Increment waitgroup outside of goroutine
- Various comment and log message consistency
- Combine peer setup and newPeer -> newInboundPeer
- Save and load peers.json to/from cfg.DataDir
- Only claim addrmgr needs more addresses when it has less than 1000
- Add warning if unkown peer on orphan block.
2013-09-17 10:48:47 -05:00
Owain G. Ainsworth
6c05e9d475 Flesh out addrmanger with some basic functionality.
Use it to add multiple peer support. We try and keep 8 outbound peers
active at all times.

This address manager is not as complete as the one in bitcoind yet, but
additional functionality is being worked on.

We currently handle (in a similar manner to bitcoind):

- biasing between new and already tried addresses based on number of connected
  peers.
- rejection of non-default ports until desparate
- address selection probabilities based on last successful connection and number
  of failures.
- routability checks based on known unroutable subnets.
- only connecting to each network `group' once at any one time.

We currently lack support for:
- tor ``addresses'' (an .onion address encoded in 64 bytes of ip address)
- full state save and restore (we just save a json with the list of known
  addresses in it)
- multiple buckets for new and tried addresses selected by a hash of address and
 source.  The current algorithm functions the same as bitcoind would with only
 one bucket for new and tried (making the address cache rather smaller than it
 otherwise would be).
2013-09-15 20:25:55 -05:00
Dave Collins
79bb334b9a Remove old regression test db in regtest mode.
The regression test mode is special in that the 'official' block test
suite requires an empty database to work properly.  Rather than having to
manual go delete it before each test, add code to automatically delete the
old regression test database when in regression test mode.
2013-09-15 16:58:02 -05:00
Dave Collins
f3cd8174bb Use the new btcdb.SupportedDBs for known db types. 2013-09-15 15:21:46 -05:00
Dave Collins
62e38e29e5 Add a new function named SupportedDBs.
This function allows the callers to programatically ascertain which
database backend drivers are registered and therefore supported.
2013-09-15 15:18:46 -05:00
Dave Collins
629a1c9d06 Rework the data path and db type handling.
This commit modifies the way the data paths are handled.  Since there will
ultimately be more data associated with each network than just the block
database, the data path has been modified to be "namespaced" based on the
network.  This allows all data associated with a specific network to
simply use the data path without having to worry about conflicts with data
from other networks.

In addition, this commit renames the block database to "blocks" plus a
suffix which denotes the database type.  This prevents issues that would
otherwise arise if the user decides to use a different database type and
a file/folder with the same name already eixsts but is of the old database
type.  For most users this won't matter, but it does provide nice
properties for testing and development as well since it makes it easy to
go back and forth between database types.

This commit also includes code to upgrade the old database paths to the
new ones so the change is seamless for the user.

Finally, bump the version to 0.2.0.
2013-09-15 14:25:32 -05:00
Dave Collins
252ecf8b00 Add basic infrastructure for upgrading btcd.
This commit adds a basic infrastructure to allow upgrades to happen to
btcd as needed.  This paves the way for the upcoming data path changes to
be automatically updated for the user as needed and also ensures any
future changes that might require upgrades already have an established
way of performing the needed upgrades.
2013-09-15 13:40:26 -05:00
Dave Collins
1c9a7095b3 Change --dbdir flag to --datadir.
This change paves the way for saving more than just the block database to
the filesystem (such as address manager data, index data, etc) where the
name "dbdir" no longer makes sense.
2013-09-13 18:02:10 -05:00