Skip to content

Conversation

@MathieuDutSik
Copy link
Contributor

@MathieuDutSik MathieuDutSik commented Aug 27, 2025

Motivation

It has recently been indicated in PR #4347 that the use ChainId in a message would be a waste of space.
But there are other wastage of key space that can be reduced.

Fixes #2391

Proposal

We check for the number of entries in views obtained by linera-views-derive. If lower than 256, we convert to u8.
It is likely that we need to remove as well the linera_views::views::MIN_VIEW_TAG.

Test Plan

CI.

Release Plan

It is definitely breaking the testnet.

Links

None

@MathieuDutSik MathieuDutSik changed the title Update the way that keys are build. Update the way that keys are build in views obtained by linera-views-derive. Aug 27, 2025
@MathieuDutSik MathieuDutSik force-pushed the key_linera_views_derive branch from f8c7730 to c5433dd Compare August 27, 2025 15:21
@MathieuDutSik MathieuDutSik marked this pull request as ready for review August 27, 2025 15:48
@MathieuDutSik MathieuDutSik requested review from Twey, deuszx and ma2bd August 27, 2025 15:48
Copy link
Contributor

@ma2bd ma2bd left a comment

Choose a reason for hiding this comment

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

As said above, this should be two PRs so that we can update the SDK 0.15.

@MathieuDutSik MathieuDutSik force-pushed the key_linera_views_derive branch from c96a821 to ddc1527 Compare September 1, 2025 08:00
@MathieuDutSik
Copy link
Contributor Author

As said above, this should be two PRs so that we can update the SDK 0.15.

Created another PR #4452 which does the addition of the prefix __linera_reserved_.

@ma2bd ma2bd self-requested a review September 2, 2025 17:13
} else {
quote! {
let index = #idx_lit;
let base_key = context.base_key().derive_tag_key(linera_views::views::MIN_VIEW_TAG, &index)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make sure that the integer type is (locally) visible when we use derive_tag_key on integers? Those types are part of the protocol and any change would be breaking.

Copy link
Contributor

Choose a reason for hiding this comment

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

(ok it looks like this is maybe the last place where it's ambiguous)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are very right. I added a bound of 65536 on the number of entries.
So, the key is either u8 or u16.

let mut pos = 0;
let index = 0;
let pos_next = pos + RegisterView::<C, usize>::NUM_INIT_KEYS;
let index_byte = 0u8;
Copy link
Contributor

@ma2bd ma2bd Sep 2, 2025

Choose a reason for hiding this comment

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

nit: Here and in other places. We don't really need _byte. (We need 0u8)

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 removed the "_byte" and added "_u8" / "_u16" when adequate.
Now the generated code does not contain the "_byte", but it does contain "0u8" / "0u16".

@MathieuDutSik MathieuDutSik force-pushed the key_linera_views_derive branch from ddc1527 to 96e06cb Compare September 3, 2025 07:03
@MathieuDutSik MathieuDutSik force-pushed the key_linera_views_derive branch from 96e06cb to 71cb6e0 Compare September 3, 2025 07:18
Copy link
Contributor

@ma2bd ma2bd left a comment

Choose a reason for hiding this comment

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

Thanks!

@MathieuDutSik MathieuDutSik added this pull request to the merge queue Sep 4, 2025
Merged via the queue into linera-io:main with commit 7e5b886 Sep 4, 2025
28 checks passed
@MathieuDutSik MathieuDutSik deleted the key_linera_views_derive branch September 4, 2025 06:31
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.

Use smaller keys in views used for views obtained by linera-views-derive

2 participants