Skip to content

Conversation

@2a5A1Ghu1
Copy link
Member

No description provided.

kcalvinalvin and others added 30 commits March 5, 2024 16:33
Sometimes the tests in the addrmanager_internal_test will fail with:
"addrmanager_internal_test.go: expected to find 5 addresses, found 4"

This is because the generated address with randAddr() may not always
generate an address that's routable. If the address is not routable,
that address will not be added to the manager when calling AddAddress().

This bug is fixed by creating a new function routableRandAddr() that
always creates a routable random address.
calculations

Since BlockHeightByHash only returns the heights for blocks that are in
the main chain, when a block that is stale gets pruned, this will cause
an error in the block height lookup and cause an error in block
processing.

Look up the node directly from the index and if the node isn't found,
just skip that node. For utxoCache.lastFlushHash, if that isn't found,
just force a flush.
The assumption in the previous code was incorrect in that we were
assuming that the chainLock is held throughout the entire chain reorg.
This is not the case since the chainLock is let go of during the
callback to the subscribers.

Because of this, we need to ensure that the utxo set is consistent on
each block disconnect. To achieve this, additional flushes are added
during block disconnects.

Also the utxocache is no longer avoided during block connects and when
we're checking for the validity of the block connects and disconnects as
we can just use the cache instead of trying to avoid it.
Allowing the caller to fetch from either the database or the cache
resulted in inconsistencies if the cache were ever to be dirty.
Removing this option eliminates this problem.
…t-addrmgr-bug

addrmgr: fix intermittent addrmanager_internal_test bug
Duplicate entries are currently possible in the following scenario:

1: Add entries to the mapslice.
2: 1st map is full. Move onto the 2nd map.
3: Delete any entry in the first map.
4: Attempt to add an entry in the 2nd map.

When attempting (4), the entry should just be overwritten but a
duplicate gets added.
When attempting to insert an entry to the mapslice, we check all the
underlying maps to ensure that the entry doesn't exist.
Since no code is now depending on accepting new blocks without the
cache, we get rid of the option to do so.
* Updated the `ecdsa.ParseDERSignature` to include the MaxSigLen constant, which defines the maximum length of a DER encoded signature.
* The MaxSigLen constant is set to 72 bytes, as per the explanation in the comment.
* A new test case has been added to test the functionality with a long signature.
* The test case checks if signatures longer than the specified maximum length are properly handled.
* The test ensures that signatures exceeding the maximum length are correctly identified as invalid.
…ight-fetching

blockchain: don't rely on BlockHeightByHash for prune height calculations
update i/o functions to use os / io package functions instead
…ading-on-reorgs

blockchain: fix inconsistent utxocache and database on reorg
…entries-on-mapslice-impossible

blockchain: fix a bug where a duplicate entry is possible in the mapslice
…bscription-callback-errors

blockchain: always relock chainLock for subscription callbacks
This commit adds detailed errors for all possible errors returned from
`sendrawtransaction` or `testmempoolaccept`, enabling upstream callers
to have refined control over the actions to be taken.
This commit changes the `RejectReason` resulted from calling
btcd's `testmempoolaccept` to be un-matched, leaving it to the caller to
decide when and where to match it.
rpcclient: add detailed error types
…ature-validation

Add check for maximum signature length in ecdsa.ParseDERSignature
build: bump version to v0.24.2-beta.rc1
This commit adds a method to MsgTx called TxID. This method returns the
transaction ID (txid) of the subject transaction.
wire: add method TxID to MsgTx
Convert `witnessToHex` into a method `ToHexStrings` on `TxWitness`
defaultMaxFeeRate was set to 1e8 / 10(sat/kb) as a parameter.
But BTC/kvB is the expected value, so the units was wrong.
This commit updates defaultMaxFeeRate to BTC/kvB and sets it to 0.1,
which is the default value of Bitcoin Core.
This commit also updates the comment to reflect the change.

Because maxFeeRate sanity check has been added in
bitcoin core v27.0 or later,
sendrawtransaction cannot be executed without this change.
Added type alias BTC/kvB to explicitly indicate that
it represents the fee in BTC for a transaction size of 1 kB.
Because bitcoind uses its own fee rate type
(BTC/kvB instead of sat/kWU we use in lnd),
define the type in btcjson package,
as it's the only place where we actually use BTC/kvB.
Aharonee and others added 30 commits July 11, 2025 23:30
Upgrade several package versions and fix a test case for transaction serialization.
psbt: upgrade dependencies and fix unit test
In this commit, we ensure hash function parameters are consistent with
filter size to avoid unnecessary operations. A filter with no capacity
doesn't actually require any hash functions, so we can cut that loop
short.
In this commit, we optimize the decoding for the CFCheckpkt message. The
old decode routine would do a fresh alloc for each hash to be read out.

Instead, we'll now allocate enough memory for the entire set of headers
to be decoded, then read them into that contiguous slice, and point to
members of this slice in the wire message itself.

