Skip to content

Commit

Permalink
blockchain: get rid of proofInterval from UtreexoViewpoint
Browse files Browse the repository at this point in the history
The proof interval was used for multiblock proofs which was a method for
caching. Removing in favor of a client-side proof caching method.
  • Loading branch information
kcalvinalvin committed Oct 22, 2024
1 parent 4c740e4 commit 282401c
Showing 1 changed file with 16 additions and 51 deletions.
67 changes: 16 additions & 51 deletions blockchain/utreexoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (

// UtreexoViewpoint is the compact state of the chainstate using the utreexo accumulator
type UtreexoViewpoint struct {
// proofInterval is the interval of block in which to receive the
// accumulator proofs. Only relevant when in multiblock proof mode.
proofInterval int32

// accumulator is the bare-minimum accumulator for the utxo set.
// It only holds the root hashes and the number of elements in the
// accumulator.
Expand Down Expand Up @@ -109,12 +105,6 @@ func (uview *UtreexoViewpoint) VerifyUData(block *btcutil.Block,
}
}

// TODO we should be verifying here but aren't as the accumulator.Verify
// function expects a complete proof.
if uview.proofInterval != 1 {
return nil
}

return uview.accumulator.Verify(dels, ud.AccProof, false)
}

Expand Down Expand Up @@ -142,33 +132,23 @@ func (uview *UtreexoViewpoint) Modify(ud *wire.UData,
addHashes[i] = add.Hash
}

var err error
// We have to do this in order to generate the update data for the wallet.
// TODO: get rid of this once the pollard can generate the update data.
s := uview.accumulator.GetStump()
var updateData utreexo.UpdateData
if uview.proofInterval == 1 {
err = uview.accumulator.Ingest(dels, ud.AccProof)
if err != nil {
return nil, err
}

// We have to do this in order to generate the update data for the wallet.
// TODO: get rid of this once the pollard can generate the update data.
s := uview.accumulator.GetStump()
updateData, err = s.Update(dels, addHashes, ud.AccProof)
if err != nil {
return nil, err
}
updateData, err := s.Update(dels, addHashes, ud.AccProof)
if err != nil {
return nil, err
}

err = uview.accumulator.Modify(adds, dels, ud.AccProof)
if err != nil {
return nil, err
}
} else {
// TODO we should be verifying here but aren't as the accumulator.Verify
// function expects a complete proof.
err = uview.accumulator.Modify(adds, dels, ud.AccProof)
if err != nil {
return nil, err
}
// Ingest and modify the accumulator.
err = uview.accumulator.Ingest(dels, ud.AccProof)
if err != nil {
return nil, err
}
err = uview.accumulator.Modify(adds, dels, ud.AccProof)
if err != nil {
return nil, err
}

return &updateData, nil
Expand Down Expand Up @@ -833,17 +813,6 @@ func (uview *UtreexoViewpoint) compareRoots(compRoot []utreexo.Hash) bool {
return true
}

// SetProofInterval sets the interval of the utreexo proofs to be received by the node.
// Ex: interval of 10 means that you receive a utreexo proof every 10 blocks.
func (uview *UtreexoViewpoint) SetProofInterval(proofInterval int32) {
uview.proofInterval = proofInterval
}

// GetProofInterval returns the proof interval of the current utreexo viewpoint.
func (uview *UtreexoViewpoint) GetProofInterval() int32 {
return uview.proofInterval
}

// PruneAll deletes all the cached leaves in the utreexo viewpoint, leaving only the
// roots of the accumulator.
func (uview *UtreexoViewpoint) PruneAll() {
Expand All @@ -854,18 +823,14 @@ func (uview *UtreexoViewpoint) PruneAll() {
// NewUtreexoViewpoint returns an empty UtreexoViewpoint
func NewUtreexoViewpoint() *UtreexoViewpoint {
return &UtreexoViewpoint{
// Use 1 as a default value.
proofInterval: 1,
accumulator: utreexo.NewMapPollard(false),
accumulator: utreexo.NewMapPollard(false),
}
}

// SetUtreexoStateFromAssumePoint sets an initialized utreexoviewpoint from the
// assumedUtreexoPoint.
func (b *BlockChain) SetUtreexoStateFromAssumePoint() {
b.utreexoView = &UtreexoViewpoint{
// Use 1 as a default value.
proofInterval: 1,
accumulator: utreexo.NewMapPollardFromRoots(
b.assumeUtreexoPoint.Roots, b.assumeUtreexoPoint.NumLeaves, false),
}
Expand Down

0 comments on commit 282401c

Please sign in to comment.