-
Notifications
You must be signed in to change notification settings - Fork 2
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
Noble sequence search #215
Conversation
0fb93f1
to
70a9988
Compare
Ready for review, but dependent on penumbra-zone/web#1855 |
70a9988
to
f9ee34b
Compare
packages/noble/src/client.ts
Outdated
accountIndex, | ||
); | ||
|
||
console.log({ penumbraAddr: bech32mAddress(penumbraAddr), nobleAddrBech32 }); |
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.
Is this intended?
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.
additional console.log(res);
debug logs?
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.
Will remove 👍
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.
Checks are failing
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.
I think we should wait to merge until there's clarity around the notion of sequence numbers wrapping and what that means in practice. Specifically, if the system exhausts all sequence numbers and begins reusing them, are we certain that user deposits won't be lost or rejected due to an old address being mistakenly reused?
references penumbra-zone/penumbra#4878 (comment)
// Perform binary search to find the earliest unused noble sequence number | ||
export const getNextSequence = async ({ |
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.
Is there a reason the binary search for obtaining a noble sequence number wasn't implemented as a wasm helper?
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.
Because we don't really have any client fetching infra in wasm for making grpc or http requests. We could investigate this, but I'm not sure if it would add value here. Do you disagree?
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.
iirc, I thought core exposes an external rust interface that handles the networking functionality that wasm can consume? maybe I'm wrong, but I don't disagree that it doesn't necessarily add extra value here.
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.
Given the use of tokio, there is not a wasm-compatible request helper I know of.
flagging for external reviewers: the UI component won't be included until the noble one-time deposit addresses land on Noble mainnet in approximately two weeks, followed by sufficient testing. |
package.json
Outdated
}, | ||
"pnpm": { | ||
"overrides": { | ||
"@penumbra-zone/bech32m": "file:///Users/gabe/Desktop/repos/web/packages/bech32m/penumbra-zone-bech32m-8.0.0.tgz", | ||
"@penumbra-zone/client": "file:///Users/gabe/Desktop/repos/web/packages/client/penumbra-zone-client-19.0.0.tgz", | ||
"@penumbra-zone/crypto-web": "file:///Users/gabe/Desktop/repos/web/packages/crypto/penumbra-zone-crypto-web-25.0.0.tgz", | ||
"@penumbra-zone/getters": "file:///Users/gabe/Desktop/repos/web/packages/getters/penumbra-zone-getters-18.0.0.tgz", | ||
"@penumbra-zone/perspective": "file:///Users/gabe/Desktop/repos/web/packages/perspective/penumbra-zone-perspective-32.0.0.tgz", | ||
"@penumbra-zone/protobuf": "file:///Users/gabe/Desktop/repos/web/packages/protobuf/penumbra-zone-protobuf-6.1.0.tgz", | ||
"@penumbra-zone/query": "file:///Users/gabe/Desktop/repos/web/packages/query/penumbra-zone-query-33.0.0.tgz", | ||
"@penumbra-zone/services": "file:///Users/gabe/Desktop/repos/web/packages/services/penumbra-zone-services-36.0.0.tgz", | ||
"@penumbra-zone/storage": "file:///Users/gabe/Desktop/repos/web/packages/storage/penumbra-zone-storage-32.0.0.tgz", | ||
"@penumbra-zone/transport-chrome": "file:///Users/gabe/Desktop/repos/web/packages/transport-chrome/penumbra-zone-transport-chrome-8.0.1.tgz", | ||
"@penumbra-zone/transport-dom": "file:///Users/gabe/Desktop/repos/web/packages/transport-dom/penumbra-zone-transport-dom-7.5.0.tgz", | ||
"@penumbra-zone/types": "file:///Users/gabe/Desktop/repos/web/packages/types/penumbra-zone-types-24.0.0.tgz", | ||
"@penumbra-zone/ui": "file:///Users/gabe/Desktop/repos/web/packages/ui/penumbra-zone-ui-10.0.2.tgz", | ||
"@penumbra-zone/wasm": "file:///Users/gabe/Desktop/repos/web/packages/wasm/penumbra-zone-wasm-29.1.0.tgz", | ||
"@penumbra-zone/keys": "file:///Users/gabe/Desktop/repos/web/packages/keys/penumbra-zone-keys-4.2.1.tgz" | ||
}, | ||
"peerDependencyRules": { | ||
"allowAny": [ | ||
"@penumbra-zone/bech32m", | ||
"@penumbra-zone/client", | ||
"@penumbra-zone/crypto-web", | ||
"@penumbra-zone/getters", | ||
"@penumbra-zone/perspective", | ||
"@penumbra-zone/protobuf", | ||
"@penumbra-zone/query", | ||
"@penumbra-zone/services", | ||
"@penumbra-zone/storage", | ||
"@penumbra-zone/transport-chrome", | ||
"@penumbra-zone/transport-dom", | ||
"@penumbra-zone/types", | ||
"@penumbra-zone/ui", | ||
"@penumbra-zone/wasm", | ||
"@penumbra-zone/bech32m", | ||
"@penumbra-zone/client", | ||
"@penumbra-zone/crypto-web", | ||
"@penumbra-zone/getters", | ||
"@penumbra-zone/keys", | ||
"@penumbra-zone/perspective", | ||
"@penumbra-zone/protobuf", | ||
"@penumbra-zone/query", | ||
"@penumbra-zone/services", | ||
"@penumbra-zone/storage", | ||
"@penumbra-zone/transport-chrome", | ||
"@penumbra-zone/transport-dom", | ||
"@penumbra-zone/types", | ||
"@penumbra-zone/ui", | ||
"@penumbra-zone/wasm" | ||
] | ||
} |
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.
we shouldn't commit these overrides in the package.json
Depositing to an already registered forwarding address will automatically "flush" and get forwarded. No funds will be lost. After all sequence numbers are exhausted, I inserted the logic just to pick one at random to return. I've linked this implementation in the protocol PR, so it's waiting on feedback from someone on that team.
Given there are 2 more PRs to consider this task completed (account selector v2 UI component & service worker polling), I don't think there is any risk in merging and editing later as needed. |
approving optimistically; pending bumping deps and green CI |
} | ||
|
||
const mid = Math.floor((left + right) / 2); | ||
const response = await client.registerAccount({ sequence: mid, accountIndex }); |
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.
thought experiment: what happens if multiple client instances try to register the same sequence number at the same time, duplicate transactions? does this need some kind of atomic registration attempt / locking?
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.
- On no deposited funds, both requests get a
NeedsDeposit
response back - On deposited funds, the first request gets a
Success
and the second aAlreadyRegistered
- On already registered, both get
AlreadyRegistered
That said, don't see a case when multiple clients are in use at the same time
const client = await StargateClient.connect(this.endpoint); | ||
|
||
try { | ||
const res = await client.broadcastTx(tx.toBinary()); |
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.
maybe an exponential backoff in the try / catch to avoid incomplete registrations?
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.
The caller of this client method would be the ones responsible for re-tries I'd say. It's also easy enough for the user to re-request a noble address if an error is thrown. Can revisit this topic though as the UI comes together and we see how that would work.
right: number; | ||
client: NobleClientInterface; | ||
fvk: FullViewingKey; | ||
accountIndex?: number; |
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.
Is the account index validated somewhere before attempting registration?
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.
The account index is only used on our side to generate the proper forwarding address. The function to generate the noble address would throw if it something were wrong with the account index.
f9ee34b
to
efcbd5f
Compare
efcbd5f
to
e581843
Compare
@JasonMHasperhoven given your first approval, going to interpret good to merge given checks are passing now 👍 |
Related to: #206 & penumbra-zone/web#1855 & penumbra-zone/penumbra#4878
Adds a new Noble client and sequence searcher. Next PR will focus on implementing UI to use within Prax account selector.