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

Rotate parent network key takes 2 steps #1018

Merged
merged 13 commits into from
Aug 28, 2024

Conversation

JesseAbram
Copy link
Member

Closes #968

@JesseAbram JesseAbram marked this pull request as ready for review August 22, 2024 21:38
@JesseAbram JesseAbram requested review from ameba23 and HCastano August 22, 2024 21:38
@JesseAbram JesseAbram added Bump `spec_version` A change which affects the current runtime behaviour Bump `impl_version` A change which only affect the implementation details of the runtime labels Aug 22, 2024
// TODO: should this be a two step process? see # https://github.com/entropyxyz/entropy-core/issues/968
if app_state.kv_store.kv().exists(&network_parent_key).await? {
app_state.kv_store.kv().delete(&network_parent_key).await?
let next_network_parent_key = hex::encode(NEXT_NETWORK_PARENT_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be encoded as hex?

Copy link
Member Author

Choose a reason for hiding this comment

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

the type that the kv takes needs it, but tbh should probably make the const that

Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

👍

crates/threshold-signature-server/src/validator/tests.rs Outdated Show resolved Hide resolved
crates/threshold-signature-server/src/validator/tests.rs Outdated Show resolved Hide resolved
serialize(&aux_info_after_rotate).unwrap()
);

// calling twice doesn't do anything
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@HCastano HCastano changed the title Rotate parent netowrk key takes 2 steps Rotate parent network key takes 2 steps Aug 23, 2024
@HCastano
Copy link
Collaborator

Will take a look at this on Monday

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

So I don't necessarily think that a two phase approach is bad, but I'm also not sure if we should be adding an extra OCW flow just yet.

I'd either want to see us explore other approaches (e.g maybe just having the TSS subscribe to an on-chain event post-confirmation before deleting), or see where this actually ends up failing in practice with the current implementation.

crates/threshold-signature-server/src/validator/api.rs Outdated Show resolved Hide resolved
crates/threshold-signature-server/src/validator/api.rs Outdated Show resolved Hide resolved
Comment on lines +295 to +299
let latest_block_number = rpc
.chain_get_header(None)
.await?
.ok_or_else(|| ValidatorErr::OptionUnwrapError("Failed to get block number".to_string()))?
.number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here it makes sense to check using the finalized header

Copy link
Member Author

Choose a reason for hiding this comment

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

no , I think that would fail as this needs to match when the OCW is fired and that isn't on finalized but on block creation

Comment on lines +103 to +104
/// Key Rotate Message passed to validators
/// parameters. [BlockNumberFor<T>]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// Key Rotate Message passed to validators
/// parameters. [BlockNumberFor<T>]
/// Key Rotate Message passed to validators parameters. [SOMETHING_MORE_DESCRIPTIVE]

Comment on lines +226 to +238
let network_parent_key_heading = hex::encode(NETWORK_PARENT_KEY);
let next_network_parent_key_heading = hex::encode(NEXT_NETWORK_PARENT_KEY);

let new_parent_key = app_state.kv_store.kv().get(&next_network_parent_key_heading).await?;

if app_state.kv_store.kv().exists(&network_parent_key_heading).await? {
app_state.kv_store.kv().delete(&network_parent_key_heading).await?;
};

app_state.kv_store.kv().delete(&next_network_parent_key_heading).await?;

let reservation = app_state.kv_store.kv().reserve_key(network_parent_key_heading).await?;
app_state.kv_store.kv().put(reservation, new_parent_key).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean we should get rid of the is_signer_or_delete_parent_key step in the other flow? We want to wait for this to be called before deleting the parent key

Copy link
Member Author

Choose a reason for hiding this comment

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

mmm yes that is a good point, that should be moved to the second step

@HCastano HCastano removed the Bump `impl_version` A change which only affect the implementation details of the runtime label Aug 26, 2024
@JesseAbram
Copy link
Member Author

So I don't necessarily think that a two phase approach is bad, but I'm also not sure if we should be adding an extra OCW flow just yet.

I'd either want to see us explore other approaches (e.g maybe just having the TSS subscribe to an on-chain event post-confirmation before deleting), or see where this actually ends up failing in practice with the current implementation.

personally Im more in favour of pushing then pulling from the TSS, plus I mean that would break convention here, and it is like we right now always have a flow that the chain pushes to the TSS but randomly we set up one long running listener, I know the ocw code is a little more verbose but I feel pretty strongly about keeping only push methods

@JesseAbram JesseAbram merged commit b5cd90a into master Aug 28, 2024
8 checks passed
@JesseAbram JesseAbram deleted the rotate-parent-network-key-2-steps branch August 28, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bump `spec_version` A change which affects the current runtime behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should deleting and rotating a parent key be a one or two step process
3 participants