Commit graph

3486 commits

Author SHA1 Message Date
Dave Collins
78e9b94d93 Implement transaction pool and relay.
This commit is a rather large one which implements transaction pool and
relay according to the protocol rules of the reference implementation.
It makes use of btcchain to ensure the transactions are valid for the
block chain and includes several stricter checks which determine if they
are "standard" or not before admitting them into the pool and relaying
them.

There are still a few TODOs around the more strict rules which determine
which transactions are willing to be mined, but the core checks which
are imperative (everything except the all of the "standard" checks really)
to operate as a good citizen on the bitcoin network are in place.
2013-10-03 22:31:54 -05:00
Dave Collins
3678153ae4 Allow regtest tool to be treated as a sync peer. 2013-10-03 22:31:00 -05:00
Dale Rahn
cda0b10082 Introduce an API change for btcdb
FetchTxBySha changes what it returns, it can now return a TxListReply and
and error if none are found.

FetchTxByShaList is renamed to FetchUnSpentTxByShaList to indicate that
it will (likey/eventually) only return Tx that have some unspent TxOuts.
Tx which are fully spent may not be (reliably) looked up using this API.
2013-10-03 16:51:34 -04:00
Dale Rahn
d58fb25d98 Update btcchain for btcdb API change. 2013-10-03 16:44:07 -04:00
Owain G. Ainsworth
182c4d9ee6 Remove peers from duplicate map *before* we restart sync.
Just in case this ordering causes problems.
2013-10-03 20:13:56 +01:00
Owain G. Ainsworth
6bb0b80bbb Ignore non-sync invs and don't relay invs if we are not yet caught up.
We originally wanted to also not fetch orphan parents in this commit, however,
I have discovered that if you are doing a main sync from a peer, if it
sends you an orphan you must fetch it, else you ahven't fetched
everything it told you about and thus it will nto send you end more invs
from the main sync.

So we always fetch orphan parents, but we still don't fetch from
non-sync peers (all invs from them will be unsolicited). Seems to fix some hangs
with multiple peers.
2013-10-03 20:13:56 +01:00
Dale Rahn
07d634c76a remove old API function. 2013-10-03 14:08:04 -04:00
Dale Rahn
78d4bfecd4 Remove obsolete API functions 2013-10-03 14:08:04 -04:00
Dave Collins
6dbc61e960 Remove the noverify option.
This was a development only option.
2013-10-03 13:01:18 -05:00
Dave Collins
0c6b79afb0 Don't disconnect on unrequested blocks for regtest.
The "official" regression test tool intentionally sends some unrequested
duplicate blocks to ensure the chain handling code does not fail when
trying to insert them.  This commit adds an exception to the block manager
which typically disconnects peers that send unrequested blocks (they are
misbehaving if they do this) for regression test mode.
2013-10-03 11:21:41 -05:00
Dave Collins
bd3a39ad4a Fix comment typo. 2013-10-03 11:10:57 -05:00
Owain G. Ainsworth
2b56e7a397 Don't need the blockpeermutex anymore.
Really, it would be nice to pass an interface{} into chain to be given
to us when the callback calls, it would avoid the awkward sidchanneling
through the map and should actually be more efffieint (pointer passing >
hashtable insert, lookup, then remove).
2013-10-03 16:13:47 +01:00
Dave Collins
b06aa1672a Initial implementation of IsCurrent func.
This commit adds a new function, IsCurrent, which can be used to determine
whether or not the chain believes it is current.

