mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
Renamed BlueBlockWindow to just BlockWindow (#1547)
* Renamed BlueBlockWindow to just BlockWindow * Update comment
This commit is contained in:
parent
a7bb1853f9
commit
bee0893660
@ -11,7 +11,7 @@ type DAGTraversalManager interface {
|
|||||||
// from lowHash (exclusive) to highHash (inclusive) over highHash's selected parent chain
|
// from lowHash (exclusive) to highHash (inclusive) over highHash's selected parent chain
|
||||||
SelectedChildIterator(highHash, lowHash *externalapi.DomainHash) (BlockIterator, error)
|
SelectedChildIterator(highHash, lowHash *externalapi.DomainHash) (BlockIterator, error)
|
||||||
Anticone(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error)
|
Anticone(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error)
|
||||||
BlueWindow(highHash *externalapi.DomainHash, windowSize int) ([]*externalapi.DomainHash, error)
|
BlockWindow(highHash *externalapi.DomainHash, windowSize int) ([]*externalapi.DomainHash, error)
|
||||||
NewDownHeap() BlockHeap
|
NewDownHeap() BlockHeap
|
||||||
NewUpHeap() BlockHeap
|
NewUpHeap() BlockHeap
|
||||||
CalculateChainPath(
|
CalculateChainPath(
|
||||||
|
@ -4,11 +4,11 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// blueBlockWindow returns a blockWindow of the given size that contains the
|
// BlockWindow returns a blockWindow of the given size that contains the
|
||||||
// blues in the past of startindNode, the sorting is unspecified.
|
// blocks in the past of startindNode, the sorting is unspecified.
|
||||||
// If the number of blues in the past of startingNode is less then windowSize,
|
// If the number of blocks in the past of startingNode is less then windowSize,
|
||||||
// the window will be padded by genesis blocks to achieve a size of windowSize.
|
// the window will be padded by genesis blocks to achieve a size of windowSize.
|
||||||
func (dtm *dagTraversalManager) BlueWindow(startingBlock *externalapi.DomainHash, windowSize int) ([]*externalapi.DomainHash, error) {
|
func (dtm *dagTraversalManager) BlockWindow(startingBlock *externalapi.DomainHash, windowSize int) ([]*externalapi.DomainHash, error) {
|
||||||
currentHash := startingBlock
|
currentHash := startingBlock
|
||||||
currentGHOSTDAGData, err := dtm.ghostdagDataStore.Get(dtm.databaseContext, currentHash)
|
currentGHOSTDAGData, err := dtm.ghostdagDataStore.Get(dtm.databaseContext, currentHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBlueBlockWindow(t *testing.T) {
|
func TestBlockWindow(t *testing.T) {
|
||||||
tests := map[string][]*struct {
|
tests := map[string][]*struct {
|
||||||
parents []string
|
parents []string
|
||||||
id string //id is a virtual entity that is used only for tests so we can define relations between blocks without knowing their hash
|
id string //id is a virtual entity that is used only for tests so we can define relations between blocks without knowing their hash
|
||||||
@ -311,7 +311,7 @@ func TestBlueBlockWindow(t *testing.T) {
|
|||||||
testutils.ForAllNets(t, true, func(t *testing.T, params *dagconfig.Params) {
|
testutils.ForAllNets(t, true, func(t *testing.T, params *dagconfig.Params) {
|
||||||
params.K = 1
|
params.K = 1
|
||||||
factory := consensus.NewFactory()
|
factory := consensus.NewFactory()
|
||||||
tc, tearDown, err := factory.NewTestConsensus(params, false, "TestBlueBlockWindow")
|
tc, tearDown, err := factory.NewTestConsensus(params, false, "TestBlockWindow")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewTestConsensus: %s", err)
|
t.Fatalf("NewTestConsensus: %s", err)
|
||||||
}
|
}
|
||||||
@ -340,9 +340,9 @@ func TestBlueBlockWindow(t *testing.T) {
|
|||||||
blockByIDMap[blockData.id] = block
|
blockByIDMap[blockData.id] = block
|
||||||
idByBlockMap[*block] = blockData.id
|
idByBlockMap[*block] = blockData.id
|
||||||
|
|
||||||
window, err := tc.DAGTraversalManager().BlueWindow(block, windowSize)
|
window, err := tc.DAGTraversalManager().BlockWindow(block, windowSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("BlueWindow: %s", err)
|
t.Fatalf("BlockWindow: %s", err)
|
||||||
}
|
}
|
||||||
sort.Sort(testutils.NewTestGhostDAGSorter(window, tc, t))
|
sort.Sort(testutils.NewTestGhostDAGSorter(window, tc, t))
|
||||||
if err := checkWindowIDs(window, blockData.expectedWindowWithGenesisPadding, idByBlockMap); err != nil {
|
if err := checkWindowIDs(window, blockData.expectedWindowWithGenesisPadding, idByBlockMap); err != nil {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package difficultymanager
|
package difficultymanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/util/difficulty"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/util/difficulty"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type difficultyBlock struct {
|
type difficultyBlock struct {
|
||||||
@ -27,13 +28,13 @@ func (dm *difficultyManager) getDifficultyBlock(blockHash *externalapi.DomainHas
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// blueBlockWindow returns a blockWindow of the given size that contains the
|
// blockWindow returns a blockWindow of the given size that contains the
|
||||||
// blues in the past of startindNode, the sorting is unspecified.
|
// blocks in the past of startindNode, the sorting is unspecified.
|
||||||
// If the number of blues in the past of startingNode is less then windowSize,
|
// If the number of blocks in the past of startingNode is less then windowSize,
|
||||||
// the window will be padded by genesis blocks to achieve a size of windowSize.
|
// the window will be padded by genesis blocks to achieve a size of windowSize.
|
||||||
func (dm *difficultyManager) blueBlockWindow(startingNode *externalapi.DomainHash, windowSize int) (blockWindow, error) {
|
func (dm *difficultyManager) blockWindow(startingNode *externalapi.DomainHash, windowSize int) (blockWindow, error) {
|
||||||
window := make(blockWindow, 0, windowSize)
|
window := make(blockWindow, 0, windowSize)
|
||||||
windowHashes, err := dm.dagTraversalManager.BlueWindow(startingNode, windowSize)
|
windowHashes, err := dm.dagTraversalManager.BlockWindow(startingNode, windowSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package difficultymanager
|
package difficultymanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/util/difficulty"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/util/difficulty"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
)
|
)
|
||||||
@ -88,7 +89,7 @@ func (dm *difficultyManager) RequiredDifficulty(blockHash *externalapi.DomainHas
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch window of dag.difficultyAdjustmentWindowSize + 1 so we can have dag.difficultyAdjustmentWindowSize block intervals
|
// Fetch window of dag.difficultyAdjustmentWindowSize + 1 so we can have dag.difficultyAdjustmentWindowSize block intervals
|
||||||
targetsWindow, err := dm.blueBlockWindow(bluestParent, dm.difficultyAdjustmentWindowSize+1)
|
targetsWindow, err := dm.blockWindow(bluestParent, dm.difficultyAdjustmentWindowSize+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func (pmtm *pastMedianTimeManager) PastMedianTime(blockHash *externalapi.DomainH
|
|||||||
return header.TimeInMilliseconds(), nil
|
return header.TimeInMilliseconds(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
window, err := pmtm.dagTraversalManager.BlueWindow(selectedParentHash, 2*pmtm.timestampDeviationTolerance-1)
|
window, err := pmtm.dagTraversalManager.BlockWindow(selectedParentHash, 2*pmtm.timestampDeviationTolerance-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user