Commit Graph

3820 Commits

Author SHA1 Message Date
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
Conner Fromknecht
025fa65c93 blockchain: Add CalcMerkleRoot
CalcMerkleRoot uses the rolling merkle root algorithm to calculate the
merkle root commitment inside the Bitcoin block header.  It allocates
significantly less memory than the BuildMerkleTreeStore function that's
currently in use (99.9% in an average block with 2000 txs).
2023-08-04 00:01:10 +09:00
Conner Fromknecht
2d23f94002 blockchain: Add benchmarks for Merkle root calculation 2023-08-04 00:00:51 +09:00
Conner Fromknecht
2bb6824067 blockchain: Add RollingMerkleTree
RollingMerkleTree is a much more memory efficient way of calculating the
merkle root of a tx commitment inside the bitcoin block header.  The
current way of calculating the merkle root allocates 2*N elements. With
the RollingMerkleTree, we are able to reduce the memory allocated to
log2(N).

This results in significant memory savings (99.9% in an average block),
allowing for a faster block verification.
2023-08-03 23:56:53 +09:00
Calvin Kim
3ba9feeeee blockchain, btcutil/bloom: BuildMerkleTreeStore returns chainhash.Hash
BuildMerkleTreeStore used to return a pointer, but it is changed to
return a chainhash.Hash directly.  This allows the compiler to make
optimizations in some cases and avoids a memory allocation.
2023-08-03 15:23:17 +09:00
Oliver Gugger
6f93d9f40d
Merge pull request #1969 from lindlof/rpc-address-align
Add address field (rpc client & server)
2023-08-03 08:17:30 +02:00
Olaoluwa Osuntokun
3a9e7e2376
Merge pull request #2006 from 0xEclair/sig_hash_type
fix: missing sighashtype when finalizing taproot keyspend signature
2023-07-23 16:01:22 +02:00
0xEclair
7f0fb2ad3b psbt: finalizer add proper sighash flag
psbt: fix missing sighash flag when finalizing
psbt: test finalizer add proper sighash flag
2023-07-17 18:35:13 +08:00
Calvin Kim
fc99e96b59 rpcclient, integration: Add test for getchaintips call
rpcclient now support calling the getchaintips rpc call.

getchaintips_test.go adds test for the getchaintips rpc call. The test
includes hard-coded blocks which the test will feed the node via rpc and
it'll check that the returned chain tips from the getchaintips call
are chaintips that we expect to be returned.
2023-07-16 16:03:50 +09:00
Calvin Kim
e2d9e2092b docs: Update json_rpc_api.md for getchaintips rpc 2023-07-16 16:03:50 +09:00
Calvin Kim
892ae679b3 btcjson, main: Implement the getchaintips call
getchaintips call is implemented and the behavior mimics that of Bitcoin
Core. Resolves https://github.com/btcsuite/btcd/issues/1912.
2023-07-16 16:03:48 +09:00
Calvin Kim
46bfb784a6 blockchain: Add ChainTips() method to BlockChain
ChainTips method allows for callers to get all the chain tips the node
is aware of. This is useful for supporting the getchaintips rpc call.
2023-07-16 16:03:45 +09:00
Calvin Kim
b84f084ce7 blockchain: Add InactiveTips() to blockindex
InactiveTips() returns all the tips of the branches of the blockchain
tree that are not in the best chain. This function is useful for
supporting the getchaintips rpc call.
2023-07-16 15:03:33 +09:00
Olaoluwa Osuntokun
7faa9b2662
Merge pull request #2003 from sputn1ck/musig2_fix_early_nonce_gen
musig2: fix early nonce gen option
2023-07-11 15:28:09 -07:00
sputn1ck
883a03da99
musig2: add early nonce gen KnownSigners test
This commit changes the early nonce gen test to use the KnownSigners
Option for one of the contexts.
2023-07-11 14:01:37 +02:00
sputn1ck
8f84bb0e9b
musig2: fix early nonce gen option
Previously the early nonce generation option was not being respected
when creating the context, with the WithKnownSigners option being
used. This commit fixes that.
2023-07-11 14:01:36 +02:00
Olaoluwa Osuntokun
4933e35f61
Merge pull request #1996 from C-Otto/trailing-zeroes
btcutil: format BTC amounts with trailing zeroes
2023-07-10 13:56:01 -07:00
Carsten Otto
725b36bf09 btcutil: format BTC amounts with trailing zeroes
so that sat amounts can be read without counting zeroes

before:
 350sat = 0.0000035 BTC
3500sat = 0.000035 BTC

after:
 350sat = 0.00000350 BTC
3500sat = 0.00003500 BTC

fixes #1995
2023-07-04 18:19:07 +02:00
Olaoluwa Osuntokun
f5eeb10d03
Merge pull request #1931 from Crypt-iQ/export_header_funcs
blockchain: refactor and export header validation checks
2023-06-29 15:01:41 -04:00
eugene
ee6c0e1962
blockchain: export CheckBlockHeaderSanity as a library function 2023-06-29 14:45:32 -04:00
eugene
00d0edd5c4
blockchain: intro HeaderCtx, ChainCtx + refactor CheckBlockHeaderContext
This change will allow an external program to provide its own HeaderCtx
and ChainCtx and be able to perform contextual block header checks.
2023-06-29 14:45:30 -04:00
Oliver Gugger
f9cbff0d81
Merge pull request #1998 from web3-explore/master
multi: remove repetitive the
2023-06-26 16:25:24 +02:00
cui fliter
e160bb6922 multi: remove repetitive the
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-06-26 15:40:51 +08:00
Oliver Gugger
7fd5c1e92c
Merge pull request #1985 from guggero/pow-no-retargeting
blockchain+chaincfg: disable retargeting for regtest
2023-06-22 09:51:09 +02:00
Oliver Gugger
599d3619e8
blockchain+chaincfg: disable retargeting for regtest
This commit emulates the behavior of Bitcoin Core introduced in
https://github.com/bitcoin/bitcoin/pull/6853 that disables retargeting
of the required proof of work for regtest.
2023-06-22 09:25:40 +02:00
Olaoluwa Osuntokun
253b688c68
Merge pull request #1981 from kcalvinalvin/2023-05-16-run-gofmt
multi: Run gofmt on the entire repository
2023-06-21 12:00:35 -05:00
Calvin Kim
ba5407615d multi: Run gofmt on the entire repository
The doc formatting changes introduced in the recent go version is
increasing the diff for all of the new commits.  Formatting it all in
this commit will help the readability of future PRs by reducing the
diff.
2023-06-21 22:31:09 +09:00
Mikael Lindlof
e4c88c3a3e rpc: Add ScriptPubKeyResult address field 2023-06-06 21:57:01 +01:00