Add Serde implementations to some structs#3157
Add Serde implementations to some structs#3157amackillop wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #3157 +/- ##
==========================================
- Coverage 89.83% 89.76% -0.08%
==========================================
Files 121 121
Lines 99454 99468 +14
Branches 99454 99468 +14
==========================================
- Hits 89345 89286 -59
- Misses 7506 7560 +54
- Partials 2603 2622 +19 ☔ View full report in Codecov by Sentry. |
ea9900b to
5b2698e
Compare
|
|
||
| core2 = { version = "0.3.0", optional = true, default-features = false } | ||
| libm = { version = "0.2", optional = true, default-features = false } | ||
| serde = { version = "1.0.203", optional = true, features = ["derive"] } |
There was a problem hiding this comment.
Could you set default-features = false to reduce the serde dependency to the minum required?
TheBlueMatt
left a comment
There was a problem hiding this comment.
I'm a bit confused by the set of things being serialized/deserialized here - what specifically are you trying to get serializable here?
|
|
||
| /// An enum representing the available verbosity levels of the logger. | ||
| #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
There was a problem hiding this comment.
This seems like a very weird thing to serialize?
There was a problem hiding this comment.
I suspect the motivation here is to be able to de/serialize LDK Node's Config object, which holds the used LogLevel.
There was a problem hiding this comment.
Correct. It's to avoid writing stuff like this
There was a problem hiding this comment.
Mmm, right. I guess it makes sense, though we should probably implement a serialization here that makes it readable, rather than just what I presume is writing an integer.
| /// | ||
| /// [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md | ||
| #[derive(Clone, Debug, Hash, PartialEq, Eq)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
There was a problem hiding this comment.
IIUC just blindly implementing Deserialize here will allow for something that violates our conditions on the internal field's value.
|
Also, if your goal is just to have a json version of some structs, maybe we should only implement Serialize, not De? |
Mh, but if you're able to serialize something, say to a JSON-based config file, you'd like to be able to read it afterwards, no? |
This set of things is based on the structs being returned by the LDK Node API. It's the set of structs that are included in structs returned by those methods or accepted as arguments plus some structs included in configuration. I'm currently doing something similar to this but was exploring what the use of JSON instead of protocol buffers would look like. With Ser/De implementations, it makes it easier to use JSON. That said, I'm still actively building the thing and some of the default implementations for these types don't actually work for what I'm doing. For example, the default implementation for Deserialize for |
|
This needs a rebase by now. @amackillop still interested in working on this? |
|
Yep I can get back to this sometime this week. This will be useful for the Prober project that I am also working on |
5b2698e to
c845508
Compare
|
Seems CI is failing unfortunately. |
|
I know why, serde_json as a test dependency causes ambiguity for some trait implementations |
|
Huh, I can't reproduce locally either. Can you rebase fix the non-spurious errors and then we'll look at it further? eg |
|
Ah, nevermind, yea, these aren't spurious, you'll need to specify the types explicitly because serde adds another option for those calls. |
|
Closing as abandoned. If you want to pick this back up no problem, we can reopen. |
I'm working on this issue in ldk-node and I think it requires adding Serialization/Deserialization implementations to some types here first. I only added implementations to to the minimal amount of structs needed based on what is returned by the ldk-node api. I'm happy to add this to more structs while I'm here if that is desired.
I understand that there has been some disagreement about adding this support to the library. My use case here is that I want to be able to use some of the ldk-node structs (which depend on these ones) as JSON responses from a server built on top of it.
The current state of this draft is just the minimal set of implementations to fix type errors when adding the the same implementations in ldk-node.