-
Notifications
You must be signed in to change notification settings - Fork 4
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(query): update block processor to include subaccounts into LPs #279
Changes from 1 commit
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
import { processActionDutchAuctionSchedule } from './helpers/process-action-dutch-auction-schedule'; | ||
import { processActionDutchAuctionWithdraw } from './helpers/process-action-dutch-auction-withdraw'; | ||
import { RootQuerier } from './root-querier'; | ||
import { IdentityKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb'; | ||
import { AddressIndex, IdentityKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb'; | ||
import { getDelegationTokenMetadata } from '@penumbra-zone/wasm/stake'; | ||
import { toPlainMessage } from '@bufbuild/protobuf'; | ||
import { getAssetIdFromGasPrices } from '@penumbra-zone/getters/compact-block'; | ||
|
@@ -317,7 +317,7 @@ | |
spentNullifiers, | ||
recordsByCommitment, | ||
blockTx, | ||
addr => this.viewServer.isControlledAddress(addr), | ||
addr => this.viewServer.getIndexByAddress(addr), | ||
Check failure on line 320 in packages/query/src/block-processor.ts
|
||
); | ||
|
||
// this simply stores the new records with 'rehydrated' sources to idb | ||
|
@@ -494,7 +494,7 @@ | |
|
||
// Nullifier is published in network when a note is spent or swap is claimed. | ||
private async resolveNullifiers(nullifiers: Nullifier[], height: bigint) { | ||
const spentNullifiers = new Set<Nullifier>(); | ||
const spentNullifiers = new Map<Nullifier, SpendableNoteRecord | SwapRecord>(); | ||
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. Before we merge, I want to circle back to this and a few other things with the data modeling. What's the lifetime of the spent nullifier map? How big is a SNR? An OOM seems somewhat unlikely but I don't totally understand the approach yet. 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. this is a good flag, still thinking through the proposed data structure. the SNRs are ~700 bytes. 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. OK this seems totally fine, round it to 1KB, that's 1M SNRs. sgtm 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. after reviewing the code, stepping through the code, prior to calling
up until this point in the block processing, we know a few things:
then, if we found a commitment or nullifier relevant to the user in that block, we request all the transactions for that block height from the full node, and filter the specific transaction relevant to the user. This is where the original After identifying the transaction, we have a special method called processTransactions that will identify the LP position relevant to the user and save it alongside the subaccount. anyways, if we didn't originally have this map, once we knew which nullifier is associated with the user, we'd need to perform another db query to fetch the relevant SNR from the table, and subsequently derive the AddressIndex. 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. thanks for this great explanation, @TalDerei! This is exactly what the PR does in the smallest details |
||
const readOperations = []; | ||
const writeOperations = []; | ||
|
||
|
@@ -518,8 +518,6 @@ | |
continue; | ||
} | ||
|
||
spentNullifiers.add(nullifier); | ||
|
||
if (record instanceof SpendableNoteRecord) { | ||
record.heightSpent = height; | ||
const writePromise = this.indexedDb.saveSpendableNote({ | ||
|
@@ -535,6 +533,8 @@ | |
}); | ||
writeOperations.push(writePromise); | ||
} | ||
|
||
spentNullifiers.set(nullifier, record); | ||
} | ||
|
||
// Await all writes in parallel | ||
|
@@ -548,9 +548,12 @@ | |
* such as metadata, liquidity positions, etc. | ||
*/ | ||
private async processTransactions(txs: RelevantTx[]) { | ||
for (const { data } of txs) { | ||
for (const { data, subaccount } of txs) { | ||
for (const { action } of data.body?.actions ?? []) { | ||
await Promise.all([this.identifyAuctionNfts(action), this.identifyLpNftPositions(action)]); | ||
await Promise.all([ | ||
this.identifyAuctionNfts(action), | ||
this.identifyLpNftPositions(action, subaccount), | ||
]); | ||
} | ||
} | ||
} | ||
|
@@ -582,7 +585,7 @@ | |
* - generate all possible position state metadata | ||
* - update idb | ||
*/ | ||
private async identifyLpNftPositions(action: Action['action']) { | ||
private async identifyLpNftPositions(action: Action['action'], subaccount?: AddressIndex) { | ||
if (action.case === 'positionOpen' && action.value.position) { | ||
for (const state of POSITION_STATES) { | ||
const metadata = getLpNftMetadata(computePositionId(action.value.position), state); | ||
|
@@ -597,12 +600,14 @@ | |
await this.indexedDb.addPosition( | ||
computePositionId(action.value.position), | ||
action.value.position, | ||
subaccount, | ||
); | ||
} | ||
if (action.case === 'positionClose' && action.value.positionId) { | ||
await this.indexedDb.updatePosition( | ||
action.value.positionId, | ||
new PositionState({ state: PositionState_PositionStateEnum.CLOSED }), | ||
subaccount, | ||
); | ||
} | ||
if (action.case === 'positionWithdraw' && action.value.positionId) { | ||
|
@@ -618,7 +623,7 @@ | |
penumbraAssetId: getAssetId(metadata), | ||
}); | ||
|
||
await this.indexedDb.updatePosition(action.value.positionId, positionState); | ||
await this.indexedDb.updatePosition(action.value.positionId, positionState, subaccount); | ||
} | ||
} | ||
|
||
|
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.
suggestion: should we actually remove this? It's used soley in
getRelevantIbcRelay
to associate IBC actions with their respective sub-accounts indices, but if the objective of this PR is only handling LP positions, it might be unnecessary. We don't have a use case for filtering IBC actions by account indexes yet. thoughts?that said, we can still keep the
getIndexByAddress
modifications in the view service method already implemented in penumbra-zone/web#2006.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.
put back the
isControlledAddress
method. Truly, no need to know AddressIndex for IBC relay actions for now