Update.
2013-10-03 10:05:44 -05:00
David Hill
9abf071308 increase default pagesize to 4096 on sqlite 2013-10-03 10:32:19 -04:00
Dave Collins
c1b327c06a Make the signal handling concurrent safe. 2013-10-03 09:29:18 -05:00
John C. Vernaleo
35c95f0a36 Handle case where no auth is sent to rpcserver. 2013-10-03 08:12:18 -04:00
Dave Collins
fd0679acdd Update notification for recent btcchain API change. 2013-10-02 21:21:52 -05:00
Dave Collins
667eaa1562 Move to a callback for notifications.
Rather than using a channel for notifictions, use a callback instead.
There are several issues that arise with async notifications via a
channel, so use a callback instead.  The caller can always make the
notifications async by using channels in the provided callback if
needed.
2013-10-02 21:16:38 -05:00
Dave Collins
29dfa22086 Introduce a Stringer on peers.
Rather than having all of the various places that print peer figure out
the direction and form the string, centralize it by implementing the
Stringer interface on the peer.
2013-10-02 20:05:10 -05:00
Dave Collins
f1e2de4f0c Go fmt. 2013-10-02 19:44:07 -05:00
Dave Collins
52701d826d Add directionality back to remove peer log too. 2013-10-02 19:43:38 -05:00
Owain G. Ainsworth
13a8a8e7e3 use directionString() instead of handrollong. 2013-10-03 01:39:31 +01:00
Owain G. Ainsworth
2dcd003722 Print if a peer is inbound or outbound.
This got lost in the peer logging rework. Pointed out by davec@.
2013-10-03 01:21:30 +01:00
Owain G. Ainsworth
eb667fdf83 Remove races on chain.
Chain is not concurrency safe, so we move the chainNotifySink handling
into the main blockmanager goroutine. Due to a possible deadlock if the
buffer is filled this still has to be a single channel that isn't linked
to the other ones. There is a possible starvation issue where the main
msgChan gets selected more often than the  notification sink, but until
chain is concurrency safe this is rather unavoidable.
2013-10-03 00:50:36 +01:00
Owain G. Ainsworth
8974e789f7 Convert the rest of the subsystems to use atomics for shutdown vars. 2013-10-03 00:33:42 +01:00
Dale Rahn
63f8993163 Delete testing operations from obsolete functions. 2013-10-02 18:10:00 -04:00
Owain G. Ainsworth
f333cb4220 Remove a (largely harmless) race on p.conn
Add a Connected() member function that checks atomic variables to see if
the peer is connected.
2013-10-02 23:06:29 +01:00
Owain G. Ainsworth
5c1340be8f make logging about peers rather quieter.
Only log errors for most cases if the peer is persisent (and thus requested).
Only log by default after version exchange, and after losing a peer that had
completed version exchange. Make most other messages debug.
2013-10-02 22:50:24 +01:00
David Hill
0cf8601169 add tests for RFC*, Local, Valid, and Routable. 2013-10-02 17:34:25 -04:00
David Hill
6f9aada482 RFC4193 is fc00::/7, not fc00::/15. Also fix two typos in RFC4843()
and RFC6052
2013-10-02 17:31:44 -04:00
Dale Rahn
8d1db93c82 Remove unused interfaces. 2013-10-02 17:24:26 -04:00
Owain G. Ainsworth
71ea6700a2 Hold amgr lock in {load,save}Peers.
We're traversing internal datastructures here.
2013-10-02 20:37:42 +01:00
Owain G. Ainsworth
70f15f434f Return nil in GetAddress if no addresses present.
Honestly thought we already did this, but turns out no.
2013-10-02 20:19:47 +01:00
Dave Collins
ad12d10503 Remove unused wakeup timer in peerHandler. 2013-10-02 13:52:44 -05:00
Dave Collins
e54fb96d80 Test tx lookup validity in CheckInputTransactions.
This commit modifies CheckInputTransactions to ensure that not only must a
transaction exist in the transaction store, it must also not have any
errors associated with it or be nil.
2013-10-02 10:26:44 -05:00
Owain G. Ainsworth
7d24f31fbd lack of a peers.json isn't an error, don't log in that case. 2013-10-02 15:25:43 +01:00
Owain G. Ainsworth
4455e77dde Don't create additional outbound peers if any --connect are specified. 2013-10-02 15:16:04 +01:00
Owain G. Ainsworth
98109dbadd Fix shutdown hangs.
We would occasionally hang or a while during server shudown, this is due
to an outbound peer waiting on a connection or a sleep. However, we
don't actually require to wait for the peers to finish at all. So just
let them finish.

Secondly, make peer.disconnnect and server.shutdown atomic varaibles so
that checking them from multiple goroutines isn't race, and clean up
their usage.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth
7eb1a5ce4e Disconnect misbehaving peers who send unsolicited blocks. 2013-10-02 14:36:04 +01:00
Owain G. Ainsworth
030c610211 Revert "Comment multi-peer connect while code is under dev."
This reverts commit 7609ff396a.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth
65725189db Keep track of currently requested blocks per peer.
Use this information so that we do not request a block per peer we got
an inv for it, makes multi peer much quieter and rather more bandwidth
efficient.

In order to remove a number of possible races we combine blockhandling
an synchandler and use one channel for all messages. This ensures that
all messages from a single peer will be recieved in order.  It also
removes the need for a lot of locking between the peer removal code and
the block/inv handlers.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth
ca7cb8c875 move the intiial chain cache generation into bm.
Blockmanager is otherwise the only current consumer of chain and it is
messy to do it outside of it.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth
850420055f Bucketizing for addrmanager
Implement the bucketing by source group and group using essentially the
same algorithm as the address maanger in bitcoind.

Fix up the saving of peer.json to do so in a json format that keeps bucket
metadata.

If we fail to load the some of the data we asssume that we have
incomplete information, so we nuke the existing file and reinitialise so
we have a clean slate.
2013-10-02 14:35:59 +01:00
Owain G. Ainsworth
d9214030e0 Don't propagate inv messages to connecting peers.
Only queue messages for peers that have finished connecting to prevent
filling goroutines and causing deadlocks.
2013-10-02 14:35:59 +01:00
Owain G. Ainsworth
989e7a9c48 Make error logging in peer.go unique.
Helps tracking down errors.
2013-10-02 14:35:58 +01:00
John C. Vernaleo
73f08e72a2 Add basic http auth to rpc server. 2013-10-01 17:10:21 -04:00
John C. Vernaleo
dc9618c9ab Add a Error() to the Error struct.
Resolves #6
2013-10-01 12:50:50 -04:00
Josh Rickmar
a5f81fc545 Add PayToPubKeyHashScript and SignatureScript functions.
PayToPubKeyHashScript generates a new pay to pubkey hash script to use
as the pkScript when creating new transactions.  If the passed pubkey
hash is an invalid size, StackErrInvalidOpcode will be returned as an
error.

SignatureScript returns the signature script necessary to validate a
single input of a transaction.

This also adds sanity checking for serializing scripts into byte
slices.  If the length of a serialized opcode does not equal the
expected length, StackErrInvalidOpcode will be returned when unparsing
a []parsedOpcode.

New internal tests were added to verify checks for valid and invalid
parsed opcodes.
2013-10-01 12:50:22 -04:00
Josh Rickmar
e748650cc8 Use uncapitalized error strings 2013-09-30 18:20:46 -04:00
Josh Rickmar
961636c764 Add functions to serialize an ecdsa public key. 2013-09-30 18:18:03 -04:00