Skip to content

Conversation

@td202
Copy link
Contributor

@td202 td202 commented Oct 15, 2025

Purpose

Closes COR-775

Revise the ChainParameters type to expose all fields as optional, rather than through multiple variants.

Changes

  • Replaced ChainParameters with a new struct, and introduced helpers and conversions.
  • Add testing for conversions from protobuf types.
  • Migration guide.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

@td202 td202 requested review from DOBEN, allanbrondum, limemloh and soerenbf and removed request for limemloh October 16, 2025 12:33
- Type `Event`/`BakerPoolInfo` field `open_status` is now wrapped in `Upward`.
- Bubble `Upward` from new variants of `VerifyKey` to `Upward<AccountCredentialWithoutProofs<...>>` in `AccountInfo::account_credentials`.

- BREAKING: Remove types associated with discontinued V1 API:
Copy link
Contributor

Choose a reason for hiding this comment

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

What does V1 and V2 API mean in the current codebase?

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't V2 the gPRC/protobuf API?

Copy link
Contributor

@allanbrondum allanbrondum Oct 17, 2025

Choose a reason for hiding this comment

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

And the types used by the gRPC/protobuf API (the non-protobuf types that we convert to from the generated protobuf types) are also located in types and not necessarility in v2? (just to align on where we put types)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

V2 is the current gRPC/protobuf API, yes. V1 was the old API that was often JSON inside protobuf (it was removed in Node version 6.2.1). It could make sense to move ChainParameters from v2 to types (and the associated definitions), since that's largely where the types belong. It's a little bit confused because there were two ChainParameters types (one in types and one in v2).

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we put all the new types in types and not in v2 then? It seems a bit confusing to add types in v2 module?

- Bubble `Upward` from new variants of `VerifyKey` to `Upward<AccountCredentialWithoutProofs<...>>` in `AccountInfo::account_credentials`.

- BREAKING: Remove types associated with discontinued V1 API:
- `types::BlockSummary`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the removal of BlockSummary and the related types in UpdateQueue unrelated to the other changes? It seems it could have been a separate PR (just for another time)

Comment on lines +392 to +411
impl TryFrom<MintDistribution> for types::MintDistributionV1 {
type Error = MintDistributionConversionError;
fn try_from(value: MintDistribution) -> Result<Self, Self::Error> {
let baking_reward =
value
.baking_reward
.ok_or(MintDistributionConversionError::MissingField(
"baking_reward",
))?;
let finalization_reward =
value
.finalization_reward
.ok_or(MintDistributionConversionError::MissingField(
"finalization_reward",
))?;
Ok(Self {
baking_reward,
finalization_reward,
})
}
Copy link
Contributor

@allanbrondum allanbrondum Oct 21, 2025

Choose a reason for hiding this comment

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

Are the conversions into base types needed? I mean is it justified that we maintain this code and these conversions? Or do we want a general policy that you can convert SDK types into base types and just always implement the conversions?

Comment on lines +78 to +105
For signing chain updates, use [`construct_update_signer()`](v2::Level2Keys::construct_update_signer), for instance as:

```rust,no_compile
let params = client
.get_block_chain_parameters(&BlockIdentifier::LastFinal)
.await
.context("Could not obtain chain parameters")?;
let keys = params
.response
.keys
.level_2_keys
.context("No level 2 keys in chain parameters.")?;
let signer = keys
.construct_update_signer(
keys.micro_ccd_per_euro
.as_ref()
.context("Missing uCCD:EUR exchange rate update keys.")?,
kps,
)
.context("Invalid keys supplied.")?;
let block_item: BlockItem<Payload> =
update::update(&signer, seq_number, effective_time, timeout, payload).into();
```

Constructing updates to the level 2 keys requires an [`AuthorizationsV1`](types::AuthorizationsV1) (or for old protocol versions, [`AuthorizationsV0`](types::AuthorizationsV0)) which can be obtained with `Level2Keys::try_into()`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the instructions could be more targeted on what usages we actually expect of the SDK (too much information can make the instructions less clear or just seem overwhelming). This usage of posting an update instruction, we likely have 0 users doing that? So we could write it shorter and just say there are changes to these types.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also an unexplained variable kps in the example (holds the private keys).


/// Timeout parameters for the new consensus protocol introduced in protocol
/// version 6.
#[derive(Debug, Clone, Default)]
Copy link
Contributor

@allanbrondum allanbrondum Oct 21, 2025

Choose a reason for hiding this comment

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

I would also just add Eq, PartialEq, Hash` to the types (https://rust-lang.github.io/api-guidelines/interoperability.html#c-common-traits)

}

#[derive(Debug, Clone, Default)]
pub struct ChainParameters {
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation on this and a few other types is missing

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