Skip to content

Commit

Permalink
Increase headers proof timeout and add more progress logs (#1939)
Browse files Browse the repository at this point in the history
* Increase timeout for pruning proof and add some logs

* Show resolving virtual progress as whole percents
  • Loading branch information
someone235 authored Feb 6, 2022
1 parent 27ba9d0 commit 1cd712a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
16 changes: 13 additions & 3 deletions app/protocol/flows/v4/blockrelay/ibd.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (flow *handleIBDFlow) syncMissingBlockBodies(highHash *externalapi.DomainHa
progressReporter.reportProgress(len(hashesToRequest), highestProcessedDAAScore)
}

return flow.resolveVirtual()
return flow.resolveVirtual(highestProcessedDAAScore)
}

func (flow *handleIBDFlow) banIfBlockIsHeaderOnly(block *externalapi.DomainBlock) error {
Expand All @@ -578,10 +578,20 @@ func (flow *handleIBDFlow) banIfBlockIsHeaderOnly(block *externalapi.DomainBlock
return nil
}

func (flow *handleIBDFlow) resolveVirtual() error {
func (flow *handleIBDFlow) resolveVirtual(estimatedVirtualDAAScoreTarget uint64) error {
virtualDAAScoreStart, err := flow.Domain().Consensus().GetVirtualDAAScore()
if err != nil {
return err
}

for i := 0; ; i++ {
if i%10 == 0 {
log.Infof("Resolving virtual. This may take some time...")
virtualDAAScore, err := flow.Domain().Consensus().GetVirtualDAAScore()
if err != nil {
return err
}
log.Infof("Resolving virtual. Estimated progress: %d%%",
int(float64(virtualDAAScore-virtualDAAScoreStart)/float64(estimatedVirtualDAAScoreTarget-virtualDAAScoreStart)*100))
}
virtualChangeSet, isCompletelyResolved, err := flow.Domain().Consensus().ResolveVirtual()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion app/protocol/flows/v4/blockrelay/ibd_with_headers_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/pkg/errors"
"time"
)

func (flow *handleIBDFlow) ibdWithHeadersProof(highHash *externalapi.DomainHash, highBlockDAAScore uint64) error {
Expand Down Expand Up @@ -87,7 +88,7 @@ func (flow *handleIBDFlow) syncAndValidatePruningPointProof() (*externalapi.Doma
if err != nil {
return nil, err
}
message, err := flow.incomingRoute.DequeueWithTimeout(common.DefaultTimeout)
message, err := flow.incomingRoute.DequeueWithTimeout(10 * time.Minute)
if err != nil {
return nil, err
}
Expand Down
18 changes: 16 additions & 2 deletions domain/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,14 +741,28 @@ func (s *consensus) ValidatePruningPointProof(pruningPointProof *externalapi.Pru
s.lock.Lock()
defer s.lock.Unlock()

return s.pruningProofManager.ValidatePruningPointProof(pruningPointProof)
log.Infof("Validating the pruning point proof")
err := s.pruningProofManager.ValidatePruningPointProof(pruningPointProof)
if err != nil {
return err
}

log.Infof("Done validating the pruning point proof")
return nil
}

func (s *consensus) ApplyPruningPointProof(pruningPointProof *externalapi.PruningPointProof) error {
s.lock.Lock()
defer s.lock.Unlock()

return s.pruningProofManager.ApplyPruningPointProof(pruningPointProof)
log.Infof("Applying the pruning point proof")
err := s.pruningProofManager.ApplyPruningPointProof(pruningPointProof)
if err != nil {
return err
}

log.Infof("Done applying the pruning point proof")
return nil
}

func (s *consensus) BlockDAAWindowHashes(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func (ppm *pruningProofManager) ValidatePruningPointProof(pruningPointProof *ext

selectedTipByLevel := make([]*externalapi.DomainHash, maxLevel+1)
for blockLevel := maxLevel; blockLevel >= 0; blockLevel-- {
log.Infof("Validating level %d from the pruning point proof", blockLevel)
headers := make([]externalapi.BlockHeader, len(pruningPointProof.Headers[blockLevel]))
copy(headers, pruningPointProof.Headers[blockLevel])

Expand Down Expand Up @@ -617,8 +618,12 @@ func (ppm *pruningProofManager) ApplyPruningPointProof(pruningPointProof *extern
defer onEnd()

for blockLevel, headers := range pruningPointProof.Headers {
log.Infof("Applying level %d from the pruning point proof", blockLevel)
var selectedTip *externalapi.DomainHash
for i, header := range headers {
if i%1000 == 0 {
log.Infof("Applying level %d from the pruning point proof - applied %d headers out of %d", blockLevel, i, len(headers))
}
stagingArea := model.NewStagingArea()

blockHash := consensushashing.HeaderHash(header)
Expand Down

0 comments on commit 1cd712a

Please sign in to comment.