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

proof: enable early termination of the universe proof courier #575

Closed
1 task
Roasbeef opened this issue Oct 12, 2023 · 0 comments · Fixed by #730
Closed
1 task

proof: enable early termination of the universe proof courier #575

Roasbeef opened this issue Oct 12, 2023 · 0 comments · Fixed by #730

Comments

@Roasbeef
Copy link
Member

Today we can use the Universe tree and the gRPC/REST API as a source for issuance and transfer proofs. The main loop walks backwards from the transaction is received on chain, using the prev outpoints to look up the next leaf in the Universe trees:

for {
assetID := *loc.AssetID
universeID := unirpc.MarshalUniverseID(assetID[:], nil)
assetKey := unirpc.MarshalAssetKey(
*loc.OutPoint, &loc.ScriptKey,
)
universeKey := unirpc.UniverseKey{
Id: universeID,
LeafKey: assetKey,
}
resp, err := c.client.QueryProof(ctx, &universeKey)
if err != nil {
return nil, err
}
// Decode transition proof from query response.
proofBlob := resp.AssetLeaf.IssuanceProof
var transitionProof Proof
if err := transitionProof.Decode(
bytes.NewReader(proofBlob),
); err != nil {
return nil, err
}
revProofs = append(revProofs, transitionProof)
// Break if we've reached the genesis point (the asset is the
// genesis asset).
asset := transitionProof.Asset
if asset.IsGenesisAsset() {
break
}
// Update locator with principal input to the current outpoint.
prevID, err := transitionProof.Asset.PrimaryPrevID()
if err != nil {
return nil, err
}
// Parse script key public key.
scriptKeyPubKey, err := btcec.ParsePubKey(prevID.ScriptKey[:])
if err != nil {
return nil, fmt.Errorf("failed to parse script key "+
"public key from Proof.PrevID: %w", err)
}
loc.ScriptKey = *scriptKeyPubKey
loc.AssetID = &prevID.ID
loc.OutPoint = &prevID.OutPoint
}

Each time we use the gRPC client to query for the proof. Instead, we should add a step right before that, that attempts to look in the local proof acrhive. This'll allow us to short circuit, as all assets with the same asset ID eventually have a common ancestor. Once we know about this ancestor, then we have the rest of the proof so we can exit early.

Steps To Completion

  • Pass in the proof archive into the UniverseRpcCourier. Use that local archive to query before making a network query to the universe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants