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

feat: #1989: subaccount filter in ownedPositionIds #2006

Merged
merged 9 commits into from
Jan 29, 2025

Conversation

VanishMax
Copy link
Contributor

@VanishMax VanishMax commented Jan 28, 2025

Closes #1989

Relates to prax-wallet/prax#279 (Prax) and penumbra-zone/dex-explorer#329 (DEX)

Changes:

  • protobuf: sync latest changes in penumbra protobufs. subaccount field appears in OwnedPositionIdsResponse buf
  • wasm: change isControlledAddress method to getIndexByAddress. Needed for the block processor to return not just a boolean but the found subaccount
  • types: sync types with updated wasm package
  • storage: add subaccount filter to getOwnedPositionIds method. Database should be populated with subaccounts by the latest changes to the block processor
  • services: add subaccount filter to ownedPositionIds method in ViewService

Note to reviewers. Before running, call pnpm gen:penumbra in packages/protobuf

@erwanor erwanor self-requested a review January 28, 2025 10:44
Copy link
Member

@vacekj vacekj left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@JasonMHasperhoven JasonMHasperhoven left a comment

Choose a reason for hiding this comment

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

Nice!

@TalDerei TalDerei self-requested a review January 28, 2025 15:33
Copy link
Contributor

@TalDerei TalDerei left a comment

Choose a reason for hiding this comment

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

nice work! noted some minor observations

#[wasm_bindgen]
pub fn is_controlled_address(&self, address: &[u8]) -> WasmResult<bool> {
pub fn get_index_by_address(full_viewing_key: &[u8], address: &[u8]) -> WasmResult<JsValue> {
Copy link
Contributor

@TalDerei TalDerei Jan 28, 2025

Choose a reason for hiding this comment

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

question: what's the functional difference between this and the other get_index_by_address method in the keys dir – are these not duplicates?

Copy link
Contributor

Choose a reason for hiding this comment

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

inspecting the wasm/index.d.ts, it seems like the caller getAddressIndexByAddress is using the get_index_by_address method in keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that's right. The block processor uses view server implementation from wasm, so i tried to stick to it without importing methods from other parts of the code

Copy link
Contributor

Choose a reason for hiding this comment

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

block processor calls getIndexByAddress, which internally calls getAddressIndexByAddress view service method, which calls get_index_by_address, which is agnostic to which file the wasm method lives in because it's calling the method from ../wasm/index.js which is a global view of all wasm_bindgen methods.

Copy link
Contributor

@TalDerei TalDerei Jan 28, 2025

Choose a reason for hiding this comment

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

basically hinting at that we should remove get_index_by_address from view_server.rs. I bring this up because we should ensure that all wasm method names are unique and avoid decorating multiple methods with wasm_bindgen that share the same name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, this change wasn't really needed. Removed all WASM code updates in favor of the old version

@@ -496,13 +498,13 @@ describe('IndexedDb', () => {
it('position should be added and their state should change', async () => {
Copy link
Contributor

@TalDerei TalDerei Jan 28, 2025

Choose a reason for hiding this comment

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

suggestion: could we consider adding a few additional tests?

  1. call getOwnedPositionIds with no positions in the database and check it returns an empty array,
  2. check that combining all filters (PositionState, tradingPair, subaccount) works and returns the expected position
  3. check that subaccount filtering mechanism works when multiple subaccounts exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added 1 and 2, number 3 is sufficiently covered by 'should get all position with given subaccount index' test

): AsyncGenerator<PositionId, void>;
addPosition(positionId: PositionId, position: Position): Promise<void>;
updatePosition(positionId: PositionId, newState: PositionState): Promise<void>;
addPosition(positionId: PositionId, position: Position, subaccount?: AddressIndex): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

ACK subaccount in POSITIONS table

Screenshot 2025-01-28 at 7 55 29 PM

@TalDerei
Copy link
Contributor

note: modifying the db schema requires bumping the IDB_VERSION, but extending the storage methods doesn't. Since we're already bumping it in a separate PR, it's fine.

@VanishMax VanishMax merged commit 29dd11a into main Jan 29, 2025
6 checks passed
@VanishMax VanishMax deleted the feat/#1989-subaccount-filter branch January 29, 2025 07:15
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.

view: implement subaccount filtering for ownedPositionIds
4 participants