Commit Graph

4068 Commits

Author SHA1 Message Date
yyforyongyu
889cdb4f66
multi: add more bitcoind versions to the BackendVersion
This commit adds bitcoind version 22.0 and 25.0 to our `BackendVersion`
set to handle the `testmempoolaccept` RPC calls. A unit test is added to
make sure the parser works as expected.
2024-01-15 17:22:40 +08:00
yyforyongyu
ca4261f028
btcjson: add TestMempoolAcceptCmd 2024-01-15 17:22:40 +08:00
yyforyongyu
2ad8026a38
mempool: add new method checkMempoolAcceptance
This commit breaks the `maybeAcceptTransaction` into two parts - the
first is reading the mempool to validate the transaction, and the
relevant logic has been moved into the new method
`checkMempoolAcceptance`. The second part is writing to the mempool, and
is kept in the method `maybeAcceptTransaction`.
2024-01-15 17:22:40 +08:00
yyforyongyu
44abf0a53c
gitignore: ignore vim files 2024-01-15 17:22:40 +08:00
Oliver Gugger
91cdf0d7fc
Merge pull request #2098 from vuittont60/master
Fix some typos
2024-01-09 12:52:07 +01:00
vuittont60
6ed54f3bf2
btcec: fix typo 2024-01-09 17:12:36 +08:00
vuittont60
7df46516b7
btcutil: fix typo 2024-01-09 17:12:23 +08:00
vuittont60
048a7ef40b
database: fix typo 2024-01-09 17:12:09 +08:00
vuittont60
7fdd92c3a0
docs: fix typo 2024-01-09 17:11:59 +08:00
Thabokani
a4df044cfd
Fix some typos (#2085)
* Dockerfile: fix typo

* blockchain: fix typos

* sample-btcd.conf: fix typos

* server: fix typos

* txscript: fix typos
2024-01-03 16:36:49 -05:00
Calvin Kim
e307ad122f blockchain: set the lastflushtime when setting the lastflushhash
On startup when the headers-first mode is off, when receiving the first
block, the periodic flush will trigger.  The lastflushtime wasn't set
which resulted in the flush being triggered on the first block on
restart.
2024-01-03 14:24:36 +09:00
Olaoluwa Osuntokun
b1b9420208
Merge pull request #2082 from btcsuite/btcd-24
build: create btcd v0.24 release branch
2023-12-30 16:52:37 -08:00
Olaoluwa Osuntokun
4ec8f016b9
rpcclient: fix race condition in doDisconnect
In this commit, we fix the following race condition:
```
==================
WARNING: DATA RACE
Write at 0x00c000216018 by goroutine 31:
  github.com/btcsuite/btcd/rpcclient.(*Client).wsReconnectHandler()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:736 +0x2aa
  github.com/btcsuite/btcd/rpcclient.New·dwrap·13()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0x39

Previous read at 0x00c000216018 by goroutine 29:
  github.com/btcsuite/btcd/rpcclient.(*Client).doDisconnect()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1079 +0x247
  github.com/btcsuite/btcd/rpcclient.(*Client).Disconnect()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1111 +0x47
  github.com/btcsuite/btcd/rpcclient.(*Client).wsInHandler()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:491 +0x1eb
  github.com/btcsuite/btcd/rpcclient.(*Client).start·dwrap·11()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x39

Goroutine 31 (running) created at:
  github.com/btcsuite/btcd/rpcclient.New()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0xd77
  github.com/btcsuite/btcd/rpcclient.makeClient()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9
  github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47

Goroutine 29 (finished) created at:
  github.com/btcsuite/btcd/rpcclient.(*Client).start()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x2e4
  github.com/btcsuite/btcd/rpcclient.New()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1493 +0xc51
  github.com/btcsuite/btcd/rpcclient.makeClient()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9
  github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47
```

This arises as in `wsReconnectHandler`, the mutex isn't held while the
`conn` pointer is modified.
2023-12-30 16:43:07 -08:00
Olaoluwa Osuntokun
8d2ab63e36
build: bump version to btcd v0.24 2023-12-30 16:25:08 -08:00
Olaoluwa Osuntokun
3c2478514f
chaincfg: update mainnet block hashes 2023-12-30 16:25:02 -08:00
Olaoluwa Osuntokun
bf23715f90
btcd: add SECURITY.md 2023-12-30 16:24:59 -08:00
Olaoluwa Osuntokun
d64de4a905
build: update to btcutil v1.1.5 2023-12-30 16:24:53 -08:00
Olaoluwa Osuntokun
16684f6cbc
Merge pull request #2073 from Roasbeef/wire-opts
wire: only borrow/return binaryFreeList buffers at the message level
2023-12-28 18:52:53 -08:00
Olaoluwa Osuntokun
790c570dda
Merge pull request #2081 from Roasbeef/dont-serialize-tx-for-txhash
btcutil: reuse serialized tx during TxHash
2023-12-28 18:45:45 -08:00
Olaoluwa Osuntokun
b0e9636689
wire: consistently use defer for returning scratch buffers 2023-12-28 18:37:43 -08:00
Olaoluwa Osuntokun
e102a81268
btcutil: add benchmarks for Hash + WitnessHash 2023-12-28 18:07:03 -08:00
Olaoluwa Osuntokun
56de9ca878
btcutil: align new serialization caching logic w/ codebase style 2023-12-28 17:47:11 -08:00
Oliver Gugger
8766bfd86e
Merge pull request #2071 from guggero/integration-harness-fixes
rpctest: integration test harness fixes
2023-12-22 11:46:20 +01:00
Oliver Gugger
7644d14078
blockchain: fix compilation issues with 32bit systems 2023-12-22 10:14:43 +01:00
Oliver Gugger
dd5f3bd513
rpctest: make test TCP ports unique per process
This commit adds a new NextAvailablePortForProcess function that takes a
process ID and then assures unique (non-occupied) port numbers are
returned per process.
This uses a temporary file that contains the latest used port and a
secondary temporary lock file to assure only a single goroutine can
request a new port at a time.

The GenerateProcessUniqueListenerAddresses is intened to be used as a
package-level override for the ListenAddressGenerator variable. We don't
use it by default to make sure we don't break any existing assumptions.
2023-12-21 09:42:09 +01:00
Oliver Gugger
d33ac28be1
rpctest: add more context to errors 2023-12-21 08:20:28 +01:00
Oliver Gugger
323cf1e0b1
rpctest: fix test node directory 2023-12-21 08:20:28 +01:00
Oliver Gugger
6e7680ad15
rpctest: fix formatting 2023-12-21 08:05:57 +01:00
Calvin Kim
83605e476c btcutil: reuse serialized tx during TxHash
btcutil.Block caches the serialized raw bytes of the block during ibd.
This serialized block bytes includes the serialized tx. The current tx
hash generation will re-serialized the de-serialized tx to create the
raw bytes and it'll only then hash that.

This commit changes the code so that the re-serialization never happens,
saving tons of cpu and memory overhead.
2023-12-21 13:43:11 +09:00
alex
4af0ca8c30 doc: correct comments 2023-12-20 11:41:55 -05:00
Olaoluwa Osuntokun
0d666ff7ce
Merge pull request #2075 from Roasbeef/btcutil-psbt-update-dec-2023
multi: update main package and btcutil to chainhash/v1.1.0, use optimized dsha256
2023-12-19 15:17:57 -08:00
Olaoluwa Osuntokun
19008edd0f
txscript: use a single shared scratch buffer in segwit sighash calc
We used to use a lot of small buffers for serialization, but now we'll
use one buffer large enough, and slice into it when needed.

``
name                  old time/op    new time/op    delta
CalcWitnessSigHash-8    31.5µs ± 0%    29.2µs ± 0%   -7.05%  (p=0.000 n=10+10)

name                  old alloc/op   new alloc/op   delta
CalcWitnessSigHash-8    19.9kB ± 0%    18.5kB ± 0%   -7.14%  (p=0.000 n=10+10)

name                  old allocs/op  new allocs/op  delta
CalcWitnessSigHash-8       801 ± 0%       445 ± 0%  -44.44%  (p=0.000 n=10+10)
```
2023-12-19 15:02:05 -08:00
Olaoluwa Osuntokun
046a70121a
txscript: use DoubleHashRaw for segwit sighash single calc
We can write direly into the hash writer vs serializing into a buffer,
then writing that into the hash writer.
2023-12-19 15:02:00 -08:00
Olaoluwa Osuntokun
adfb641a36
txscript: use DoubleHashRaw to write directly crypto.Hash for segwit sighash
In this commit, we optimize the sighash calc further by writing directly
into the buffer used for serialization by the sha256.New() instance
rather than to an intermediate buffer, which is then write to the hash
buffer.
2023-12-19 15:01:58 -08:00
Olaoluwa Osuntokun
c3c3545f9b
multi: update main package to chainhash/v1.1.0, use optimized dsha256
In this commit, we update the top-level btcd package to use the latest
version of btcutil and also the chainhash package. With this version
bump, we can now use the new optimized dsha256 routine where applicable.

With this commit, I've covered most of the areas we'll hash an entire
transaction/block/header, but we may want to optimize some other areas
further, in particular, the witness sighash calc.
2023-12-19 15:01:55 -08:00
Olaoluwa Osuntokun
4126760706
btcutil/psbt: update to btcutil btcutil/v1.1.4 2023-12-19 15:01:52 -08:00
Afanti
b2f340d9d9
fix: enhance code comments (#2074)
* fix: enhance code comments
2023-12-19 10:40:37 -05:00
Olaoluwa Osuntokun
4c2ce6daed
Merge pull request #2072 from Roasbeef/chainhash-v-1-1-0-btcutil
btcutil: update to chaincfg/chainhash/v1.1.0
2023-12-18 16:36:33 -08:00
Olaoluwa Osuntokun
941e42c781
Merge pull request #1955 from kcalvinalvin/utxocache-original
blockchain, cmd, netsync, main: Add utxocache
2023-12-18 16:35:17 -08:00
Calvin Kim
87a81f14fc blockchain: address nit comments 2023-12-16 16:53:17 +09:00
Calvin Kim
26b2e9d9de blockchain: add test for InitConsistentState 2023-12-16 16:53:17 +09:00
Calvin Kim
84bdd0180e ffldb: change export_test.go to export.go
The testing function in export_test.go is changed to just export.go so
that callers outside the ffldb package will be able to call the
function.

The main use for this is so that the prune code can be triggered from
the blockchain package.  This allows testing code to have less than
1.5GB worth of blocks to trigger the prune.
2023-12-16 16:53:17 +09:00
Calvin Kim
ebc93a34ce blockchain: flush the utxo cache on prune if needed
If the prune will delete block past the last flush hash of the
utxocache, the cache will need to be flushed first to avoid a case
where the utxocache is irrecoverable.  The newly added code adds this
flush logic to connectBlock.
2023-12-16 16:53:17 +09:00
Calvin Kim
dd37dfa80b blockchain: add flushNeededAfterPrune
flushNeededAfterPrune returns true if the utxocache needs to be flushed
after the pruning of the given slice of block hashes.  For the utxo
cache to be recoverable while pruning is enabled, we need to make sure
that there exists blocks since the last utxo cache flush.  If there are
blocks that are deleted after the last utxo cache flush, the utxo set is
irrecoverable.  The added method provides a way to tell if a flush is
needed.
2023-12-16 16:53:17 +09:00
Calvin Kim
d387d162f3 database/ffldb: make PruneBlocks atomic
PruneBlocks used to delete files immediately before the database
transaction finished.  By making the prune atomic, we can guarantee that
the database flush will happen before the utxo cache is flushed,
ensuring that the utxo cache is never in an irrecoverable state.
2023-12-16 16:53:17 +09:00
Calvin Kim
16cd44f0e6 blockchain, netsync, main, cmd/addblock: Use utxocache
This change is part of the effort to add utxocache support to btcd.

utxo cache is now used by the BlockChain struct.  By default it's used
and the minimum cache is set to 250MiB.  The change made helps speed up
block/tx validation as the cache allows for much faster lookup of utxos.
The initial block download in particular is improved as the db i/o
bottleneck is remedied by the cache.
2023-12-16 16:53:17 +09:00
Calvin Kim
3c11e48dd2 blockchain: Add utxocache
The implemented utxocache implements connectTransactions just like
utxoviewpoint and can be used as a drop in replacement for
connectTransactions.

One thing to note is that unlike the utxoViewpoint, the utxocache
immediately deletes the spent entry from the cache.  This means that the
utxocache is unfit for functions like checkConnectBlock where you expect
the entry to still exist but be marked as spent.

disconnectTransactions is purposely not implemented as using the cache
during reorganizations may leave the utxo state inconsistent if there is
an unexpected shutdown.  The utxoViewpoint will still have to be used
for reorganizations.
2023-12-16 16:53:04 +09:00
Calvin Kim
053ef330f2 blockchain: Refactor fetchInputUtxos
This change is part of the effort to add utxocache support to btcd.

fetchInputUtxos had mainly 2 functions:
1: Figure out which outpoints to fetch
2: Call fetchUtxosMain to fetch those outpoints

Functionality for (1) is refactored out to fetchInputsToFetch.  This is
done to allow fetchInputUtxos to use the cache to fetch the outpoints
as well in a later commit.
2023-12-16 16:36:45 +09:00
Calvin Kim
bcd8f547fe blockchain: Require utxoBucket in dbFetchUtxoEntry
This change is part of the effort to add utxocache support to btcd.

Require the caller to pass in the utxoBucket as the caller may be
fetching many utxos in one loop.  Having the caller pass it in removes
the need for dbFetchUtxoEntry to grab the bucket on every single fetch.
2023-12-16 16:36:45 +09:00
Calvin Kim
953d62afa7 blockchain: Return early on nil utxo view in dbPutUtxoView
This change is part of the effort to add utxocache support to btcd.

connectBlock may have an empty utxoviewpoint as the block verification
process may be using the utxo cache directly.  In that case, a nil utxo
viewpoint will be passed in.  Just return early on a nil utxoviewpoint.
2023-12-16 16:36:45 +09:00