Commit graph

93 commits

Author SHA1 Message Date
Dave Collins
0280fa0264 Convert block heights to int32.
This commit converts all block height references to int32 instead of
int64.  The current target block production rate is 10 mins per block
which means it will take roughly 40,800 years to reach the maximum
height an int32 affords.  Even if the target rate were lowered to one
block per minute, it would still take roughly another 4,080 years to
reach the maximum.

In the mean time, there is no reason to use a larger type which results
in higher memory and disk space usage.  However, for now, in order to
avoid having to reserialize a bunch of database information, the heights
are still serialized to the database as 8-byte uint64s.

This is being mainly being done in preparation for further upcoming
infrastructure changes which will use the smaller and more efficient
4-byte serialization in the database as well.
2015-08-11 11:13:17 -05:00
David Hill
3331d6098b txscript: New function IsUnspendable
IsUnspendable takes a public key script and returns whether it is
spendable.

Additionally, hook this into the mempool isDust function, since
unspendable outputs can't be spent.

This mimics Bitcoin Core commit 0aad1f13b2430165062bf9436036c1222a8724da
2015-08-03 10:10:23 -04:00
David Hill
9ffd96bf51 Revert "Move IsFinalizedTransaction to txscript."
This reverts commit 17da2ba7fa.

This was done prematurely.  This will be revisited when a code
restructure is more urgent.
2015-06-29 11:12:35 -04:00
David Hill
17da2ba7fa Move IsFinalizedTransaction to txscript.
This change moves IsFinalizedTransaction to txscript and also changes
the first argument to take a wire.MsgTx instead of btcutil.Tx.  This
is needed for an upcoming diff in which txscript will require
IsFinalizedTransaction and we do not want to import the btcd/blockchain.
2015-06-28 09:43:14 -04:00
David Hill
5f8dbab47a Add new option -maxorphantx
The option -maxorphantx allows the user to specify the number of
orphan transactions to keep in memory.

Also, lower the default max orphan count from 10000 to 1000.
2015-05-12 17:22:13 -04:00
Dave Collins
6e402deb35 Relicense to the btcsuite developers.
This commit relicenses all code in this repository to the btcsuite
developers.
2015-05-01 12:00:56 -05:00
Alex Akselrod
ead39153af Fix #303 and #346 and change addrindex sort order
Fix #303 by changing the addrindex key prefix to 3 characters so that
it's easy to check length when dropping the index. To drop the old
index, check to make sure we aren't dropping any entries that end in
"sx" or "tx" as those aren't part of the addrindex. Update test to
deal with the new prefix length.

Fix #346 by changing the pointers in the mempool's addrindex map to
wire.ShaHash 32-byte values. This lets them be deleted even if the
transaction data changes places in memory upon expanding the maps.

Change the way addrindex uint32s are stored to big-endian in order to
sort the transactions on disk in chronological/dependency order.

Change the "searchrawtransactions" RPC call to return transactions
from the database before the memory pool so that they're returned in
order. This commit DOES NOT do topological sorting of the memory pool
transactions to ensure they're returned in dependency order. This may
be a good idea for a future enhancement.

Add addrindex versioning to automatically drop the old/incompatible
version of the index and rebuild with the new sort method and key
prefix.
2015-03-23 13:05:54 -04:00
David Hill
54d7951084 Process orphans on block acceptance.
For every transaction in a newly accepted block, process the orphan
pool moving now no longer orphan transactions to the mempool.

Previously, no longer orphan transactions would remain in the orphan
pool.
2015-03-10 14:15:55 -04:00
David Hill
ad35a5dc48 Have calcPriority determine the tx size. 2015-03-10 00:19:23 -04:00
Dave Collins
def0ef6af6 Use network adjusted time for finalized tx check.
This commit modifies finalized transaction check used by the memory pool
and block templates to use the network adjusted time instead of the
unadjusted local time.  This helps keep the transactions accepted to the
memory pool, and hence allowed to relay, more consistent across nodes.
2015-03-09 22:03:58 -05:00
David Hill
d9cba7ca6a txscript: export StandardVerifyFlags
By exporting StandardVerifyFlags, clients can ensure they create
transactions that btcd will accept into its mempool.

This flag doesn't belong in txscript.  It belongs in a
policy package.  However, this is currently the least worse place.
2015-02-26 15:21:12 -05:00
David Hill
ff747f8eae Use ScriptVerifyMinimalData
Additionally, drop HasCanoncialPushes as ScriptVerifyMinimalData
offers more complete checks.
2015-02-26 13:13:16 -05:00
Dave Collins
4c53599b67 mempool: Loosen restrictions for resurrected txns.
This modifies the recently added code which rejects free/low-fee
transactions with insufficient priority to ignore resurrected transactions
from disconnected blocks.  It also exempts resurrected transactions from
the free/low-fee rate limiting.
2015-02-25 22:07:12 -06:00
David Hill
833bb04775 Reject free/low-fee transactions with insufficient priority.
By default, have the mempool reject free and low-fee transactions that
have insufficient priority to be mined in the next block.

Addtionally, add a new configuration option, -norelaypriority, to
disable the check.
2015-02-25 11:27:41 -05:00
Josh Rickmar
951f244f87 Move calcPriority to the file where it's used. 2015-02-24 10:15:15 -05: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
Dave Collins
03433dad6a Update btcwire path import paths to new location. 2015-02-05 15:16:39 -06:00
Dave Collins
624bbb3216 Update btcchain import paths to new location. 2015-01-30 16:25:42 -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
309a9ea31d Update database import paths to new location. 2015-01-27 15:38:23 -06:00
Dave Collins
a57505b7f0 Update btcscript import paths to new location. 2015-01-16 19:37:00 -06:00
Dave Collins
528622b259 Update btcchain import paths to new location. 2015-01-16 18:47:50 -06:00
Dave Collins
0b7a9074ef Update btcdb import paths to new location. 2015-01-16 18:30:32 -06:00
Dave Collins
54ccb83025 Update btcwire import paths to new location. 2015-01-16 15:13:21 -06:00
Dave Collins
58db4a8b7e Update btcutil import paths to new location. 2015-01-15 10:30:38 -06:00
Dave Collins
4589d60212 Don't treat nulldata tx outs as nonstandard dust.
This commit modifies the dust check to exclude transactions with nulldata
outputs so they may be considered standard.
2015-01-11 17:09:11 -06:00
Josh Rickmar
c257da934e Improve double spend error strings.
The mempool's MaybeAcceptTransaction methods have also been modified
to return a slice of transaction hashes referenced by the transaction
inputs which are unknown (totally spent or never seen).  While this is
currently used to include the first hash in a ProcessTransaction error
message if inserting orphans is not allowed, it may also be used in
the future to request orphan transactions from peers.
2015-01-08 23:54:11 -05:00
Dave Collins
1973aa5fd5 A few nitpicks with recent getrawmempool updates.
This commit addresses a few nitpicks in the recent getrawmppol update
which populates the starting and current priority fields.

In particular:

- Move the new calcInputValueAge function before the function which
  invokes it so it is consistent with the rest of the mempool code
- Double space after periods for consistency
- Correct the comments for calcInputValueAge to indiciate that inputs
  which are in the the memory pool count as zero toward the value age
  rather than the incorrect claim that that the overal input value age is
  zero when one of them does
- Rename endingPriority to currentPriority to match the RPC field and its
  actual function
- Make the comment about using zero when input transactions can't be found
  for some reason more accurate since there can be (and frequently is)
  more than one input transaction
2014-11-17 00:31:14 -06:00
Olaoluwa Osuntokun
a49b0d05b3 Add the starting+current priority to getrawmempool. 2014-11-16 23:58:33 -06:00
Jonathan Gillham
1bbd1e9cba Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint after btcwire API change. 2014-10-01 16:34:30 +01:00
David Hill
4ad8622af9 Remove transactions from orphan pool.
This change removes transactions from a newly connected block
from the orphan pool if they exist.  Additionally, any orphan
transactions that are no longer orphan transactions are moved
to the mempool and inv'd to the currently connected peers.
2014-09-19 22:58:06 -05:00
John C. Vernaleo
2480cb3a87 Match error names to btcdb updates. 2014-09-16 15:09:32 -04:00
David Hill
41fbb87c86 Reject transactions with too many signature operations.
This matches recent changes in bitcoin core.
2014-09-10 19:28:03 -05:00
Dave Collins
3dc3fefc9b Improve readability of recent rate limiter changes.
This commit builds on the recent limiter updates.  The recent changes
introduced a new function named calcTxFee which could easily be confused
with calculating the fees of the transaction rather than its intended
purpose of calculating the minimum transaciton relay fee.

Rather than taking that approach, this commit instead renames the existing
function to calcMinRequiredTxRelayFee and uses a consistent variable name
for the serialized size of a transaction.  It then moves the check for
whether or not the check should be applied based on the serialized size of
the transcation and block priority to the call site.

This approach also has the benefit of avoiding two calls to the
calculation function since it's a local at the call site.

ok @jrick, @dajohi
2014-08-19 11:39:30 -05:00
David Hill
61a53adccd Fix the mempool rate limiter.
Before, btcd was rate limiting all transactions that had a minimum
fee of zero.  Now, btcd only rate limits transactions that contain
a fee less than the calculated fee based on size.

Closes #163
2014-08-19 10:22:22 -04:00
Dave Collins
000691dc9e Implement BIP0061 reject handling (pver 70002).
This commit implements reject handling as defined by BIP0061 and bumps the
maximum supported protocol version to 70002 accordingly.

As a part of supporting this a new error type named RuleError has been
introduced which encapsulates and underlying error which could be one of
the existing TxRuleError or btcchain.RuleError types.

This allows a single high level type assertion to be used to determine if
the block or transaction was rejected due to a rule error or due to an
unexpected error.  Meanwhile, an appropriate reject error can be created
from the error by pulling the underlying error out and using it.

Also, a check for minimum protocol version of 209 has been added.

Closes #133.
2014-07-14 12:25:11 -05:00
Dave Collins
fc5656894d Implement getblocktemplate long poll support.
This commit implements the long polling portion of the getblocktemplate
RPC as defined by BIP0022.  Per the specification, each block template is
returned with a longpollid which can be used in a subsequent
getblocktemplate request to keep the connection open until the server
determines the block template associated with the longpollid should be
replaced with a new one.

This is work towards #124.
2014-07-10 09:42:58 -05:00
Tomás Senart
84fa553b65 Split imports into logical groups 2014-07-02 15:56:41 +02:00
David Hill
e9211bd01a Fix log message. 2014-06-12 14:04:05 -04:00
David Hill
7f825fd9bc Remove unneeded usage of fmt.Sprintf 2014-06-04 20:24:48 -04:00
Dave Collins
468f8366cf Make multisig txns with non-null dummy nonstandard.
This commit helps prevent transaction malleability by enforcing that the
extra dummy value on multisig transaction script contains no data for a
transaction .  This syncs with a recent change in Bitcoin Core to remain
compatible.

As part of this change a new constant has been introduced which is used to
specify the script flags which are used for standard transactions.  This
constant is then used in both the memory pool and the mining code to
ensure they remain in sync with one another.

Closes #131.

ok @jrick, @dajohi
2014-05-31 11:56:58 -05:00
Dave Collins
6d8b873923 Raise maxStandardSigScriptSize to 1650.
This commit raises the maximum allowed size for a standard signature
script to cover a 15-of-15 multi-signature pay-to-script-hash with
compressed pubkeys.

This mirrors a recent change to remain compatible with Bitcoin Core.

ok @owinga who also helped verify and correct the script math.

Closes #128.
2014-05-23 12:23:36 -05:00
Josh Rickmar
bcc78565fd Initial pass at updating to btcnet.
This change modifies the params struct to embed a *btcnet.Params,
removing the old parameter fields that are handled by the btcnet
package.

Hardcoded network checks have also been removed in favor of modifying
behavior based on the current active net's parameters.

Not all library packages, notable btcutil and btcchain, have been
updated to use btcnet yet, but with this change, each package can be
updated one at a time since the active net's btcnet.Params are
available at each callsite.

ok @davecgh
2014-05-23 01:02:14 -05:00
Dave Collins
a4a79387cc Add support for getmininginfo RPC.
Closes #126.
2014-05-04 14:34:25 -05:00
Dave Collins
92ca0e92c0 Implement getwork RPC.
This commit adds full support for the getwork RPC which can be used to
support external mining through applications such as cgminer.

Closes #125.
2014-05-01 10:52:28 -05:00
David Hill
8a322e4792 Bypass rate limiter for sendrawtransaction.
ok @davecgh
2014-04-23 07:45:56 -04:00
Owain G. Ainsworth
3a03a03a92 Kill duff newline. 2014-03-28 00:01:46 +00:00
mydesktop
ab002c90cc Implement a rebroadcast handler.
This commit implements a rebroadcast handler which deals with
rebroadcasting inventory at a random time interval between 0 and 30
minutes.  It then uses the new rebroadcast logic to ensure transactions
which were submitted via the sendrawtransaction RPC are rebroadcast until
they make it into a block.

Closes #99.
2014-03-27 14:09:33 -05:00
Dave Collins
e98db34ef2 Add infrastructure for creating a block template.
This commit adds a new function named NewBlockTemplate along with
supporting infrastructure which is part of the core functionality needed
to support mining.

In particular the function creates a new block template which contains a
fully populated block with a zero nonce that is ready to be solved as well
as additional information regarding the fees and number of signature
operations for each transaction included in the block.  The specific
transaction selection logic mirrors the reference implementation.

Various cleanup, optimizations, and comment suggestions provided by
@owainga.  Also contains some naming suggestions and comment fixes from
@flammit.
2014-03-22 11:47:38 -05:00