Skip to content

Commit

Permalink
BuildPruningPointProof
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Sep 15, 2021
1 parent 0d8980b commit a183a94
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 32 deletions.
22 changes: 21 additions & 1 deletion app/protocol/flows/blockrelay/ibd_with_headers_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -112,7 +113,16 @@ func (flow *handleRelayInvsFlow) downloadHeadersAndPruningUTXOSet(highHash *exte
return err
}

log.Debugf("Blocks downloaded from peer %s", flow.peer)
log.Debugf("Headers downloaded from peer %s", flow.peer)

highHashInfo, err := flow.Domain().StagingConsensus().GetBlockInfo(highHash)
if err != nil {
return err
}

if !highHashInfo.Exists {
return protocolerrors.Errorf(true, "the triggering IBD block was not send")
}

log.Debugf("Syncing the current pruning point UTXO set")
syncedPruningPointUTXOSetSuccessfully, err := flow.syncPruningPointUTXOSet(flow.Domain().StagingConsensus(), pruningPoint)
Expand Down Expand Up @@ -238,6 +248,16 @@ func (flow *handleRelayInvsFlow) validateAndInsertPruningPoints() error {
return protocolerrors.Errorf(false, "pruning points are violating finality")
}

currentPruningPoint, err := flow.Domain().Consensus().PruningPoint()
if err != nil {
return err
}

proposedPruningPoint := consensushashing.HeaderHash(headers[len(headers)-1])
if currentPruningPoint.Equal(proposedPruningPoint) {
return protocolerrors.Errorf(true, "the proposed pruning point is the same as the current pruning point")
}

err = flow.Domain().StagingConsensus().ImportPruningPoints(headers)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions domain/consensus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ func (f *factory) NewConsensus(config *Config, db infrastructuredatabase.Databas
pruningManager := pruningmanager.New(
dbManager,
dagTraversalManager,
dagTopologyManager,
dagTopologyManagers,
consensusStateManager,
finalityManager,
ghostdagManagers,

consensusStateStore,
ghostdagDataStore,
ghostdagDataStores,
pruningStore,
blockStatusStore,
headersSelectedTipStore,
Expand Down
Loading

0 comments on commit a183a94

Please sign in to comment.