Commit graph

74 commits

Author SHA1 Message Date
Oliver Gugger
dccea8feba multi: use new v2 modules everywhere 2026-05-14 18:05:33 -07:00
Calvin Kim
e009124748 treap, ffldb: change Put() to take in multiple key-value pairs
Previously, the Put() function took in a single key-value pair,
resulting in memory allocation overhead as the intermediary treapNodes
got allocated and immediately garbage collected, resulting in
performance loss due to the garbage collection overhead.

We're able to recycle the intermediary treapNodes allocated by taking in
multiple key-value pairs.  This results in better performance of the
node especially during UTXO cache flushes.
2025-11-14 14:58:35 +01:00
Calvin Kim
0e95ae381a treap: add recycle() method on treapNode
The recycle method resets and puts the treapNode into the treapNodePool
to be recycled at a future date.
2025-10-30 17:21:22 +09:00
Calvin Kim
65d39687bf treap: return newly created treapNodes in put()
The newly created treapNodes in put() are now returned so that the
caller has access to them.  This is done so that the caller can put back
some of the treapNodes to sync.Pool.

For multiple put operations, an immutable treap will allocate many
treapNodes that will immediately be garbage collected.  Let's say
there's 3 key-value pairs that are going to be inserted:

key 1: 50
key 2: 10
key 3: 4

Then the insertion is like so:

1: allocate 50.

        50

2: clone 50, allocate 10.

        50
       /  \
      10

3: clone 50, clone 10, allocate 4

        50
       /  \
      10
     /
    4

In this example, only the nodes allocated during insertion of (3) is
going to be used.  The rest is going to be garbage collected and they
can be safely be put in the sync.Pool if there's a guarantee that the
previous copies are not being accessed.  This is true if the put
operations are going to be called in batches.

By returning the pointers of these allocated treapNodes, we allow the
caller to make such optimizations.
2025-10-30 16:57:57 +09:00
Calvin Kim
e3d237d3ca treap: add treapNodePool and fetch from it for cloneTreapNode and
newTreapNode

The treapNodePool will allow for less memory allocations during
immutable treap operations.  We first change the cloneTreapNode and
newTreapNode to allocate a treapNode from the sync.Pool.

