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

Noble sequence search #215

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Noble sequence search #215

merged 1 commit into from
Oct 16, 2024

Conversation

grod220
Copy link
Contributor

@grod220 grod220 commented Oct 15, 2024

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.

@grod220
Copy link
Contributor Author

grod220 commented Oct 15, 2024

Ready for review, but dependent on penumbra-zone/web#1855

accountIndex,
);

console.log({ penumbraAddr: bech32mAddress(penumbraAddr), nobleAddrBech32 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intended?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove 👍

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.

Checks are failing

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.

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)

Comment on lines +7 to +8
// Perform binary search to find the earliest unused noble sequence number
export const getNextSequence = async ({
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@TalDerei TalDerei Oct 16, 2024

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.

Copy link
Contributor Author

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.

@TalDerei
Copy link
Contributor

TalDerei commented Oct 16, 2024

Next PR will focus on implementing UI to use within Prax account selector.

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
Comment on lines 54 to 105
},
"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"
]
}
Copy link
Contributor

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

@grod220
Copy link
Contributor Author

grod220 commented Oct 16, 2024

clarity around the notion of sequence numbers wrapping

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.

I think we should wait to merge

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.

@TalDerei TalDerei self-requested a review October 16, 2024 14:31
@TalDerei
Copy link
Contributor

TalDerei commented Oct 16, 2024

approving optimistically; pending bumping deps and green CI

}

const mid = Math.floor((left + right) / 2);
const response = await client.registerAccount({ sequence: mid, accountIndex });
Copy link
Contributor

@TalDerei TalDerei Oct 16, 2024

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?

Copy link
Contributor Author

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 a AlreadyRegistered
  • 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());
Copy link
Contributor

@TalDerei TalDerei Oct 16, 2024

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@grod220
Copy link
Contributor Author

grod220 commented Oct 16, 2024

@JasonMHasperhoven given your first approval, going to interpret good to merge given checks are passing now 👍

@grod220 grod220 merged commit 97fa552 into main Oct 16, 2024
3 checks passed
@grod220 grod220 deleted the noble-bin-search branch October 16, 2024 16:29
@grod220 grod220 self-assigned this Oct 16, 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.

3 participants