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

x/sync / x/merkledb -- add SyncableDB interface #1555

Merged
merged 11 commits into from
May 30, 2023
Prev Previous commit
Next Next commit
add VerifyProof to SyncableDB interface
  • Loading branch information
Dan Laine committed May 30, 2023
commit 8d6581f52ae65b1b939afb5b513b4ab47a533cd4
12 changes: 12 additions & 0 deletions x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ type Config struct {
Tracer trace.Tracer
}

type ProofVerifier interface {
// Returns nil if the trie given in [proof] has root [expectedRootID].
// That is, this is a valid proof that [proof.Key] exists/doesn't exist
// in the trie with root [expectedRootID].
VerifyProof(ctx context.Context, proof *Proof, expectedRootID ids.ID) error
Copy link
Author

@danlaine danlaine May 30, 2023

Choose a reason for hiding this comment

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

VerifyProof isn't actually required by x/sync but it felt weird to have methods for verifying range and change proofs but not regular proofs. I can remove this if people fell this shouldn't be included.

}

type SyncableDB interface {
MerkleRootGetter
ProofGetter
ProofVerifier

// GetChangeProof returns a proof for a subset of the key/value changes in key range
// [start, end] that occurred between [startRootID] and [endRootID].
Expand Down Expand Up @@ -474,6 +482,10 @@ func (db *merkleDB) getProof(ctx context.Context, key []byte) (*Proof, error) {
return view.getProof(ctx, key)
}

func (db *merkleDB) VerifyProof(ctx context.Context, proof *Proof, expectedRootID ids.ID) error {
return proof.Verify(ctx, expectedRootID)
}

// GetRangeProof returns a proof for the key/value pairs in this trie within the range
// [start, end].
func (db *merkleDB) GetRangeProof(
Expand Down
14 changes: 14 additions & 0 deletions x/merkledb/mock_db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.