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

Add multiverse RPC proof courier #473

Merged
merged 13 commits into from
Sep 19, 2023
Merged

Add multiverse RPC proof courier #473

merged 13 commits into from
Sep 19, 2023

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Aug 29, 2023

@ffranr ffranr changed the base branch from main to hashmail-courier-session August 29, 2023 17:42
@ffranr ffranr self-assigned this Aug 29, 2023
@ffranr ffranr force-pushed the hashmail-courier-session branch 3 times, most recently from 9d2cd98 to e5ef9bd Compare August 30, 2023 13:50
proof/courier.go Outdated Show resolved Hide resolved
Base automatically changed from hashmail-courier-session to main August 31, 2023 07:29
@ffranr ffranr force-pushed the rpc-courier branch 4 times, most recently from d4462b5 to 6590830 Compare August 31, 2023 21:00
@ffranr
Copy link
Contributor Author

ffranr commented Aug 31, 2023

The integration test changes reveal that the proof insertion into the new universe RPC courier is failing. I think it would still be worth getting a first review on this PR given the team's schedule.

@ffranr ffranr marked this pull request as ready for review August 31, 2023 21:02
@ffranr ffranr requested review from Roasbeef and guggero August 31, 2023 21:03
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Looks very good! I dig how small the diff turned out to be in the end 🎉

itest/tapd_harness.go Outdated Show resolved Hide resolved
itest/universerpc_harness.go Show resolved Hide resolved
proof/courier.go Outdated Show resolved Hide resolved
proof/courier.go Outdated Show resolved Hide resolved
proof/courier.go Show resolved Hide resolved
@ffranr ffranr force-pushed the rpc-courier branch 2 times, most recently from 15d2cfe to ab506bb Compare September 4, 2023 11:48
@ffranr ffranr requested a review from guggero September 4, 2023 11:59
@dstadulis
Copy link
Collaborator

This PR will need to rebase to incorporate #483 (which may be subsumed into a PR @guggero opens)

@ffranr
Copy link
Contributor Author

ffranr commented Sep 4, 2023

Should still be ready for review. Merge is waiting for rebase on #484 to double check that the itest still pass.

@ffranr ffranr changed the base branch from main to proof-courier-ntfn September 4, 2023 21:43
@ffranr
Copy link
Contributor Author

ffranr commented Sep 4, 2023

I think this is failing during proof verification. The proof courier's VM is trying to verify that the asset associated with the proof was correctly split from its input asset. But I don't think that the input asset snapshot is available in the proof.

In a separate part of the codebase we perform proof verification on a complete proof file. And in this way we have the previous asset snapshot at any given transition proof. See https://github.com/ffranr/taproot-assets/blob/main/proof/verifier.go#L433-L450

When inserting a proof into the universe RPC courier we insert every proof in turn starting at the issuance proof. So we could reform the proof file before verification. But this strategy would entail reforming the proof file every time a transition proof is inserted into the courier.

@guggero any thoughts on this?

Base automatically changed from proof-courier-ntfn to main September 5, 2023 17:33
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Took another look, looking really good. The issue with the empty PrevID is the split commitment as suspected. Should be very easy to fix.

taprpc/universerpc/marshal.go Outdated Show resolved Hide resolved
proof/courier.go Show resolved Hide resolved
universe/base.go Outdated Show resolved Hide resolved
universe/base.go Show resolved Hide resolved
universe/base.go Outdated Show resolved Hide resolved
@ffranr ffranr force-pushed the rpc-courier branch 2 times, most recently from fc55f2c to ee04e76 Compare September 6, 2023 15:48
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Great work! Gotta love it when a design plan comes together neatly 😎

Main thing that popped out is to ensure that we're handling cases of merged inputs for an asset properly.

taprpc/marshal.go Show resolved Hide resolved
taprpc/universerpc/marshal.go Outdated Show resolved Hide resolved
// PrevOut is the previous on-chain outpoint of the asset.
// PrevOut is the previous on-chain outpoint of the asset. This outpoint
// is that of the first on-chain input. Outpoints which correspond to
// the other inputs can be found in AdditionalInputs.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is a clarification: this is the outpoint where the asset currently resides (or previously).

}
if !txSpendsPrevOut(&p.AnchorTx, &p.PrevOut) {
return nil, commitment.ErrInvalidTaprootProof // TODO
}

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 existence of PrevOut as a field was/is confusing to me. Because in the context of a multi input spend (merge) we seem to make an arbitrary choice of "the asset" that we're spending, is that correct?

this is the outpoint where the asset currently resides (or previously).

In the context of a multi input spend, what do you mean by "the asset" here?

It's this confusion/uncertainty that motivated me to add more to the comment to make sure I understand what's going on. I think by "the asset" we mean the first input, and that's what I've tried to capture in the comment.

asset/asset.go Outdated Show resolved Hide resolved
proof/courier.go Show resolved Hide resolved
return nil, err
}

revProofs = append(revProofs, transitionProof)
Copy link
Member

Choose a reason for hiding this comment

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

Re this and above, what about the additional inputs? So the case where you have an asset, but it was created by merging 3 change UTXOs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each individual (transition) Proof contains a field called AdditionalInputs []File. The entire proof file for each additional inputs is included in that field. At least, that's my current understanding after speaking with Oli.

We noticed that this is a memory inefficiency within the universe tree (on the courier server side). Each leaf of the universe tree contains a proof and each one of those proofs may contain entire proof files for additional inputs. Those proof files may already exist in the universe as other leaves.

However, from a tapd peer sending/receiving perspective, this setup makes things simpler. I'll add an issue to talk about the potential optimisation here. It will help me get a clear picture of what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue here: #503

proof/courier.go Show resolved Hide resolved
universe/base.go Show resolved Hide resolved
universe/base.go Show resolved Hide resolved
// previous (input) asset. We know that it was already verified
// as it was present in the multiverse/universe archive.
return &proof.AssetSnapshot{
Asset: &prevProof.Asset,
Copy link
Member

Choose a reason for hiding this comment

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

What about the other set of assets in the case of inputs merged to create this new asset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this relies on the additional inputs field, see https://github.com/ffranr/taproot-assets/blob/main/proof/verifier.go#L206-L213

And my answer here: #473 (comment)

@Roasbeef
Copy link
Member

Also I think we can use the HasSplitCommitmentWitness method in most places here?

@ffranr
Copy link
Contributor Author

ffranr commented Sep 13, 2023

Also I think we can use the HasSplitCommitmentWitness method in most places here?

Where are you referring to please @Roasbeef ?

@ffranr ffranr force-pushed the rpc-courier branch 3 times, most recently from ab506bb to 147af79 Compare September 19, 2023 13:39
@Roasbeef Roasbeef requested a review from guggero September 19, 2023 18:30
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐊

Reviewed 6 of 10 files at r7, 7 of 7 files at r8, all commit messages.
Reviewable status: 13 of 17 files reviewed, 34 unresolved discussions (waiting on @ffranr and @guggero)


tapgarden/custodian.go line 391 at r8 (raw file):

			// Sleep to give the sender an opportunity to transfer
			// the proof to the proof courier service.
			time.Sleep(defaultProofRetrievalDelay)

I think let's endeavor to remove this in a follow up PR. IMO the backoff should just handle this, and it can speed up our itests with it gone as well.

@Roasbeef Roasbeef merged commit 90b0ac3 into main Sep 19, 2023
14 checks passed
@guggero guggero deleted the rpc-courier branch September 19, 2023 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants