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

Remove deprecated position state #763

Merged
merged 6 commits into from
Mar 14, 2024

Conversation

Valentine1898
Copy link
Contributor

@Valentine1898 Valentine1898 commented Mar 14, 2024

This fixes the errors during synchronization that I discovered
telegram-cloud-photo-size-2-5447309195226503859-y

Related to penumbra-zone/penumbra#3883

The issue is that PositionState_PositionStateEnum.CLAIMED was marked as deprecated in proto, yet was removed from the rust codebase. This was causing wasm to error and stop synchronization, which caused us to not save the block completely.

Comment on lines 327 to 332
let positionState = new PositionState({
state: PositionState_PositionStateEnum.WITHDRAWN,
sequence: action.value.sequence,
});
const metadata = getLpNftMetadata(action.value.positionId, positionState);
await this.indexedDb.saveAssetsMetadata(metadata);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default we save the withdrawn lpnft asset with sequence=0, we must additionally save the withdrawn lpnft asset with the sequence we detect

Comment on lines -313 to -326
#[wasm_bindgen]
pub fn get_lpnft_asset(
&mut self,
position_value: JsValue,
position_state_value: JsValue,
) -> Result<JsValue, Error> {
utils::set_panic_hook();

let position: Position = serde_wasm_bindgen::from_value(position_value)?;
let position_state = serde_wasm_bindgen::from_value(position_state_value)?;
let lp_nft = LpNft::new(position.id(), position_state);
let denom = lp_nft.denom();
serde_wasm_bindgen::to_value(&denom)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not part of the view server actually, moved to dex.rs

];

for (const tx of txs) {
for (const { action } of tx.body?.actions ?? []) {
if (action.case === 'positionOpen' && action.value.position) {
for (const state of positionStates) {
const positionState = new PositionState({ state });
const metadata = this.viewServer.getLpNftMetadata(action.value.position, positionState);
const metadata = getLpNftMetadata(computePositionId(action.value.position), state);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now getLpNftMetadata() only requires PositionId, not Position. This makes its use more versatile

@Valentine1898 Valentine1898 marked this pull request as ready for review March 14, 2024 14:51
@Valentine1898 Valentine1898 requested a review from grod220 March 14, 2024 14:58
Copy link
Collaborator

@grod220 grod220 left a comment

Choose a reason for hiding this comment

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

Nice catch! Just one comment.

Comment on lines 19 to 20
const result = get_lpnft_asset(positionId.toJson(), positionState.toJson()) as JsonValue;
return Metadata.fromJsonString(JSON.stringify(result));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have to stringify? Can we not do:

return Metadata.fromJson(result);

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're right, it works without stringify

@Valentine1898 Valentine1898 merged commit 74d9a83 into main Mar 14, 2024
1 check passed
@Valentine1898 Valentine1898 deleted the remove_deprecated_position_state branch March 14, 2024 15:21
@Valentine1898 Valentine1898 self-assigned this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants