Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sim-lib: Get rid of nested json for node definition #152

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Oct 25, 2023

I must have been way more sleep-deprived than I thought when originally designing this, but we don't really need the nested json with node type tags to parse node information (as long as the node info has, at least one different field name).

Mainly, this goes from:

"nodes": [
    {
        "LND": {
            "id": "...",
            "address": "...",
            "macaroon": "...",
            "cert": "..."
        }
    },
    {
        "CLN": {
            "id": "...",
            "address": "...",
            "ca_cert": "...",
            "client_cert": "...",
            "client_key": "..."
        }
    }
]

To:

"nodes": [
    {
        "id": "...",
        "address": "...",
        "macaroon": "...",
        "cert": "..."
    },
    {
        "id": "...",
        "address": "...",
        "ca_cert": "...",
        "client_cert": "...",
        "client_key": "..."
    }
]

@sr-gi sr-gi force-pushed the 20231025_improve_json_parsing branch from adf31b7 to 3938066 Compare October 25, 2023 15:48
@@ -25,10 +25,9 @@ mod random_activity;
mod serializers;

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL of this magic! 🥇

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, there's a bunch of these you can use depending on what you're aiming for:

https://serde.rs/enum-representations.html
https://serde.rs/attr-flatten.html

Comment on lines 64 to 65
serde_json::from_str(&std::fs::read_to_string(cli.sim_file)?)
.map_err(|e| anyhow!("Cannot deserialize node connection data into LndConnection nor ClnConnection (line {}, col {})", e.line(), e.column()))?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realised this may not be good, given this can error out both for node parsing and activity parsing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just make the error more holistic?
Could not deserialize node connection (LND or CLN) or activity description: (line {}, col {}) in simulation file.

Most folks should be able to figure it out based on the line). Perhaps also include the error string if there is one? Since it's often hanging , or some other annoying json error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your version better.

Regarding including the original string, there's actually no meaningful info there, that's why I decided to go with a custom error.

Error: data did not match any variant of untagged enum NodeConnection at line 11 column 8

Not even the line and column are that useful, they mark the end of the section where the error is at, not even the real line :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ok, let's just get as user friendly as we can and ship it.

README.md Show resolved Hide resolved
@carlaKC
Copy link
Contributor

carlaKC commented Oct 26, 2023

Let's get this done with high priority if we're going to change it, told the warnet folks to wait on a stable config file before they proceed.

@sr-gi
Copy link
Member Author

sr-gi commented Oct 26, 2023

Let's get this done with high priority if we're going to change it, told the warnet folks to wait on a stable config file before they proceed.

On it

@sr-gi sr-gi force-pushed the 20231025_improve_json_parsing branch from 3938066 to 76c8ced Compare October 26, 2023 18:43
@sr-gi sr-gi requested review from carlaKC and okjodom October 26, 2023 18:44
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nits

README.md Outdated
```
{
"id": <node_id>,
"address": <ip_and_port_or_domain_and_port>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: include https://

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just move this line up?

**Note that node addresses must be declare with HTTPS transport, i.e. <https://ip-or-domain>**

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! But I'd still hard code it in before to get as close as possible - https://<ip:port or domain:port>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm going to open an issue so we don't require this, and we can do that in a low-prio followup

Comment on lines 64 to 65
serde_json::from_str(&std::fs::read_to_string(cli.sim_file)?)
.map_err(|e| anyhow!("Cannot deserialize node connection data into LndConnection nor ClnConnection (line {}, col {})", e.line(), e.column()))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just make the error more holistic?
Could not deserialize node connection (LND or CLN) or activity description: (line {}, col {}) in simulation file.

Most folks should be able to figure it out based on the line). Perhaps also include the error string if there is one? Since it's often hanging , or some other annoying json error.

sr-gi added 2 commits October 26, 2023 15:15
I must have been way more sleep-deprived than I thought when originally designing this,
but we don't really need the nested json with node type tags to parse node information
(as long as the node info has, **at least** one different field name).

Mainly, this goes from:

```json
"nodes": [
    {
        "LND": {
            "id": "...",
            "address": "...",
            "macaroon": "...",
            "cert": "..."
        }
    },
    {
        "CLN": {
            "id": "...",
            "address": "...",
            "ca_cert": "...",
            "client_cert": "...",
            "client_key": "..."
        }
    }
]
```

To:

```json
"nodes": [
    {
        "id": "...",
        "address": "...",
        "macaroon": "...",
        "cert": "..."
    },
    {
        "id": "...",
        "address": "...",
        "ca_cert": "...",
        "client_cert": "...",
        "client_key": "..."
    }
]
```
@sr-gi sr-gi force-pushed the 20231025_improve_json_parsing branch from 76c8ced to 8ad307b Compare October 26, 2023 20:46
@sr-gi
Copy link
Member Author

sr-gi commented Oct 26, 2023

@carlaKC should be good now

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

@sr-gi sr-gi merged commit 1270a16 into bitcoin-dev-project:main Oct 30, 2023
2 checks passed
Extheoisah added a commit to Extheoisah/sim-ln that referenced this pull request Nov 17, 2023
Extheoisah added a commit to Extheoisah/sim-ln that referenced this pull request Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants