Crates.io | lightning-wire-msgs |
lib.rs | lightning-wire-msgs |
version | 0.2.1 |
source | src |
created_at | 2019-08-22 22:16:16.537577 |
updated_at | 2019-09-06 20:25:40.664686 |
description | bitcoin lightning wire message types |
homepage | |
repository | |
max_upload_size | |
id | 158988 |
size | 45,268 |
A crate defining serialization and deserialization for lightning wire messages into rust structs.
This crate defines the following traits:
WireItemWriter
and WireItemReader
encode
.decode
TLVWireItemWriter
and TLVWireItemReader
encode
.encode_tlv
.decode
.decode_tlv
.WireMessageWriter
and WireMessageReader
.check_type
is false for decode
, it is expecting the message without the first 2 bytes indicating the message type.std::io::ErrorKind::InvalidData
.encode
.decode
.WireMessage
.WireMessageWriter
.WireMessageReader
.Most lightning messages can be trivially implemented using the following derive macros:
WireMessageWriter
or WireMessageReader
.#[msg_type = 123]
which defines the 2 byte number used to uniquely identify the message type.WireItemWriter + WireItemReader
.
WireMessageWriter
, only requires WireItemWriter
.WireMessageReader
, only requires WireItemReader
.#[tlv_type = 123]
attribute.Option<T> where T: TLVWireItemWriter + TLVWireItemReader
.
WireMessageWriter
, only requires TLVWireItemWriter
.WireMessageReader
, only requires TLVWireItemReader
.AnyWireMessageWriter
or AnyWireMessageReader
WireMessageWriter + WireMessageReader
.
AnyWireMessageWriter
, only requires WireMessageWriter
.AnyWireMessageReader
, only requires WireMessageReader
.Tested 1,000,000 serializations and deserializations of the watchtower::Init
message, for both this crate and lnd with the following results:
387.640625ms
1.349666231s
Code for lnd benchmark can be found at bench/bench.go
.
Code for crate benchmark can be found at the end of src/lib.rs
.
I urge anyone else to verify these benchmarks, however I am fairly confident at this point that my crate cuts serialization + deserialization time down by about 70%.