Commit Graph

61 Commits

Author SHA1 Message Date
Steven Roose 61918dfe81
Change the signature of consensus_encode to return io::Error's
This is instead of encode::Errors because the encoders should
not be allowed to return errors that don't originate in the writer
they are writing into.

This is a part of the method definition that has been relied upon for a
while already.
2021-01-12 17:39:41 +00:00
Andrew Poelstra 4b58a254c5 encode: add some more generic impls (more tuples, references) 2021-01-08 23:21:55 +00:00
Steven Roose 767b14f696
Make Inventory and NetworkMessage enums exhaustive
Both by added an `Unknown` variant.
2020-12-21 12:04:26 +00:00
Alekos Filini 373f355b5a Flush unrecognized network messages from the read buffer
Currently whenever an unrecognized network message is received, it is never
flushed from the read buffer, meaning that unless the stream is closed and
recreated it will keep returning the same error every time `read_next()` is
called.

This commit adds the length of the message to `UnrecognizedNetworkCommand`,
so that the `StreamReader` can flush those bytes before returning the error
to the caller.
2020-12-15 19:54:21 +01:00
Andrew Poelstra 8295885e8e
Merge pull request #454 from jrawsthorne/improved-bip158-types
Implement new FilterHeader type to differentiate from FilterHash
2020-11-05 16:46:50 +00:00
Jake Rawsthorne cf8e290c99 AddrV2 structures 2020-10-26 21:46:10 +00:00
Andrew Poelstra 93df7cbd3e
Merge pull request #291 from kallewoof/2019-07-signet
add signet support
2020-10-26 19:46:10 +00:00
Steven Roose 545965d9e3
Change consensus::encode::serialize assert to debug_assert
This is just a sanity check on our own serialization code.
2020-10-23 21:28:17 +01:00
Steven Roose 5c04a059d5
Change some static assertions to debug_assert 2020-10-23 21:28:13 +01:00
Jake Rawsthorne eeb14c4b08 Implement new FilterHeader type to differentiate from FilterHash 2020-10-10 20:38:10 +01:00
Elichai Turkel 2d70623356
Remove deprecated Error::description impl 2020-10-08 17:11:18 +03:00
Elichai Turkel 023fae1f65
Add the dyn keyword where appropriate 2020-10-08 17:11:16 +03:00
Elichai Turkel efe1a55819
Use new inclusive range syntax 2020-10-08 17:08:51 +03:00
Karl-Johan Alm a3d9899cb1
add signet support 2020-09-18 16:32:33 +09:00
Matt Corallo cf45a61070 Set Params::pow_limit to an attainable value not a theoretical one
`cloudhead` on IRC was asking how to properly use
`BlockHeader::validate_pow()` on genesis (or similar) when the
pow_limit field isn't expressible as a compact target (and, thus,
does not actually represent the PoW limit/genesis target). We
swap it for the actual PoW limit by truncating the way a compact
encoding round-trip would.

Note that, in Bitcoin Core, the original value is only ever used
once in its original form:
```
    if (bnNew > bnPowLimit) // Note: bnPowLimit is params.powLimit
        bnNew = bnPowLimit;

    return bnNew.GetCompact();
```
Thus, even if Core adopted our change, as long as there exist no
256-bit integer x which satisfies
`x <= powLimit && x > encoding_roundtrip_truncated(powLimit)` and
`enoding_roundtrip_truncated(x) != powLimit`, the change would have
no impact on consensus.

It is trivial to show that there are no values which are between
the new value
(0x00000000ffff0000000000000000000000000000000000000000000000000000)
and the original value
(0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
which can be encoded in compact form, but it is also critically, no
such values will encode to a compact form of anything different than
the new value as the encoding always truncates the low bits, never
rounding up.
2020-09-10 12:03:51 -04:00
Andrew Poelstra 7efde3ae47
Merge pull request #419 from elichai/2020-03-description
Deprecate Error::description
2020-05-23 17:26:38 +00:00
Elichai Turkel af31017eb1
Remove the cursor overhead, write is implemented on vec these days 2020-05-19 12:57:39 +03:00
Elichai Turkel 654232a3dc
Deprecate Error::description 2020-04-13 02:15:28 +03:00
Elichai Turkel a473d01b17
Made some idiomatic changes 2020-03-29 17:15:15 +03:00
Elichai Turkel 16eb81e1f7
Replaced slow vec initialization, and dual calls to hashmap 2020-03-29 17:10:27 +03:00
Elichai Turkel 5d276caf95
Mutation testing: encode: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel eb7369b1db
Simlify consensus_encode vectors 2020-02-23 15:59:23 +02:00
Dr Maxim Orlovsky 5fc24dea33 Multiple fixes for hash types and their computing
Unit test for wtxid and SegWit transactions
2020-01-01 13:54:23 +01:00
Dr Maxim Orlovsky f5a8087105 New hash types: MerkleRoot/Branch, WitnessCommit, SigHash, FilterHash 2020-01-01 13:50:17 +01:00
Steven Roose 024557fe47
Merge pull request #357 from stevenroose/command-str
Various optimizations of the network code
2019-12-11 15:38:52 +00:00
Steven Roose 617c07d796
Remove encode::Error::ByteOrder
Functions from the byteorder crate only return downstream io errors on
io calls.
2019-12-09 14:19:11 +00:00
Steven Roose 5f4555bfac
Remove util::misc::hex_bytes in favor of bitcoin_hashes::hex 2019-12-09 14:19:09 +00:00
Steven Roose 1eeaccc92e
Add encode::Error::NonMinimalVarInt variant 2019-12-09 14:19:05 +00:00
Steven Roose d02318f423
Remove deprecated std::error::Error::description 2019-12-09 14:18:37 +00:00
Steven Roose 5373428510
Drop unused encode::Error::Secp256k1 variant 2019-12-09 14:17:41 +00:00
Steven Roose 725884bab5
Introduce key::Error 2019-12-09 14:17:39 +00:00
Steven Roose c30d6d12ab
Implement Encodable for Cow<'static, str> 2019-12-08 20:57:46 +00:00
Matt Corallo acb43af981 Drop byteorder dependency
Taking an external dependency just to convert ints to byte arrays
is somewhat of a waste, especially when Rust isn't very aggressive
about doing cross-crate LTO.

Note that the latest LLVM pattern-matches this, and while I haven't
tested it, that should mean this means no loss of optimization.
2019-12-05 10:41:00 -05:00
Matt Corallo f1f7718b6c Drop (non-test/serde) hex dep in favor of bitcoin_hashes' fn's 2019-12-05 10:40:59 -05:00
Matt Corallo fe917765c0 Drop message decode max length to 4_000_000
It has been a long time since Bitcoin's maximum network message
length was 32MB, so we should follow suit. This is also an important
DoS limit, so we should limit it as much as possible.
2019-11-06 16:29:21 -05:00
Steven Roose 48f4c1989f
Rename bitcoin_hashes dependency to hashes 2019-08-16 15:52:27 +01:00
Steven Roose 7e0d997150
Remove unused encode::Error variant 2019-08-13 08:47:13 +01:00
Steven Roose 385a657974
Refactor Address
- use AddressError instead of encode::Error
- replace using bech32-bitcoin with Payload::WitnessProgram variant
2019-08-13 08:47:10 +01:00
Aleru 40c5a568fa add TODOs 2019-08-04 22:27:59 -04:00
Andrew Poelstra 3b9a94a178 eliminate type parameter from the `Decodable` trait 2019-07-11 17:23:01 +00:00
Andrew Poelstra 42960b959f eliminate type parameter from `Encodable` trait 2019-07-11 17:21:19 +00:00
Andrew Poelstra b734d6488a make consensus_encode return the encoded length 2019-07-11 17:15:32 +00:00
Andrew Poelstra abb9210c04 make `VarInt::len` and `Transaction::get_weight` return a usize 2019-07-11 17:14:05 +00:00
Andrew Poelstra 7e6ad7c893 rename Encoder to WriteExt and Decoder to ReadExt 2019-07-11 15:01:38 +00:00
Matt Corallo 98796576d2 Fix trivial DoS when deserializing messages from the network 2019-06-05 07:49:19 -04:00
Matt Corallo fa1ec2028d Speed up Vec<u8> [d]e[n]code operations by dropping the generic 2019-05-30 11:25:37 -04:00
Matt Corallo ee827e4aa3 Drop some unused/not-needed Encodable impls 2019-05-30 11:25:37 -04:00
Matt Corallo 084f82be21 Swap a few more [d]encoders to slice emit/read functions 2019-05-30 11:25:37 -04:00
Matt Corallo 7015b064dd Add slice consensus encode/decode functions and use for short arrays 2019-05-30 11:25:37 -04:00
Carl Dong 9c08dbae47 Add PSBT output data key-value map type
- Implement psbt::Map trait for psbt::Output
- Add (en)decoding logic for psbt::Output

- Implement PSBT (de)serialization trait for relevant psbt::Output types

- Add macro for merging fields for PSBT key-value maps
- Add macro for implementing decoding logic for PSBT key-value maps
- Add convenience macro for implementing both encoding and decoding
  logic for PSBT key-value maps
- Add macro for inserting raw PSBT key-value pairs into PSBT key-value
  maps
- Add macro for getting raw PSBT key-value pairs from PSBT key-value
  maps
2019-02-28 10:54:53 -05:00