Skip to content

Commit

Permalink
indexers: get rid of multiblockproof related code from proof stats
Browse files Browse the repository at this point in the history
  • Loading branch information
kcalvinalvin committed Oct 22, 2024
1 parent 900d953 commit 6c486ae
Showing 1 changed file with 11 additions and 163 deletions.
174 changes: 11 additions & 163 deletions blockchain/indexers/utreexoproofstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,23 @@ import (
"io"
"math"

"github.com/utreexo/utreexod/chaincfg/chainhash"
"github.com/utreexo/utreexod/wire"
)

// proofStatsSize has 19 elements that are each 8 bytes big.
const proofStatsSize int = 8 * 19
// proofStatsSize has 10 elements that are each 8 bytes big.
const proofStatsSize int = 8 * 10

// proofStats are the relevant proof statistics to check how big each proofs are.
type proofStats struct {
// The height of the chain for the below stats.
BlockHeight uint64

// The overhead of the multi interval proof.
MultiBlockProofOverheadSum float64
MultiBlockProofCount uint64

// The overhead of the single interval proof.
BlockProofOverheadSum float64
BlockProofCount uint64

// Total deletions vs the proven deletions by the multi-block proof.
TotalDels uint64
TotalProvenDels uint64
// Total deletions.
TotalDels uint64

// Size of all the leaf datas.
LdSize uint64
Expand All @@ -45,18 +39,6 @@ type proofStats struct {
// Size of all the proofs in the batchproofs.
ProofSize uint64
ProofCount uint64

// Size of the multi-block targets.
MbTgSize uint64
MbTgCount uint64

// Size of the multi-block proofs.
MbProofSize uint64
MbProofCount uint64

// Size of the leafhashes for the multi-block proofs.
MbHashSize uint64
MbHashCount uint64
}

// UpdateTotalDelCount updates the deletion count in the proof stats.
Expand Down Expand Up @@ -86,40 +68,15 @@ func (ps *proofStats) UpdateUDStats(excludeAccProof bool, ud *wire.UData) {
ps.BlockProofOverheadSum += overhead
}

// UpdateMultiUDStats updates the multi-block utreexo data statistics.
func (ps *proofStats) UpdateMultiUDStats(delCount int, multiUd *wire.UData) {
// Update target size.
ps.MbTgSize += uint64(wire.BatchProofSerializeTargetSize(&multiUd.AccProof))
ps.MbTgCount += uint64(len(multiUd.AccProof.Targets))

// Update proof size.
ps.MbProofSize += uint64(wire.BatchProofSerializeAccProofSize(&multiUd.AccProof))
ps.MbProofCount += uint64(len(multiUd.AccProof.Proof))

// Update multi-block proof overhead.
overhead := calcProofOverhead(multiUd)
ps.MultiBlockProofCount++
ps.MultiBlockProofOverheadSum += overhead

// Update the multi-block proof hash size.
ps.MbHashSize += uint64(delCount * chainhash.HashSize)
ps.MbHashCount += uint64(delCount)

// Update proven dels by the multi-block proofs.
ps.TotalProvenDels += uint64(delCount)
}

// LogProofStats outputs a log of the proof statistics.
func (ps *proofStats) LogProofStats() {
log.Infof("height %d: totalProvenPercentage %f, totalDels %d, totalProvenDels %d, ldSize %d, ldCount %d, tgSize %d, tgCount %d, proofSize %d, proofCount %d "+
"mbTgSize %d, mbTgCount %d, mbProofSize %d, mbProofCount %d, mbHashSize %d, mbHashCount %d",
ps.BlockHeight, float64(ps.TotalProvenDels)/float64(ps.TotalDels), ps.TotalDels, ps.TotalProvenDels, ps.LdSize, ps.LdCount, ps.TgSize, ps.TgCount,
ps.ProofSize, ps.ProofCount, ps.MbTgSize, ps.MbTgCount,
ps.MbProofSize, ps.MbProofCount, ps.MbHashSize, ps.MbHashCount)

log.Infof("height %d, average-blockoverhead %f, average-multiblockoverhead %f, blockoverhead-sum %f, blockcount %d, mboverhead-sum %f, mbCount %d",
ps.BlockHeight, ps.BlockProofOverheadSum/float64(ps.BlockProofCount), ps.MultiBlockProofOverheadSum/float64(ps.MultiBlockProofCount),
ps.BlockProofOverheadSum, ps.BlockProofCount, ps.MultiBlockProofOverheadSum, ps.MultiBlockProofCount)
log.Infof("height %d: totalDels %d, ldSize %d, ldCount %d, tgSize %d, tgCount %d, proofSize %d, proofCount %d",
ps.BlockHeight, ps.TotalDels, ps.LdSize, ps.LdCount, ps.TgSize, ps.TgCount,
ps.ProofSize, ps.ProofCount)

log.Infof("height %d, average-blockoverhead %f, blockoverhead-sum %f, blockcount %d",
ps.BlockHeight, ps.BlockProofOverheadSum/float64(ps.BlockProofCount),
ps.BlockProofOverheadSum, ps.BlockProofCount)
}

// Serialize serializes the proof statistics into the writer.
Expand All @@ -133,18 +90,6 @@ func (ps *proofStats) Serialize(w io.Writer) error {
return err
}

binary.BigEndian.PutUint64(buf[:], math.Float64bits(ps.MultiBlockProofOverheadSum))
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MultiBlockProofCount)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], math.Float64bits(ps.BlockProofOverheadSum))
_, err = w.Write(buf[:])
if err != nil {
Expand All @@ -163,12 +108,6 @@ func (ps *proofStats) Serialize(w io.Writer) error {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.TotalProvenDels)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.LdSize)
_, err = w.Write(buf[:])
if err != nil {
Expand Down Expand Up @@ -205,42 +144,6 @@ func (ps *proofStats) Serialize(w io.Writer) error {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbTgSize)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbTgCount)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbProofSize)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbProofCount)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbHashSize)
_, err = w.Write(buf[:])
if err != nil {
return err
}

binary.BigEndian.PutUint64(buf[:], ps.MbHashCount)
_, err = w.Write(buf[:])
if err != nil {
return err
}

return nil
}

Expand All @@ -255,19 +158,6 @@ func (ps *proofStats) Deserialize(r io.Reader) error {
}
ps.BlockHeight = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
res = binary.BigEndian.Uint64(buf[:])
ps.MultiBlockProofOverheadSum = math.Float64frombits(res)

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MultiBlockProofCount = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
Expand All @@ -287,12 +177,6 @@ func (ps *proofStats) Deserialize(r io.Reader) error {
}
ps.TotalDels = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.TotalProvenDels = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
Expand Down Expand Up @@ -329,42 +213,6 @@ func (ps *proofStats) Deserialize(r io.Reader) error {
}
ps.ProofCount = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbTgSize = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbTgCount = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbProofSize = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbProofCount = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbHashSize = binary.BigEndian.Uint64(buf[:])

_, err = r.Read(buf[:])
if err != nil {
return err
}
ps.MbHashCount = binary.BigEndian.Uint64(buf[:])

return nil
}

Expand Down

0 comments on commit 6c486ae

Please sign in to comment.