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

Add submitpackage support #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Aug 30, 2024

Based on #22.

Rebased after #22 landed. Should be good for review.

@tnull tnull marked this pull request as draft August 30, 2024 12:22
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Looks good so far.

/// whose fees and vsizes are included in effective-feerate.
#[serde(rename = "effective-includes")]
pub effective_includes: Vec<Wtxid>,
}
Copy link
Member

Choose a reason for hiding this comment

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

These structs look good, we will need to also add similar structs in json/src/model and also into_model() functions on each of them here in this module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I think on the first attempt I didn't quite get when code would fully live in one of the vXX modules and when it would go in model. IIUC, Is the idea that everthing should be duplicated in model and the model is fed with the respective implementations based on the features?

Copy link
Member

Choose a reason for hiding this comment

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

In model the structs are fully typed i.e., in the respective json version module we use standard language types (String, u32) and in model we use bitcoin types (BlockHash, Version). The into_model function is to do the conversion. The hope is that then the model structs will be somewhat universal across all the Core versions without having a bunch of conditional logic in them. We will only know if this works after writing a bunch more code though. I did iterate quite a few times already to get to this design, so I am hopeful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think I still don't fully get why the model is necessary. Why can't we just use serde's with attribute for the fields that need to be de/serialized differently from their Rust type?
It would allow to avoid a lot of redundant boilerplate, at least if I understand the problem at hand correctly?

For example, see these definitions: https://github.com/lightningdevkit/lightning-liquidity/blob/8dd8a1cdf52d5913ff18d9677c152c521b22c4cc/src/lsps0/ser.rs#L603-L678 which are used here: https://github.com/lightningdevkit/lightning-liquidity/blob/8dd8a1cdf52d5913ff18d9677c152c521b22c4cc/src/lsps2/msgs.rs#L85-L105

Copy link
Member

Choose a reason for hiding this comment

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

The problem the model module is trying to solve is multiple versions of Core returning different things for the same JSONRPC method. This led, in rust-bitcoincore-rpc, to loads of logic inside the types crate to handle the differences, this was scattered all over the place making it hard to know exactly what was supported and what was not. The idea in this repo is to make the version specific types dumb as possible, then the model types are, if possible, some representation of the data returned by all supported Core versions. Each version specific type then implements into_model (if possible). Users are free to not use the model types at all if they only want standard typed fields and not the rust-bitcoin typed fields in model. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

it's not clear to me what happens if we in fact can't easily accommodate a breaking change, i.e., would we end up with multiple models?

Definitely not, we just modify the model. The model structs can become as convoluted as necessary and still not effect easy reading, writing, and usage of the version specific JSON types. Then there are no strange JSONRPC errors to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there is a good solution to Core's JSONRPC API returning different data for different versions

Mhh, I see the issue for the raw JSON types, but want to note we could somewhat mitigate the issue in the client implementation by checking the version after connection (e.g., through getnetworkinfo), and switch to the matching types accordingly? In any case, I'll just proceed for now.

Copy link
Member

Choose a reason for hiding this comment

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

Yes in theory, but someone somewhere said that some ops guys disable that RPC method for some security reason that I don't remember so their is no reliable way to get the version. The fella shortly afterwards did a PR to Core to add a new method to get just the version. I can dig it out if you want but since we want to support old versions it doesn't help us much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can dig it out if you want but since we want to support old versions it doesn't help us much.

Since it came up once or twice since you wrote this, I'd actually be interested to hear how and why they do this. Do you think you can still find it?

Copy link
Member

Choose a reason for hiding this comment

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

Right now I have no clue, but I can keep you in mind and message you if/when I stumble upon it.

@tcharding
Copy link
Member

Woops, no need to run CI we know its going to fail because there is no binary to pull down.

@tcharding
Copy link
Member

How hard was it to work out how to patch this repo @tnull? I realise its a bit unusual, from your experience do you think I'm correct in thinking that there is no point asking more junior devs to work on this repo because its a little too strange?

@tnull
Copy link
Contributor Author

tnull commented Sep 2, 2024

How hard was it to work out how to patch this repo @tnull? I realise its a bit unusual, from your experience do you think I'm correct in thinking that there is no point asking more junior devs to work on this repo because its a little too strange?

Given there are no docs describing the ideas behind the project layout (w.r.t. features etc) it took a while to get the hang of it. I think if it would be clearly documented how everything's supposed to work it shouldn't be too hard to contribute though, even for more junior devs.

@tcharding
Copy link
Member

No sweat, I actually added a wiki doc yesterday before reading your comment above but we can do even better. Thanks man.

We don't actually test package submission semantics, but most of the
type de/ser logic by submitting a package of two already-known txs.
@tnull tnull changed the title WIP: Add submitpackage support Add submitpackage support Nov 7, 2024
@tnull tnull marked this pull request as ready for review November 7, 2024 13:11
@tnull tnull requested a review from tcharding November 7, 2024 13:11
@tnull
Copy link
Contributor Author

tnull commented Nov 7, 2024

I now rebased this after #22 landed, fixed some minor things and added a really basic test for most of the introduced API types (we don't actually test package submission, but submission of two already-known transactions).

Should be good for review (cc @tcharding)

@tcharding
Copy link
Member

Thanks for the work man, I didn't review closely but a few quick comments:

  • Can you do this as a single patch please since its a discreet change
  • Can you remove the commented out docs from Bitocin Core in json/src/v28/raw_transactions.rs
  • We either need an issue saying "Implement into_model for SubmitPackage" or we should implement it in this PR

use bitcoin::{Amount, FeeRate, Txid, Wtxid};
use serde::{Deserialize, Serialize};

/// Models the result of JSON-RPC method `submitpackage`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Models the result of JSON-RPC method `submitpackage`.
/// Result of JSON-RPC method `submitpackage`.

So folk don't get confused between this and the model module types.

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.

2 participants