Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 71 additions & 80 deletions ffi/firewood.h

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

37 changes: 31 additions & 6 deletions ffi/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type VerifiedChangeProof struct {
// ProposedChangeProof contains a proposal for the ChangeProof.
type ProposedChangeProof struct {
handle *C.ProposedChangeProofContext
db *Database
}

// NextKeyRange represents a range of keys to fetch from the database. The start
Expand Down Expand Up @@ -140,9 +141,9 @@ func (p *RangeProof) Verify(
return getErrorFromVoidResult(C.fwd_range_proof_verify(args))
}

// VerifyChangeProof verifies the provided change [proof] proves the changes
// between [startRoot] and [endRoot] for keys in the range [startKey, endKey]. If
// the proof is valid, a proposal containing the changes is prepared. The
// VerifyRangeProof verifies the provided range range [proof] proves the values
// in the range [startKey, endKey] are included in the tree with the given
// [rootHash]. If the proof is valid, a proposal containing the values is prepared. The
// call to [*Database.VerifyAndCommitRangeProof] will skip verification and commit the
// prepared proposal.
//
Expand Down Expand Up @@ -390,9 +391,31 @@ func (db *Database) ProposeChangeProof(
args := C.ProposedChangeProofArgs{
proof: proof.handle,
}
return getProposedChangeProofFromProposedChangeProofResult(C.fwd_db_propose_change_proof(db.handle, args))
return getProposedChangeProofFromProposedChangeProofResult(db, C.fwd_db_propose_change_proof(db.handle, args))
}

func (proof *ProposedChangeProof) CommitChangeProof() (Hash, error) {
proof.db.handleLock.RLock()
defer proof.db.handleLock.RUnlock()
if proof.db.handle == nil {
return EmptyRoot, errDBClosed
}

var pinner runtime.Pinner
defer pinner.Unpin()

args := C.CommittedChangeProofArgs{
proof: proof.handle,
}

return getHashKeyFromHashResult(C.fwd_db_commit_change_proof(args))
}

func (proof *ProposedChangeProof) FindNextKey() (*NextKeyRange, error) {
return getNextKeyRangeFromNextKeyRangeResult(C.fwd_change_proof_find_next_key_proposed(proof.handle))
}

/*
// VerifyAndCommitChangeProof verifies the provided change [proof] proves the changes
// between [startRoot] and [endRoot] for keys in the range [startKey, endKey]. If
// the proof is valid, it is committed to the database and the new root hash is
Expand Down Expand Up @@ -425,6 +448,7 @@ func (db *Database) VerifyAndCommitChangeProof(
return getHashKeyFromHashResult(C.fwd_db_verify_and_commit_change_proof(db.handle, args))
}


// FindNextKey returns the next key range to fetch for this proof, if any. If the
// proof has been fully processed, nil is returned. If an error occurs while
// determining the next key range, that error is returned.
Expand All @@ -434,6 +458,7 @@ func (db *Database) VerifyAndCommitChangeProof(
func (p *ChangeProof) FindNextKey() (*NextKeyRange, error) {
return getNextKeyRangeFromNextKeyRangeResult(C.fwd_change_proof_find_next_key(p.handle))
}
*/

// CodeHashes returns an iterator for the code hashes contained in the account nodes
// of this proof. This list may contain duplicates and is not guaranteed to be in any particular order.
Expand Down Expand Up @@ -664,13 +689,13 @@ func getVerifiedChangeProofFromVerifiedChangeProofResult(result C.VerifiedChange
}
}

func getProposedChangeProofFromProposedChangeProofResult(result C.ProposedChangeProofResult) (*ProposedChangeProof, error) {
func getProposedChangeProofFromProposedChangeProofResult(db *Database, result C.ProposedChangeProofResult) (*ProposedChangeProof, error) {
switch result.tag {
case C.ProposedChangeProofResult_NullHandlePointer:
return nil, errDBClosed
case C.ProposedChangeProofResult_Ok:
ptr := *(**C.ProposedChangeProofContext)(unsafe.Pointer(&result.anon0))
return &ProposedChangeProof{handle: ptr}, nil
return &ProposedChangeProof{handle: ptr, db: db}, nil
case C.ProposedChangeProofResult_Err:
err := newOwnedBytes(*(*C.OwnedBytes)(unsafe.Pointer(&result.anon0))).intoError()
return nil, err
Expand Down
Loading