The allocated treapNodes will be put back into the sync.Pool in later
commits.
2025-09-20 17:54:14 +09:00
Calvin Kim
26ef499ae4 treap: refactor the Put() code into exported and unexported versions
We do this to later add batch put logic into the exported Put()
function.
2025-09-20 17:50:54 +09:00
Olaoluwa Osuntokun
1eb974aab6
Merge pull request #2358 from kcalvinalvin/2025-02-17-exit-when-running-out-of-disk-space
database: shut the program down immediately if we run out of disk space
2025-05-06 16:31:09 -07:00
Calvin Kim
cabd3654a9 database: shut the program down immediately if we run out of disk space
Currently btcd keeps downloading blocks and fails to verify them if the
disk is out of space. We exit immediately if we detect that the disk is
out of space to ensure the database is at a recoverable state later on.
2025-05-06 08:43:01 +09:00
Oleg Bondar
64fe10c77a
dbtool: add TestNet4 config param 2025-03-18 11:18:38 -05:00
petersssong
6f09db1924 multi:use t.TempDir replace os.MkdirTemp 2025-03-07 16:54:47 +08:00
finaltrip
c448768d1f refactor: using slices.Contains to simplify the code
Signed-off-by: finaltrip <finaltrip@qq.com>
2025-02-13 00:02:09 +08:00
omahs
019988b696
multi: fix typos 2024-10-08 14:41:44 +02:00
Calvin Kim
c9fae1ac7c ffldb: close block files before deleting them
The block files may be open when deleteFile is called.  This resulted in
files not being deleted and erroring out on windows.  Properly closing
the files closing the files avoids this error.
2024-07-01 22:13:22 +09:00
Calvin Kim
8ed8ef1340 ffldb: refactor out file close code into its own method
The existing file close code is refactored out into it's own method
closeFile() so that it can be reused elsewhere.
2024-07-01 22:12:32 +09:00
Calvin Kim
8b5f2aa6f2 ffldb: add check for deleting files that are open
This check let's us ensure that attempting to delete open files are
caught during unit tests.
2024-07-01 22:12:32 +09:00
Calvin Kim
4712e20049 ffldb: throw error when attempting to delete an open file
This change lets us test that we don't attempt to delete open files with
unit tests.  On Windows this behavior is not allowed which results in an
error but on linux and osx it's allowed. To better test Windows
compatibilty adding this explicit check in is useful.
2024-07-01 22:12:32 +09:00
goodfirm
9f93dc1842
chore: fix function names in comment (#2163)
Signed-off-by: goodfirm <fanyishang@yeah.net>
2024-04-10 12:59:42 -04:00
mattn
3cb9f602e8
fix typos (#2100) 2024-03-25 09:44:25 -04:00
theedtron
b66f5b8379
multi: fix ioutil deprecated function
update i/o functions to use os / io package functions instead
2024-03-08 17:41:41 -08:00
vuittont60
048a7ef40b
database: fix typo 2024-01-09 17:12:09 +08: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
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
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
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
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
cui fliter
e160bb6922 multi: remove repetitive the
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-06-26 15:40:51 +08: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
Anup Chenthamarakshan
87e3d7e278 Replace github.com/btcsuite/goleveldb with github.com/syndtr/goleveldb 2022-03-08 10:07:52 -08:00
Olaoluwa Osuntokun
caac0f821a
multi: update btcutil imports to point to new sub-module
In this commit, we update all the btcutil imports to point to the new
sub-module.

In the same commit, we also modify the recently added `btcutil/go.mod`
file as we need to continue pointing to the _old_ version of btcd, until
we merge this PR and push a new tag.
2022-01-10 18:44:58 -08:00
Jake Sylvestre
d08785547a docs: update shields 2021-03-05 07:45:19 -05:00
Iskander Sharipov
0886f1e5c1 simplify s[:] to s where s is a slice
Found using https://go-critic.github.io/overview#unslice-ref
2020-11-20 15:43:12 -05:00
ipriver
42782bba18 removed unnecessary GOMAXPROCS function calls 2020-09-14 09:57:30 -04:00
David Hill
f7399e6157 build: clean linter warnings 2020-05-13 08:58:39 -04:00
tpkeeper
8512affc59 readme: remove duplicate word 2020-05-06 08:32:44 -04:00
Murray Nesbitt
9f15a7e6af Alphabetize --help output; add missing options to doc.go 2020-04-14 05:09:43 -05:00
Yash Bhutwala
318c89dfed fix comment of database.Tx to match code 2020-03-04 09:21:27 -05:00
Nisen
0c76fbd26f Fix comment error 2020-03-04 08:40:20 -05:00
Olaoluwa Osuntokun
3d1caa2f83 multi: update to point to roasbeef forks 2018-05-23 16:46:15 -07:00
Jim Posen
ad00e7ff82 database: Stop writing block header data to LevelDB.
Now that all headers are stored in the in-memory index, the database
bucket managed by blockchain, and in the flat files, it makes sense to
drop the redundant data from the block index bucket in ffldb.

To avoid modifying the database interface, this reimplements
FetchBlockHeader(s) to use header data stored in flat files. This can
be trivially implemented by delegating to FetchBlockRegion.
2018-01-28 23:34:56 -06:00
Leonardo Lazzaro
78d12c33f0 database: Update rpcclient link in README.md. 2018-01-25 22:43:53 -06:00
Dave Collins
01cb59c67d
multi: Simplify code per gosimple linter.
This simplifies the code based on the recommendations of the gosimple
lint tool.
2017-07-01 02:25:10 -05:00
Josh Rickmar
a6965d493f all: Remove seelog logger.
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-19 16:46:50 -04:00
Steven Roose
3d0dfed40b Fix a ton of typos accumulated over time 2017-05-30 16:59:51 +02:00
Dave Collins
9918e2a561
multi: Update markdown files for GFM changes.
The github markdown interpreter has been changed such that it no longer
allows spaces in between the brackets and parenthesis of links and now
requires a newline in between anchors and other formatting.  This
updates all of the markdown files accordingly.

While here, it also corrects a couple of inconsistencies in some of the
README.md files.
2017-05-25 12:06:16 -05:00
Dave Collins
f8673776ab
database: Update overview documentation in doc.go.
This updates the overview documentation to remove reference of the
outside Namespace bits.
2017-05-21 18:22:33 -05:00
David Hill
4f12c97d0f Drop btcsuite/go-flags in favor of upstream 2017-01-09 14:10:18 -06:00
Dave Collins
915fa6639b
multi: Simplify code per gosimple linter.
This simplifies the code based on the recommendations of the gosimple
lint tool.
2016-11-03 13:00:35 -05:00
Dave Collins
af524fb3e7
multi: Remove unnecessary convs found by unconvert.
This removes all unnecessary typecast conversions as found by the
unconvert linter.
2016-11-03 11:59:38 -05:00
Dave Collins
bd4e64d1d4 chainhash: Abstract hash logic to new package. (#729)
This is mostly a backport of some of the same modifications made in
Decred along with a few additional things cleaned up.  In particular,
this updates the code to make use of the new chainhash package.

Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.

The following is an overview of the changes:

- Remove the wire.ShaHash type
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
  - wire.BlockHeader.BlockSha -> BlockHash
  - wire.MsgBlock.BlockSha -> BlockHash
  - wire.MsgBlock.TxShas -> TxHashes
  - wire.MsgTx.TxSha -> TxHash
  - blockchain.ShaHashToBig -> HashToBig
  - peer.ShaFunc -> peer.HashFunc
- Rename all variables that included sha in their name to include hash
  instead
- Update for function name changes in other dependent packages such as
  btcutil
- Update copyright dates on all modified files
- Update glide.lock file to use the required version of btcutil
2016-08-08 14:04:33 -05:00
Dave Collins
b580cdb7d3 database: Replace with new version.
This commit removes the old database package, moves the new package into
its place, and updates all imports accordingly.
2016-04-12 14:55:15 -05:00