-
Notifications
You must be signed in to change notification settings - Fork 120
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
tapfreighter: don't send proofs for tombstones, remove tombstones and burns from commitments #556
Changes from all commits
7719833
1540534
1291077
89082cd
afc4ff7
1f2eaab
23827ff
f12cf24
62e2be4
bd59fa8
b1084e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,26 +78,41 @@ type TapCommitment struct { | |
|
||
// NewTapCommitment creates a new Taproot Asset commitment for the given asset | ||
// commitments capable of computing merkle proofs. | ||
func NewTapCommitment(assets ...*AssetCommitment) (*TapCommitment, error) { | ||
func NewTapCommitment(newCommitments ...*AssetCommitment) (*TapCommitment, | ||
error) { | ||
|
||
maxVersion := asset.V0 | ||
tree := mssmt.NewCompactedTree(mssmt.NewDefaultStore()) | ||
assetCommitments := make(AssetCommitments, len(assets)) | ||
for _, asset := range assets { | ||
asset := asset | ||
assetCommitments := make(AssetCommitments, len(newCommitments)) | ||
for idx := range newCommitments { | ||
assetCommitment := newCommitments[idx] | ||
|
||
if asset.Version > maxVersion { | ||
maxVersion = asset.Version | ||
if assetCommitment.Version > maxVersion { | ||
maxVersion = assetCommitment.Version | ||
} | ||
key := asset.TapCommitmentKey() | ||
leaf := asset.TapCommitmentLeaf() | ||
key := assetCommitment.TapCommitmentKey() | ||
|
||
// Do we already have an asset commitment for this key? If so, | ||
// we need to merge them together. | ||
existingCommitment, ok := assetCommitments[key] | ||
if ok { | ||
err := existingCommitment.Merge(assetCommitment) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
assetCommitment = existingCommitment | ||
} | ||
|
||
leaf := assetCommitment.TapCommitmentLeaf() | ||
|
||
// TODO(bhandras): thread the context through. | ||
_, err := tree.Insert(context.TODO(), key, leaf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
assetCommitments[key] = asset | ||
assetCommitments[key] = assetCommitment | ||
} | ||
|
||
root, err := tree.Root(context.Background()) | ||
|
@@ -365,7 +380,7 @@ func (c *TapCommitment) Proof(tapCommitmentKey, | |
proof.AssetProof = &AssetProof{ | ||
Proof: *assetProof, | ||
Version: assetCommitment.Version, | ||
AssetID: assetCommitment.AssetID, | ||
TapKey: assetCommitment.TapKey, | ||
} | ||
|
||
return a, proof, nil | ||
|
@@ -437,18 +452,14 @@ func (c *TapCommitment) Merge(other *TapCommitment) error { | |
|
||
// Otherwise, we'll need to merge the other asset commitments into | ||
// this commitment. | ||
for key, otherCommitment := range other.assetCommitments { | ||
existingCommitment, ok := c.assetCommitments[key] | ||
for key := range other.assetCommitments { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
otherCommitment := other.assetCommitments[key] | ||
|
||
// If we already have an asset commitment for this key, then we | ||
// merge the two asset trees together. | ||
existingCommitment, ok := c.assetCommitments[key] | ||
if ok { | ||
commitmentCopy, err := otherCommitment.Copy() | ||
if err != nil { | ||
return fmt.Errorf("error copying asset "+ | ||
"commitment: %w", err) | ||
} | ||
err = existingCommitment.Merge(commitmentCopy) | ||
err := existingCommitment.Merge(otherCommitment) | ||
if err != nil { | ||
return fmt.Errorf("error merging asset "+ | ||
"commitment: %w", err) | ||
|
@@ -459,12 +470,7 @@ func (c *TapCommitment) Merge(other *TapCommitment) error { | |
|
||
// With either the new or merged asset commitment obtained, we | ||
// can now (re-)insert it into the Taproot Asset commitment. | ||
existingCommitmentCopy, err := existingCommitment.Copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC we started to do this mainly as a precautionary mechanism. |
||
if err != nil { | ||
return fmt.Errorf("error copying asset commitment: "+ | ||
"%w", err) | ||
} | ||
if err := c.Upsert(existingCommitmentCopy); err != nil { | ||
if err := c.Upsert(existingCommitment); err != nil { | ||
return fmt.Errorf("error upserting other commitment: "+ | ||
"%w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to do this any longer, but does't hurt.