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: sync tags as sender #10071

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Nov 20, 2024

This PR enables simple multi-device support by simply syncing the tagging secret indexes when fetching calculating the tag latest tag to use as a sender. The calculated tag uses the largest found index (recent), whether it be from on device, or from remote.

Resolves #9762.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch from c52fc20 to cbfa05a Compare November 20, 2024 15:35
@sklppy88 sklppy88 changed the title init feat: sync tags as sender Nov 20, 2024
@sklppy88 sklppy88 marked this pull request as ready for review November 20, 2024 16:05
@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch 2 times, most recently from 49ac3de to 5435af5 Compare November 20, 2024 18:01
sklppy88

This comment was marked as outdated.

@sklppy88 sklppy88 marked this pull request as draft November 20, 2024 18:04
@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch from 5435af5 to 8b53b70 Compare November 20, 2024 18:35
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

Hm, I'm unsure as to the overall approach. I get wanting to reuse stuff, but this feels quite odd. syncTaggedLogs returns logs and has some side effects (the indices get advanced), but here we're ignoring the retun value, and we're making it have a different set of side effects (since it's the sender indices that move forward, not the recipient ones).

syncTaggedLogs is also fairly complicated for reasons we don't care about here: it deals with multiple senders and recipients (while we just have the one), has a sliding window that moves back (we only need to move forward), etc.

It feels to me like we could just have a way simpler version in which we just read the current index in the database, queries the node for logs and moves the index forward until it doesn't find any logs, with some forward window to be able to jump over skipped indices.

Comment on lines 338 to 377
async #getAppTaggingSecretAsSender(
contractAddress: AztecAddress,
sender: AztecAddress,
recipient: AztecAddress,
): Promise<IndexedTaggingSecret> {
const senderCompleteAddress = await this.getCompleteAddress(sender);
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);

const sharedSecret = computeTaggingSecret(senderCompleteAddress, senderIvsk, recipient);
const appTaggingSecret = poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]);
const [index] = await this.db.getTaggingSecretsIndexesAsSender([appTaggingSecret]);

return new IndexedTaggingSecret(appTaggingSecret, index);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why reimplement all of this instead of calling calculateTaggingSecret?

Copy link
Contributor Author

@sklppy88 sklppy88 Nov 21, 2024

Choose a reason for hiding this comment

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

Just did it as an analog of the other function without realizing calculateTaggingSecret was the actual corresponding function, was a bit confused. Removed this in favor of calculateTaggingSecret that you pointed out.

@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch 4 times, most recently from 2d60a0d to 1778062 Compare November 20, 2024 23:41
@sklppy88
Copy link
Contributor Author

sklppy88 commented Nov 20, 2024

Hm, I'm unsure as to the overall approach. I get wanting to reuse stuff, but this feels quite odd. syncTaggedLogs returns logs and has some side effects (the indices get advanced), but here we're ignoring the retun value, and we're making it have a different set of side effects (since it's the sender indices that move forward, not the recipient ones).

syncTaggedLogs is also fairly complicated for reasons we don't care about here: it deals with multiple senders and recipients (while we just have the one), has a sliding window that moves back (we only need to move forward), etc.

It feels to me like we could just have a way simpler version in which we just read the current index in the database, queries the node for logs and moves the index forward until it doesn't find any logs, with some forward window to be able to jump over skipped indices.

Ah this is a very good point. I had just wanted to maximize reuse of code, like you said. I didn't realize though that the tradeoff for this maximization was this large.

I have made the changes you suggested and made it much simpler. I also did not implement a window though, because I think it would be okay to just use the first found open index for now, as I think we will take another pass at this logic when adapting it for reorgs.

@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch 2 times, most recently from aa56f47 to 621ffab Compare November 21, 2024 03:36
@sklppy88 sklppy88 marked this pull request as ready for review November 21, 2024 03:41
@Thunkar
Copy link
Contributor

Thunkar commented Nov 21, 2024

I would add the e2e-all tag to this one, since it modifies the way notes are sent for the whole repo.

@sklppy88 sklppy88 added the e2e-all CI: Enables this CI job. label Nov 21, 2024
@sklppy88 sklppy88 force-pushed the ek/feat/9762/find-next-tag-as-sender branch from b1c28a4 to 0aa3b96 Compare November 21, 2024 19:18
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

I also did not implement a window though, because I think it would be okay to just use the first found open index for now, as I think we will take another pass at this logic when adapting it for reorgs.

We already support reorgs as of #9913, and #10071 will trigger an index reset. If we choose the first empty index then any reverted transaction will result in the sender and recipient being desynced until the sender sends sufficient notes to cover the gap.

We must use a forward sliding window with the same size as the recipient, and only stop looking for indices once we find a full window with no tags (which is the same thing the recipient does).

sender: AztecAddress,
recipient: AztecAddress,
): Promise<void> {
const contractName = await this.contractDataOracle.getDebugContractName(contractAddress);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this below next to the log statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e-all CI: Enables this CI job.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find next tag as sender
3 participants