We've also added benchmarks to show the improvement:
```
⛰   cat bench-cmp.txt
goos: darwin
goarch: arm64
pkg: github.com/btcsuite/btcd/wire
cpu: Apple M4 Max
                                     │ bench-old.txt │             bench-new.txt             │
                                     │    sec/op     │    sec/op     vs base                 │
MsgCFCheckptDecode/headers_1000-16     14.354µ ± ∞ ¹   6.919µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_10000-16    146.77µ ± ∞ ¹   70.23µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_100000-16   1473.6µ ± ∞ ¹   564.2µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptEncode/headers_1000-16      7.021µ ± ∞ ¹   7.196µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptEncode/headers_10000-16     88.97µ ± ∞ ¹   90.40µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptEncode/headers_100000-16    861.0µ ± ∞ ¹   875.0µ ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptDecodeEmpty-16              68.28n ± ∞ ¹   66.61n ± ∞ ¹        ~ (p=1.000 n=1) ²
geomean                                 37.98µ         26.98µ        -28.98%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                                     │ bench-old.txt │             bench-new.txt             │
                                     │     B/op      │     B/op       vs base                │
MsgCFCheckptDecode/headers_1000-16     39.36Ki ± ∞ ¹   40.11Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_10000-16    392.6Ki ± ∞ ¹   400.1Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_100000-16   3.817Mi ± ∞ ¹   3.820Mi ± ∞ ¹       ~ (p=1.000 n=1) ²
MsgCFCheckptEncode/headers_1000-16     63.98Ki ± ∞ ¹   63.98Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
MsgCFCheckptEncode/headers_10000-16    1.000Mi ± ∞ ¹   1.000Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
MsgCFCheckptEncode/headers_100000-16   8.000Mi ± ∞ ¹   8.000Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
MsgCFCheckptDecodeEmpty-16               112.0 ± ∞ ¹     112.0 ± ∞ ¹       ~ (p=1.000 n=1) ³
geomean                                166.5Ki         167.4Ki        +0.55%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
³ all samples are equal

                                     │  bench-old.txt   │            bench-new.txt             │
                                     │    allocs/op     │  allocs/op   vs base                 │
MsgCFCheckptDecode/headers_1000-16       1003.000 ± ∞ ¹   4.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_10000-16     10003.000 ± ∞ ¹   4.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptDecode/headers_100000-16   100003.000 ± ∞ ¹   4.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
MsgCFCheckptEncode/headers_1000-16          11.00 ± ∞ ¹   11.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
MsgCFCheckptEncode/headers_10000-16         15.00 ± ∞ ¹   15.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
MsgCFCheckptEncode/headers_100000-16        18.00 ± ∞ ¹   18.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
MsgCFCheckptDecodeEmpty-16                  2.000 ± ∞ ¹   2.000 ± ∞ ¹        ~ (p=1.000 n=1) ³
geomean                                     179.3         6.268        -96.50%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
³ all samples are equal
```

Old bench:
```
goos: darwin
goarch: arm64
pkg: github.com/btcsuite/btcd/wire
cpu: Apple M4 Max
BenchmarkMsgCFCheckptDecode/headers_1000-16         	   74678	     14354 ns/op	   40304 B/op	    1003 allocs/op
BenchmarkMsgCFCheckptDecode/headers_10000-16        	    8234	    146770 ns/op	  402033 B/op	   10003 allocs/op
BenchmarkMsgCFCheckptDecode/headers_100000-16       	     822	   1473622 ns/op	 4002931 B/op	  100003 allocs/op
BenchmarkMsgCFCheckptEncode/headers_1000-16         	  173762	      7021 ns/op	   65520 B/op	      11 allocs/op
BenchmarkMsgCFCheckptEncode/headers_10000-16        	   13459	     88968 ns/op	 1048564 B/op	      15 allocs/op
BenchmarkMsgCFCheckptEncode/headers_100000-16       	    1399	    860985 ns/op	 8388592 B/op	      18 allocs/op
BenchmarkMsgCFCheckptDecodeEmpty-16                 	17459148	        68.28 ns/op	     112 B/op	       2 allocs/op
PASS
ok  	github.com/btcsuite/btcd/wire	10.135s

```

New bench:
```
goos: darwin
goarch: arm64
pkg: github.com/btcsuite/btcd/wire
cpu: Apple M4 Max
BenchmarkMsgCFCheckptDecode/headers_1000-16         	  166368	      6919 ns/op	   41072 B/op	       4 allocs/op
BenchmarkMsgCFCheckptDecode/headers_10000-16        	   17079	     70227 ns/op	  409712 B/op	       4 allocs/op
BenchmarkMsgCFCheckptDecode/headers_100000-16       	    2062	    564175 ns/op	 4006003 B/op	       4 allocs/op
BenchmarkMsgCFCheckptEncode/headers_1000-16         	  173940	      7196 ns/op	   65520 B/op	      11 allocs/op
BenchmarkMsgCFCheckptEncode/headers_10000-16        	   13054	     90401 ns/op	 1048564 B/op	      15 allocs/op
BenchmarkMsgCFCheckptEncode/headers_100000-16       	    1408	    875012 ns/op	 8388592 B/op	      18 allocs/op
BenchmarkMsgCFCheckptDecodeEmpty-16                 	17256627	        66.61 ns/op	     112 B/op	       2 allocs/op
PASS
ok  	github.com/btcsuite/btcd/wire	10.522s

```

As seen from the benchmarks, allocs have decreased by 96%, and the decode
speed by nearly 30%.
wire: optimize parsing for CFCheckpkt message, reduce allocs by 96%
Align hash function count with bloom filter capacity
btcjson: add stubs for SubmitPackage
Fixes #2404.
If different versions of bitcoind return different error strings, we
need a way to match those as well.
rpcclient: add bitcoind version dependent error matching
Co-authored-by: Oliver Gugger <gugger@gmail.com>
Makefile+workflows: fallback to `GOPATH/bin` on non-existent `GOBIN`
build: bump version to v0.25.0-beta.rc1
This commit adds a new function to musig2.Session, which allows the caller
to add an external aggregated nonce to the session.
musig2: add WithExternalCombinedNonce option to Sign
Ensure that the dial phase of rpcclient's HTTP posts respects the http.Client's Timeout. It was instead falling back to the OS settings.
…dialcontext

rpcclient: ensure http dial respects timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.