mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
Calc new pruning point utxo diff through chain acceptance data
This commit is contained in:
parent
c7bd84ef9d
commit
877c46bfec
@ -772,78 +772,112 @@ func (pm *pruningManager) calculateDiffBetweenPreviousAndCurrentPruningPoints(st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
currentPruningGhostDAG, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, currentPruningHash, false)
|
//currentPruningGhostDAG, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, currentPruningHash, false)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
//}
|
||||||
previousPruningGhostDAG, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, previousPruningHash, false)
|
//previousPruningGhostDAG, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, previousPruningHash, false)
|
||||||
|
//if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
|
||||||
|
utxoDiff := utxo.NewMutableUTXODiff()
|
||||||
|
|
||||||
|
iterator, err := pm.dagTraversalManager.SelectedChildIterator(stagingArea, currentPruningHash, previousPruningHash, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer iterator.Close()
|
||||||
|
|
||||||
currentPruningCurrentDiffChild := currentPruningHash
|
for ok := iterator.First(); ok; ok = iterator.Next() {
|
||||||
previousPruningCurrentDiffChild := previousPruningHash
|
child, err := iterator.Get()
|
||||||
// We need to use BlueWork because it's the only thing that's monotonic in the whole DAG
|
if err != nil {
|
||||||
// We use the BlueWork to know which point is currently lower on the DAG so we can keep climbing its children,
|
return nil, err
|
||||||
// that way we keep climbing on the lowest point until they both reach the exact same descendant
|
}
|
||||||
currentPruningCurrentDiffChildBlueWork := currentPruningGhostDAG.BlueWork()
|
chainBlockAcceptanceData, err := pm.acceptanceDataStore.Get(pm.databaseContext, stagingArea, child)
|
||||||
previousPruningCurrentDiffChildBlueWork := previousPruningGhostDAG.BlueWork()
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, blockAcceptanceData := range chainBlockAcceptanceData {
|
||||||
|
blockHeader, err := pm.blockHeaderStore.BlockHeader(pm.databaseContext, stagingArea, blockAcceptanceData.BlockHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, transactionAcceptanceData := range blockAcceptanceData.TransactionAcceptanceData {
|
||||||
|
if transactionAcceptanceData.IsAccepted {
|
||||||
|
err = utxoDiff.AddTransaction(transactionAcceptanceData.Transaction, blockHeader.DAAScore())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return utxoDiff.ToImmutable(), nil
|
||||||
|
|
||||||
var diffHashesFromPrevious []*externalapi.DomainHash
|
//currentPruningCurrentDiffChild := currentPruningHash
|
||||||
var diffHashesFromCurrent []*externalapi.DomainHash
|
//previousPruningCurrentDiffChild := previousPruningHash
|
||||||
for {
|
//// We need to use BlueWork because it's the only thing that's monotonic in the whole DAG
|
||||||
// if currentPruningCurrentDiffChildBlueWork > previousPruningCurrentDiffChildBlueWork
|
//// We use the BlueWork to know which point is currently lower on the DAG so we can keep climbing its children,
|
||||||
if currentPruningCurrentDiffChildBlueWork.Cmp(previousPruningCurrentDiffChildBlueWork) == 1 {
|
//// that way we keep climbing on the lowest point until they both reach the exact same descendant
|
||||||
diffHashesFromPrevious = append(diffHashesFromPrevious, previousPruningCurrentDiffChild)
|
//currentPruningCurrentDiffChildBlueWork := currentPruningGhostDAG.BlueWork()
|
||||||
previousPruningCurrentDiffChild, err = pm.utxoDiffStore.UTXODiffChild(pm.databaseContext, stagingArea, previousPruningCurrentDiffChild)
|
//previousPruningCurrentDiffChildBlueWork := previousPruningGhostDAG.BlueWork()
|
||||||
if err != nil {
|
//
|
||||||
return nil, err
|
//var diffHashesFromPrevious []*externalapi.DomainHash
|
||||||
}
|
//var diffHashesFromCurrent []*externalapi.DomainHash
|
||||||
diffChildGhostDag, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, previousPruningCurrentDiffChild, false)
|
//for {
|
||||||
if err != nil {
|
// // if currentPruningCurrentDiffChildBlueWork > previousPruningCurrentDiffChildBlueWork
|
||||||
return nil, err
|
// if currentPruningCurrentDiffChildBlueWork.Cmp(previousPruningCurrentDiffChildBlueWork) == 1 {
|
||||||
}
|
// diffHashesFromPrevious = append(diffHashesFromPrevious, previousPruningCurrentDiffChild)
|
||||||
previousPruningCurrentDiffChildBlueWork = diffChildGhostDag.BlueWork()
|
// previousPruningCurrentDiffChild, err = pm.utxoDiffStore.UTXODiffChild(pm.databaseContext, stagingArea, previousPruningCurrentDiffChild)
|
||||||
} else if currentPruningCurrentDiffChild.Equal(previousPruningCurrentDiffChild) {
|
// if err != nil {
|
||||||
break
|
// return nil, err
|
||||||
} else {
|
// }
|
||||||
diffHashesFromCurrent = append(diffHashesFromCurrent, currentPruningCurrentDiffChild)
|
// diffChildGhostDag, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, previousPruningCurrentDiffChild, false)
|
||||||
currentPruningCurrentDiffChild, err = pm.utxoDiffStore.UTXODiffChild(pm.databaseContext, stagingArea, currentPruningCurrentDiffChild)
|
// if err != nil {
|
||||||
if err != nil {
|
// return nil, err
|
||||||
return nil, err
|
// }
|
||||||
}
|
// previousPruningCurrentDiffChildBlueWork = diffChildGhostDag.BlueWork()
|
||||||
diffChildGhostDag, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, currentPruningCurrentDiffChild, false)
|
// } else if currentPruningCurrentDiffChild.Equal(previousPruningCurrentDiffChild) {
|
||||||
if err != nil {
|
// break
|
||||||
return nil, err
|
// } else {
|
||||||
}
|
// diffHashesFromCurrent = append(diffHashesFromCurrent, currentPruningCurrentDiffChild)
|
||||||
currentPruningCurrentDiffChildBlueWork = diffChildGhostDag.BlueWork()
|
// currentPruningCurrentDiffChild, err = pm.utxoDiffStore.UTXODiffChild(pm.databaseContext, stagingArea, currentPruningCurrentDiffChild)
|
||||||
}
|
// if err != nil {
|
||||||
}
|
// return nil, err
|
||||||
// The order in which we apply the diffs should be from top to bottom, but we traversed from bottom to top
|
// }
|
||||||
// so we apply the diffs in reverse order.
|
// diffChildGhostDag, err := pm.ghostdagDataStore.Get(pm.databaseContext, stagingArea, currentPruningCurrentDiffChild, false)
|
||||||
oldDiff := utxo.NewMutableUTXODiff()
|
// if err != nil {
|
||||||
for i := len(diffHashesFromPrevious) - 1; i >= 0; i-- {
|
// return nil, err
|
||||||
utxoDiff, err := pm.utxoDiffStore.UTXODiff(pm.databaseContext, stagingArea, diffHashesFromPrevious[i])
|
// }
|
||||||
if err != nil {
|
// currentPruningCurrentDiffChildBlueWork = diffChildGhostDag.BlueWork()
|
||||||
return nil, err
|
// }
|
||||||
}
|
//}
|
||||||
err = oldDiff.WithDiffInPlace(utxoDiff)
|
//// The order in which we apply the diffs should be from top to bottom, but we traversed from bottom to top
|
||||||
if err != nil {
|
//// so we apply the diffs in reverse order.
|
||||||
return nil, err
|
//oldDiff := utxo.NewMutableUTXODiff()
|
||||||
}
|
//for i := len(diffHashesFromPrevious) - 1; i >= 0; i-- {
|
||||||
}
|
// utxoDiff, err := pm.utxoDiffStore.UTXODiff(pm.databaseContext, stagingArea, diffHashesFromPrevious[i])
|
||||||
newDiff := utxo.NewMutableUTXODiff()
|
// if err != nil {
|
||||||
for i := len(diffHashesFromCurrent) - 1; i >= 0; i-- {
|
// return nil, err
|
||||||
utxoDiff, err := pm.utxoDiffStore.UTXODiff(pm.databaseContext, stagingArea, diffHashesFromCurrent[i])
|
// }
|
||||||
if err != nil {
|
// err = oldDiff.WithDiffInPlace(utxoDiff)
|
||||||
return nil, err
|
// if err != nil {
|
||||||
}
|
// return nil, err
|
||||||
err = newDiff.WithDiffInPlace(utxoDiff)
|
// }
|
||||||
if err != nil {
|
//}
|
||||||
return nil, err
|
//newDiff := utxo.NewMutableUTXODiff()
|
||||||
}
|
//for i := len(diffHashesFromCurrent) - 1; i >= 0; i-- {
|
||||||
}
|
// utxoDiff, err := pm.utxoDiffStore.UTXODiff(pm.databaseContext, stagingArea, diffHashesFromCurrent[i])
|
||||||
return oldDiff.DiffFrom(newDiff.ToImmutable())
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// err = newDiff.WithDiffInPlace(utxoDiff)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//return oldDiff.DiffFrom(newDiff.ToImmutable())
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalityScore is the number of finality intervals passed since
|
// finalityScore is the number of finality intervals passed since
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user