-
Notifications
You must be signed in to change notification settings - Fork 296
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
Add position to OwnedPositionIdsResponse #4837
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -21,6 +21,7 @@ use url::Url; | |||
|
||||
use penumbra_app::params::AppParameters; | ||||
use penumbra_asset::{asset, asset::Id, asset::Metadata, Value}; | ||||
use penumbra_dex::lp::{BareTradingFunction, TradingFunction}; | ||||
use penumbra_dex::{ | ||||
lp::position::{self, Position, State}, | ||||
TradingPair, | ||||
|
@@ -1097,7 +1098,7 @@ impl Storage { | |||
|
||||
tx.commit()?; | ||||
Ok::<(), anyhow::Error>(()) | ||||
}) | ||||
}) | ||||
.await??; | ||||
|
||||
Ok(()) | ||||
|
@@ -1679,11 +1680,11 @@ impl Storage { | |||
Ok(()) | ||||
} | ||||
|
||||
pub async fn owned_position_ids( | ||||
pub async fn owned_positions( | ||||
&self, | ||||
position_state: Option<State>, | ||||
trading_pair: Option<TradingPair>, | ||||
) -> anyhow::Result<Vec<position::Id>> { | ||||
) -> anyhow::Result<Vec<(position::Id, Position)>> { | ||||
let pool = self.pool.clone(); | ||||
|
||||
let state_clause = match position_state { | ||||
|
@@ -1714,8 +1715,29 @@ impl Storage { | |||
pool.get()? | ||||
.prepare_cached(&q)? | ||||
.query_and_then([], |row| { | ||||
let position_id: Vec<u8> = row.get("position_id")?; | ||||
Ok(position::Id(position_id.as_slice().try_into()?)) | ||||
let position_id_bytes: Vec<u8> = row.get("position_id")?; | ||||
let id = position::Id(position_id_bytes.as_slice().try_into()?); | ||||
|
||||
let position_state_str: String = row.get("position_state")?; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting errors that position_state isn't in the database 🤔 , but it's here: penumbra/crates/view/src/storage/schema.sql Line 129 in b858016
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weirdly, this seems to only fail in smoke tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not just in smoke tests: I can replicate the smoke test failure locally, yes, but I can also run the same cmd locally against a devnet and observe the same failure:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's at least the |
||||
let trading_pair_str: String = row.get("trading_pair")?; | ||||
|
||||
// TODO: DB currently does not save full position. Hence, default backups are used below. | ||||
// We should save the full position in the db to be able to provide the full correct data. | ||||
Comment on lines
+1724
to
+1725
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand if relying on defaults may not be an acceptable change and we will want to update the database schema + sync logic (hard to tell how much work this is though). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking through the requirements here: the existing Position data is recorded in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tricky part here is that there's currently nothing that comes across in sync that would tell you when a position's reserves changed. The three approaches that come to mind are:
this seems like it runs the danger of bloating the compact block with data that is not relevant to nearly every client syncing, so I think it should be excluded from consideration
This is a little bad because we can't ensure that the block height of the position data is perfectly consistent with the sync block height, but I think it might be fine.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Late to the party, but that feels like a very appropriate solution to the problem at hand. We already have penumbra.core.component.dex.v1.QueryService.LiquidityPositionById which exists specifically for this use case: accept position IDs, return full positions. In OP, @grod220 did say
but I lack context on why that might be a hard requirement. To my eye, we already have "the ability for the view service to return position info to a client." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helpful discussion! @zbuc ah, I see what you mean. For point 2, it is not clear to me at what frequency or signal would trigger re-fetching a position's data 🤔 (or how to do this in a privacy-preserving way). @conorsch thanks for sharing that. I did run into this rpc method. However, before I realized the reserves limitation, I thought it would be simple to just serve the position data that is already in the database. I was gravitating toward updating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @grod220 the naive solution would be to fetch all the positions during For privacy's sake, either adding the positions to the compact block or doing something like having the client fetch additional randomly selected positions as "noise" to reduce linkability seems good, but there still seems to be danger of linkability over time based on the union of positions between sets of queries. Additionally there might be other heuristics that could be applied and lead to linkability, for example, "this IP address queries for this list of positions regularly, the majority of which are for trading pair XY, so it seems like this IP address is providing liquidity for trading pair XY". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given there doesn't seem like a practical privacy-preserving solution, it sounds like the roundtrip Thanks everyone! 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hdevalence tagging you for posterity re: the accepted LP linkability risk for the present moment. IMO it is worth investigating what a better privacy preserving design here would look like. |
||||
let position = Position { | ||||
state: State::from_str(&position_state_str)?, | ||||
phi: TradingFunction { | ||||
component: BareTradingFunction { | ||||
fee: 0, | ||||
p: Default::default(), | ||||
q: Default::default(), | ||||
}, | ||||
pair: TradingPair::from_str(&trading_pair_str)?, | ||||
}, | ||||
reserves: Default::default(), | ||||
nonce: [0u8; 32], | ||||
close_on_fill: false, | ||||
}; | ||||
Ok((id, position)) | ||||
})? | ||||
.collect() | ||||
}) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -689,6 +689,7 @@ message OwnedPositionIdsRequest { | |
|
||
message OwnedPositionIdsResponse { | ||
core.component.dex.v1.PositionId position_id = 1; | ||
core.component.dex.v1.Position position = 2; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not convinced that |
||
|
||
// Requests information on an asset by asset id | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: would prefer to keep
position_id
var name for comprehension. Also makes the diff smaller and easier to review.