Commit Graph

114 Commits

Author SHA1 Message Date
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
cui fliter
e160bb6922 multi: remove repetitive the
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-06-26 15:40:51 +08: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
Olaoluwa Osuntokun
9c16d23918
Merge pull request #1879 from GeorgeTsagk/wire/outpoint-parse-string
Add wire.Outpoint parser from string
2023-05-24 19:40:36 -07:00
Elle Mouton
6a03eb372b
wire: increase max witness items per input 2022-11-01 13:43:52 +02:00
Olaoluwa Osuntokun
f523d4ccaa
wire: remove erroneous witness size check in wire parsing
In this commit, we fix a bug that would cause nodes to be unable to
parse a given block from the wire. The block would be properly accepted
if fed in via other mechanisms.

The issue here is that the old checks for the maximum witness size,
circa segwit v0 where placed in the wire package _as well_ as the tx
engine. This check should only be in the engine, since it's properly
gated by other related scrip validation flags.

The fix itself is simple: limit witnesses only based on the maximum
block size in bytes, or ~4MB.
2022-10-09 18:09:02 -07:00
George Tsagkarelis
d827d0240a
wire: add outpoint string parser unit tests 2022-08-17 19:22:33 +03:00
George Tsagkarelis
571f9c69ec
wire: add string parser to outpoint 2022-08-17 18:25:24 +03:00
Olaoluwa Osuntokun
bf64c8bdbb
Merge pull request #1812 from Crypt-iQ/btcd_addrv2
multi: implement BIP-155 addrv2 support
2022-04-13 10:25:12 -07:00
Olaoluwa Osuntokun
79c314d503
txscript: add taproot JSON success/fail reference tests
In this commit, we add a total of 2760 taproot reference tests generated
by the bitcoind functional tests located at:
https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py.
The tests aren't deterministic (fresh private keys are generated), so we
time we go to update the set of tests, we'll end up with fresh hashes
(the file name is the sha1 of the raw json test) and tests.
2022-03-15 18:23:29 -07:00
Olaoluwa Osuntokun
81a546bded
wire: export WriteOutPoint to public module 2022-03-15 18:22:35 -07:00
eugene
cb6f21b598
peer+wire: add addrv2 message, protocol negotiation 2022-02-24 13:11:15 -05:00
eugene
1ec4a1e77f
wire: netaddressv2 and tests 2022-02-24 13:11:12 -05:00
Jake Sylvestre
d08785547a docs: update shields 2021-03-05 07:45:19 -05:00
Yaacov Akiba Slama
29c9ff351c Add support for receiving sendaddrv2 message from a peer 2020-12-02 12:10:43 +02: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
Anirudha Bose
ff59bbc14a wire: add proper types for flag field and improve docs
Summary of changes:

- Add a new const TxFlagMarker to indicate the flag prefix byte.
- Add a new TxFlag type to enumerate the flags supported by the
  tx parser.

  This allows us to avoid hardcoded magics, and will make it easier
  to support new flags in future.
- Improve code comments.

Closes #1598.
2020-09-14 09:50:13 -04:00
Federico Bond
35194e2dac btcjson,wire: fix invalid use of string(x) to convert byte value 2020-08-31 16:01:10 -04:00
David Hill
f7399e6157 build: clean linter warnings 2020-05-13 08:58:39 -04:00
Wilmer Paulino
2cd83210b5
wire: only write message payload if there actually is one
There are certain messages that won't have a payload, e.g., verack,
causing an unnecessary write of 0 bytes.
2019-08-20 15:26:23 -07:00
Conner Fromknecht
7a657ffa2e
wire/msgcfcheckpt: add sanity check for cf checkpoint parsing 2018-08-23 22:55:20 -07:00
Olaoluwa Osuntokun
21b0303341
wire: remove instances of the extended gcs filter 2018-07-06 16:15:25 -07:00
Olaoluwa Osuntokun
66d632f32e
wire: remove the extended filter 2018-07-06 16:15:23 -07:00
Dave Collins
a59ac5b18f
multi: Rework utxoset/view to use outpoints.
This modifies the utxoset in the database and related UtxoViewpoint to
store and work with unspent transaction outputs on a per-output basis
instead of at a transaction level.  This was inspired by similar recent
changes in Bitcoin Core.

The primary motivation is to simplify the code, pave the way for a
utxo cache, and generally focus on optimizing runtime performance.

The tradeoff is that this approach does somewhat increase the size of
the serialized utxoset since it means that the transaction hash is
duplicated for each output as a part of the key and some additional
details such as whether the containing transaction is a coinbase and the
block height it was a part of are duplicated in each output.

However, in practice, the size difference isn't all that large, disk
space is relatively cheap, certainly cheaper than memory, and it is much
more important to provide more efficient runtime operation since that is
the ultimate purpose of the daemon.

While performing this conversion, it also simplifies the code to remove
the transaction version information from the utxoset as well as the
spend journal.  The logic for only serializing it under certain
circumstances is complicated and it isn't actually used anywhere aside
from the gettxout RPC where it also isn't used by anything important
either.  Consequently, this also removes the version field of the
gettxout RPC result.

The utxos in the database are automatically migrated to the new format
with this commit and it is possible to interrupt and resume the
migration process.

Finally, it also updates the tests for the new format and adds a new
function to the tests to convert the old test data to the new format for
convenience.  The data has already been converted and updated in the
commit.

An overview of the changes are as follows:

- Remove transaction version from both spent and unspent output entries
  - Update utxo serialization format to exclude the version
  - Modify the spend journal serialization format
    - The old version field is now reserved and always stores zero and
      ignores it when reading
    - This allows old entries to be used by new code without having to
      migrate the entire spend journal
  - Remove version field from gettxout RPC result
- Convert UtxoEntry to represent a specific utxo instead of a
  transaction with all remaining utxos
  - Optimize for memory usage with an eye towards a utxo cache
    - Combine details such as whether the txout was contained in a
      coinbase, is spent, and is modified into a single packed field of
      bit flags
    - Align entry fields to eliminate extra padding since ultimately
      there will be a lot of these in memory
    - Introduce a free list for serializing an outpoint to the database
      key format to significantly reduce pressure on the GC
  - Update all related functions that previously dealt with transaction
    hashes to accept outpoints instead
  - Update all callers accordingly
  - Only add individually requested outputs from the mempool when
    constructing a mempool view
- Modify the spend journal to always store the block height and coinbase
  information with every spent txout
  - Introduce code to handle fetching the missing information from
    another utxo from the same transaction in the event an old style
    entry is encountered
    - Make use of a database cursor with seek to do this much more
      efficiently than testing every possible output
- Always decompress data loaded from the database now that a utxo entry
  only consists of a specific output
- Introduce upgrade code to migrate the utxo set to the new format
  - Store versions of the utxoset and spend journal buckets
  - Allow migration process to be interrupted and resumed
- Update all tests to expect the correct encodings, remove tests that no
  longer apply, and add new ones for the new expected behavior
  - Convert old tests for the legacy utxo format deserialization code to
    test the new function that is used during upgrade
  - Update the utxostore test data and add function that was used to
    convert it
- Introduce a few new functions on UtxoViewpoint
  - AddTxOut for adding an individual txout versus all of them
  - addTxOut to handle the common code between the new AddTxOut and
    existing AddTxOuts
  - RemoveEntry for removing an individual txout
  - fetchEntryByHash for fetching any remaining utxo for a given
    transaction hash
2018-05-27 03:07:41 -05:00
Olaoluwa Osuntokun
5596b63846 multi: fix linter warnings 2018-05-23 16:46:15 -07:00
Olaoluwa Osuntokun
b72e16f0d6 multi: correct all import paths 2018-05-23 16:46:15 -07:00
Olaoluwa Osuntokun
ceb1caeb24 wire: increase MaxGetCFiltersReqRange from 100 to 1000 2018-05-23 16:46:15 -07:00
Jim Posen
0581e18840 wire: Define CFCheckpt message. 2018-05-23 16:46:15 -07:00
Jim Posen
336b18c584 wire: Define GetCFCheckpt message. 2018-05-23 16:46:15 -07:00
Jim Posen
4c991c8783 wire: Populate cfheaders message with filter hashes instead of headers. 2018-05-23 16:46:15 -07:00
Jim Posen
175af18043 multi: Modify CFHeaders message to have a PrevFilterHeader field. 2018-05-23 16:46:15 -07:00
Jim Posen
7a53a05878 multi: Redefine GetCFHeaders to have StartHeight and StopHash. 2018-05-23 16:46:15 -07:00
Jim Posen
daac60675e multi: Redefine GetCFilters to have StartHeight and StopHash. 2018-05-23 16:46:15 -07:00
Jim Posen
621f347929 wire: Remove cftypes and getcftypes commands. 2018-05-23 16:46:15 -07:00
Alex
c7e7acc7fd multi: use hidden varint for cftypes count; make filter type enum, not uint8 2018-05-23 16:46:15 -07:00
Alex
8d2ce855eb wire: update service bits for xthin, bit 5, cfilters, and segwit2x 2018-05-23 16:46:15 -07:00
Alex
1aa7a6166d wire: update messages to conform to BIP and fix comments 2018-05-23 16:46:15 -07:00
Alex
89d6696560 wire: add getcftypes and cftypes messages 2018-05-23 16:46:15 -07:00
Alex
621c73dad1 multi: change cfilter Extended bool to FilterType uint8
The cfilter BIP specifies that the filter type is a uint8. The
current code encodes it correctly on the wire, but everywhere else,
it's treated as a boolean (false for basic filter, true for
extended). This commit corrects that to account for possible
additional filter types in the future. All package changes are
done in one commit as they're all interdependent. The following
packages are updated:

* blockchain/indexers
* btcjson
* peer
* wire
* main (server.go and rpcserver.go)
2018-05-23 16:46:15 -07:00
Olaoluwa Osuntokun
7c2f7be2ea wire: update compact filter messages to match wire.Message interface 2018-05-23 16:46:15 -07:00
Alex
dabb8000fb Add Extended flag to cfilter and cfheaders messages 2018-05-23 16:46:15 -07:00
Alex
936caad9c2 Add last blockhash to cfheaders and blockhash to cfilter messages 2018-05-23 16:46:15 -07:00
Alex
ba4a2f77a5 wire/server: allocate hash once per loop to prevent overwriting 2018-05-23 16:46:15 -07:00
Alex
71ccc95502 wire: Fix MsgCFHeaders.Decode() 2018-05-23 16:46:15 -07:00
Alex
29b5ece196 Changed getcfheaders/cfheaders messages to get multiple headers. 2018-05-23 16:46:15 -07:00
Alex
8ad7aa5d5d Rename CFilterHeader to CFHeader on P2P side; fix some bugs/tests 2018-05-23 16:46:15 -07:00
pedro martelletto
0c08ba2786 define MsgCFilterHeader.Deserialize(), required by btcrpcclient 2018-05-23 16:46:15 -07:00
pedro martelletto
b5de49aa73 define MsgCFilter.Deserialize(), required by btcrpcclient 2018-05-23 16:46:15 -07:00
pedro martelletto
b8c3be740f Add CFilterHeader p2p counterparts 2018-05-23 16:46:15 -07:00