Commit Graph

3997 Commits

Author SHA1 Message Date
Calvin Kim
f396b3d3d9 blockchain: better Ancestor with skiplists
On startup, Ancestor call was taking a lot of time when the node was
loading the blockindex onto memory. This change speeds up the Ancestor
function significantly and speeds up the node during startup.

On testnet3 at blockheight ~2,500,000, the startup was around 30seconds
on current main and was 5 seconds with this change. Below is a benchstat
result showing the significant speedup.

goos: darwin
goarch: arm64
pkg: github.com/utreexo/utreexod/blockchain
           │     old.txt      │               new.txt                │
           │      sec/op      │    sec/op     vs base                │
Ancestor-8   120819.301µ ± 5%   7.013µ ± 19%  -99.99% (p=0.000 n=10)

           │  old.txt   │            new.txt             │
           │    B/op    │    B/op     vs base            │
Ancestor-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

           │  old.txt   │            new.txt             │
           │ allocs/op  │ allocs/op   vs base            │
Ancestor-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
2023-11-17 16:55:58 +09:00
Olaoluwa Osuntokun
f7e9fba086
Merge pull request #1918 from kcalvinalvin/2022-11-06-implement-getchaintips
blockchain, btcjson: Implement getchaintips rpc call
2023-11-14 17:16:15 -08:00
Calvin Kim
b4992febff netsync: change isSyncCandidate behavior to include pruned nodes
isSyncCandidate is now changed to return true even if the peer is a
pruned node if and only if our chaintip is within 288 blocks of the
peer.

Rationale:
Pruned nodes that signal NODE_NETWORK_LIMITED MUST serve 288 blocks from
their chaintip.  If our chaintip is within that range, this peer can be
a sync candidate even if they aren't an archival node.
2023-11-07 11:04:34 +09:00
Calvin Kim
a09e7b224a wire: add HasFlag method 2023-11-07 11:04:34 +09:00
Calvin Kim
375f79dcd0 chainhash: Add DoubleHashRaw
DoubleHashRaw provides a simple function for doing double hashes.  Since
it uses the digest instead of making the caller allocate a byte slice, it
can be more memory efficient vs other double hash functions.
2023-11-07 08:27:02 +09:00
ClaytonNorthey92
d15dd71087 added tests for GetBestBlockHashAsync
now testing that GetBestBlockHashAsync sends the getbestblockhash command via websocket connection and that the channel returned can be used to send the response when it is received
2023-11-06 15:56:24 -05:00
ClaytonNorthey92
d988b86027 Added test for client.GetChainTxStatsAsync() in rpcclient. This sets up a test websocket server to run the tests. Also, ensure these are run within a timeout, since they rely on concurrency 2023-11-02 16:16:11 -04:00
ClaytonNorthey92
208800c5f4 Added tests for FutureGetBestBlockHashResult.Receive 2023-11-02 15:17:27 -04:00
0xEclair
0e795fbbfb fix: default forward port 2023-11-01 16:51:20 -04:00
Olaoluwa Osuntokun
e16cdb6bcf
Merge pull request #2051 from Crypt-iQ/txscript_alloc_cb_change
blockchain: export CheckSerializedHeight
2023-10-31 13:02:24 -07:00
eugene
1a615550b7
blockchain: export CheckSerializedHeight, reduce allocs for cb height
parsing

Some callers only want to check the coinbase height rather than be given
the height.
2023-10-30 12:06:10 -04:00
David Cardenas
ad26585576 Update LICENSE 2023-10-20 15:24:16 -04:00
Kevin Heavey
8677a140eb fix typos in sighash.go 2023-10-20 15:23:55 -04:00
Oliver Gugger
a35a687a7f
Merge pull request #2043 from kcalvinalvin/2023-10-12-add-integration-test-for-prune
integration: add test to check prune status
2023-10-16 16:23:15 +00:00
Calvin Kim
520d45e3b1 fixup! integration: add test to check prune status 2023-10-16 16:34:49 +09:00
Calvin Kim
d3d0682dd3 integration: add test to check prune status
Adds a check to make sure that prune status on getblockchaininfo
returns true for pruned nodes.
2023-10-12 15:24:42 +09:00
Calvin Kim
1012f1e4ba wire: add NodeNetworkLimitedBlockThreshold const
NodeNetworkLimitedBlockThreshold is a constant representing how many
blocks from tip a node signaling NODE_NETWORK_LIMITED must serve.
2023-09-25 18:41:36 +09:00
Olaoluwa Osuntokun
80f5a0ffdf
Merge pull request #2028 from yyforyongyu/catch-shutdown
rpcclient: catch shutdown signal when sending RPC requests
2023-09-05 10:09:01 -07:00
yyforyongyu
3a8b851aaf
rpcclient: catch shutdown signal when sending requests 2023-09-04 12:04:32 +08:00
yyforyongyu
d62d537fb5
rpcclient: remove redundant params used in handleSendPostMessage 2023-09-04 12:04:32 +08:00
yyforyongyu
d4f519f5dc
gomod: clean go mod files
Resulted from running `go mod tify`.
2023-09-04 12:04:16 +08:00
Olaoluwa Osuntokun
f12a0b3b56
Merge pull request #2025 from Beerosagos/hash-unmarshal
chainhash: add support to legacy-marshaled hashes
2023-09-01 13:52:39 -07:00
yyforyongyu
87552ddca7
gitignore: ignore vim files 2023-08-30 18:45:58 +08:00
beerosagos
36278166e5
chainhash: add support to legacy-marshaled hashes
Recent commits 1d6e578 and 72ea23e introduced a change in the way Hashes
are serialized and deserialized. This change could cause errors in
downstream applications that persisted hashes serialized using the previous
methods.

This introduces support for legacy-serialized hashes unmarshaling and restores
the compatibility with previous versions.
2023-08-29 14:52:29 +02:00
Olaoluwa Osuntokun
ec401d00a1
Merge pull request #1971 from kcalvinalvin/add-pruning
main, wire, blockchain, indexers, ffldb: Add pruning
2023-08-23 15:59:37 -07:00
Calvin Kim
65c729960a main: cfindex related sanity checks when enabled with pruning
This change is part of the effort to add pruning support to btcd.

cfIndex is a useful index even if the node has been pruned so it's
allowed to be enabled together with pruning.  However, if the user had
disabled cfindex and enabled pruning, it's not possible to generate
them.  In this case, we tell the user that it's impossible unless the
user deletes and start anew.

Additionally, if the user had enabled cfindex and also enabled pruning
from the start, don't let the user turn the cfindex off without dropping
it explicitly.  This is to make sure that the user isn't left at an
inconsistent state where the cfindex isn't able to catch up to the tip
because the blocks have already been pruned.
2023-08-23 00:46:53 +09:00
Calvin Kim
8f8040e596 main: return error if user requests addr or tx index while pruned
This change is part of the effort to add pruning support to btcd.

It's not possible to generate the addr or tx indexes from scratch if the
block storage had been pruned previously as it's missing the block data.
When the user asks to create these indexes, tell them it's not possible
and the only way it's possible is if they delete and start anew.
2023-08-23 00:46:53 +09:00
Calvin Kim
f161a31a93 main: force the user to drop tx and addr indexes for pruning
This change is part of the effort to add pruning support to btcd.

The addr and tx indexes are not useful when the node is pruned as the
actual block data that the indexes point to are gone.  If the user had
previously enabled them, then explicitly require an action from the user
to remove the indexes before letting the user enable pruning.
2023-08-23 00:46:53 +09:00
Calvin Kim
e27fcac9cd blockchain/indexers: add functions to report init status
This change is part of the effort to add pruning support to btcd.

The added *Initialized() functions to each of the indexers allow for
callers to check if each of the indexes have been created.  It's
useful for ux improvements where we force the user to manually drop
indexes that aren't compatible with pruning when the user enables
pruning.
2023-08-23 00:46:53 +09:00
Calvin Kim
47261ef205 main: fetch prune status from db for handleGetBlockChainInfo
This change is part of the effort to add pruning support to btcd.

Now that pruning is allowed in btcd, accurately report the prune status
back to the user.
2023-08-23 00:46:53 +09:00
Calvin Kim
56f3463d9d main: force user to enable pruning if database is already pruned
This change is part of the effort to add pruning support to btcd.

Allowing the user to not pass in the --prune flag after pruning results
in inaccurate reporting of the prune status for getblockchaininfo and
for signaling NODE_NETWORK_LIMITED to peers.  Anything that relies on
cfg.Prune to be accurate is at risk of being incorrect.

To solve the current problems and to prevent potential future problems,
just force the user to keep the prune flag on like bitcoind.  In terms
of UX, there isn't that much of a loss since if the user wants to keep
more blocks than they previously did, they can just increase the size
passed to --prune.
2023-08-23 00:46:53 +09:00
Calvin Kim
aaedc11887 database, database/ffldb: add BeenPruned() method
This change is part of the effort to add pruning support to btcd.

BeenPruned will return true if the database has ever been pruned.  This
allows for accurate prune status to be reported as well as ux
improvements by disallowing the user to accidently remove or enable
indexes.
2023-08-23 00:46:53 +09:00
Calvin Kim
57903c71c9 main: Disable enabling both --prune and --addrindex
You can have a addrindex but with the actual blocks gone, they won't be
much of a help.  Consider allowing these option to be both on in the
future where the addrindex is only indexing the non-pruned blocks.
2023-08-23 00:46:53 +09:00
Calvin Kim
a1736b4267 main: Disable enabling both --prune and --txindex
You can have a txindex but with the actual blocks gone, they won't be
much of a help.  Consider allowing these option to be both on in the
future where the txindex is only indexing the non-pruned blocks.
2023-08-23 00:46:53 +09:00
Calvin Kim
02469e16a6 main: Add prune flag
This change is part of the effort to add pruning support to btcd.

Pruning is now available to the end user via --prune flag.  There are
checks in place so that the user doesn't go below the minimum prune
target of 1536 MiB.  The minimum is set so that we keep at least 288
blocks per the requirement for NODE_NETWORK_LIMITED nodes specified by
BIP0159.  The default value of 0 will disable pruning.
2023-08-23 00:46:26 +09:00
Calvin Kim
0212c334ce wire, main: Add SFNodeNetworkLimited flag
This change is part of the effort to add pruning support to btcd.

Wire now supports the ability to signal NODE_NETWORK_LIMITED which
signals to peers that the node is able to serve the last 288 blocks.

Since archival nodes have all blocks, they can also signal for
NODE_NETWORK_LIMITED.  SFNodeNetworkLimited flag is added to the default
services.
2023-08-22 15:48:55 +09:00
Calvin Kim
57ec43fedc blockchain: Add pruning support
This change is part of the effort to add pruning support to btcd.

A field for pruning is added and the BlockChain struct is now able to be
configured with pruning.  Prune is called on every block connect and
the prune target field is passed to PruneBlocks func.  There's no check
to keep the latest 288 blocks to abide by the NODE_NETWORK_LIMITED rule.
That'll have to be enforced by the caller creating the BlockChain
struct.
2023-08-22 15:48:55 +09:00
Calvin Kim
5c1dd21e79 database/ffldb: Add PruneBlocks to db interface
This change is part of the effort to add pruning support to btcd.

PruneBlocks will prune the earliest block files until it reaches the
given target size.  The returned hashes are the hashes of the blocks
that were pruned.
2023-08-22 15:48:46 +09:00
Olaoluwa Osuntokun
40d7a0a06c
Merge pull request #2022 from wydengyre/bip-340-signing
schnorr: bip-340 compliant signing
2023-08-15 15:30:33 -07:00
Olaoluwa Osuntokun
201b608f31
Merge pull request #1980 from halseth/script-callback
txscript/engine: add execution StepCallback
2023-08-15 15:23:35 -07:00
wydengyre
1c0bc470e8 schnorr: bip-340 compliant signing
fixes https://github.com/btcsuite/btcd/issues/2021
2023-08-15 14:58:15 +01:00
Olaoluwa Osuntokun
0bed86b3f0
Merge pull request #2018 from wydengyre/bip340-schnorr-verification
schnorr: bip-340 compliant verification
2023-08-14 12:09:56 -07:00
wydengyre
ab9338ddbf schnorr: bip-340 compliant verification
fixes https://github.com/btcsuite/btcd/issues/2017
2023-08-12 10:09:27 +01:00
Olaoluwa Osuntokun
0aaa7c5e7b
Merge pull request #1979 from kcalvinalvin/merkle-calc-fast
blockchain, integration, mining, main: Rolling merkle root calculation
2023-08-10 15:05:40 -07:00
Olaoluwa Osuntokun
d776d9c105
Merge pull request #2016 from wydengyre/fix-docs-rfc6979
schnorr: correct rfc reference in docs
2023-08-09 16:46:55 -07:00
Johan T. Halseth
5c5bef0308
txscript/engine_debug_test: add TestDebugEngine
Add a simple test that make sure the stack and alt stack is correctly
set in the callback from script execution.
2023-08-07 14:22:42 +02:00
Johan T. Halseth
6d38900304
txscript/engine: add execution stepCallback
We add a new stepCallback as optional function closure on the Engine
that will be called every time a step has been performed during script
execution.

It is accessed by calling the NewDebugEngine constructor.

This is only meant to be used in debugging.
2023-08-07 14:22:42 +02:00
Calvin Kim
f258d0c8d2 database/ffldb: Change scanBlockFiles behavior
This change is part of the effort to add pruning support to btcd.

scanBlockFiles nows supports scanning files from an arbitrary block
number.  When blocks are pruned, the file number may not start from 0.
To account for this, scanBlockFiles now scans and retreives the start
and the end block file numbers and scans those files.
2023-08-04 17:40:34 +09:00
wydengyre
880d9f9026 schnorr: correct rfc reference in docs
The RFC used for deterministic nonce generation is rfc6979, not rfc6679. This commit fixes documentation in two places accordingly.
2023-08-03 18:49:26 +01:00
Conner Fromknecht
ecfbb7e5d8 blockchain, rpctest, mining, main: replace usage of BuildMerkleTreeStore with CalcMerkleRoot 2023-08-04 00:02:26 +09:00