Skip to content

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

Closed
@Roasbeef

Description

@Roasbeef

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions