forked from kaspanet/kaspad
-
Notifications
You must be signed in to change notification settings - Fork 8
/
validate_and_insert_imported_pruning_point.go
47 lines (37 loc) · 1.38 KB
/
validate_and_insert_imported_pruning_point.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package blockprocessor
import (
"github.com/Hoosat-Oy/HTND/domain/consensus/model"
"github.com/Hoosat-Oy/HTND/domain/consensus/model/externalapi"
"github.com/Hoosat-Oy/HTND/domain/consensus/ruleerrors"
"github.com/pkg/errors"
)
func (bp *blockProcessor) validateAndInsertImportedPruningPoint(
stagingArea *model.StagingArea, newPruningPointHash *externalapi.DomainHash) error {
log.Info("Checking that the given pruning point is the expected pruning point")
isValidPruningPoint, err := bp.pruningManager.IsValidPruningPoint(stagingArea, newPruningPointHash)
if err != nil {
return err
}
if !isValidPruningPoint {
return errors.Wrapf(ruleerrors.ErrUnexpectedPruningPoint, "%s is not a valid pruning point",
newPruningPointHash)
}
arePruningPointsInValidChain, err := bp.pruningManager.ArePruningPointsInValidChain(stagingArea)
if err != nil {
return err
}
if !arePruningPointsInValidChain {
return errors.Wrapf(ruleerrors.ErrInvalidPruningPointsChain, "pruning points do not compose a valid "+
"chain to genesis")
}
log.Infof("Updating consensus state manager according to the new pruning point %s", newPruningPointHash)
err = bp.consensusStateManager.ImportPruningPointUTXOSet(stagingArea, newPruningPointHash)
if err != nil {
return err
}
err = bp.updateVirtualAcceptanceDataAfterImportingPruningPoint(stagingArea)
if err != nil {
return err
}
return nil
}