Commit Graph

12 Commits

Author SHA1 Message Date
mattn
3cb9f602e8
fix typos (#2100) 2024-03-25 09:44:25 -04:00
Olaoluwa Osuntokun
8ed234b9f5
Merge pull request #2134 from kcalvinalvin/2024-03-07-make-duplicate-entries-on-mapslice-impossible
blockchain: fix a bug where a duplicate entry is possible in the mapslice
2024-03-08 17:54:08 -08:00
Calvin Kim
8d1aa01c69 blockchain: add another mapslice duplicate entry case
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.
2024-03-07 15:24:00 +09:00
Calvin Kim
a0c9e3b384 blockchain: add case for pruning stale blocks
Pruning stale blocks will make the block validation fail for the block
that the prune was triggered on as BlockHeightByHash will not return the
height for blocks that are not in the main chain.

We add a test case to ensure that the test fails in the above case.
2024-02-16 16:17:04 +09:00
Calvin Kim
8836219a02 blockchain: return error in db.View instead of t.Fatal
Calling t.Fatal inside db.View makes the test hang on failures.  Return
the error and call t.Fatal outside of db.View avoids this.
2024-02-16 16:17:04 +09: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
26b2e9d9de blockchain: add test for InitConsistentState 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
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
1f2dfa2d6e blockchain: Add mapslice
This change is part of the effort to add utxocache support to btcd.

mapslice allows the caller to allocate a fixed amount of memory for the
utxo cache maps without the mapslice going over that fixed amount of
memory.  This is useful as we can have variable sizes (1GB, 1.1GB, 2.3GB,
etc) while guaranteeing a memory limit.
2023-12-16 16:36:43 +09:00