mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[DEV-86] Update BlockDAG.initDAGState to load the whole dag
* [DEV-86] remove selectedPrevBlock from initDAGState * [DEV-86] re-implement dagview to be dag compatible * [DEV-86] change comments
This commit is contained in:
parent
460216be65
commit
713b01c69d
@ -115,7 +115,7 @@ func (bs blockSet) hashes() []daghash.Hash {
|
||||
}
|
||||
|
||||
// first returns the first block in this set or nil if this set is empty.
|
||||
func (bs blockSet) first() *blockNode {
|
||||
func (bs blockSet) first() *blockNode { //TODO: (Ori) This is wrong. Done only for compilation. We should probably get rid of this method
|
||||
for _, block := range bs {
|
||||
return block
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"math/rand"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig"
|
||||
"github.com/daglabs/btcd/dagconfig/daghash"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
"github.com/daglabs/btcutil"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// TestHaveBlock tests the HaveBlock API to ensure proper functionality.
|
||||
|
@ -999,10 +999,7 @@ func (dag *BlockDAG) initDAGState() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Determine the parent block node. Since we iterate block headers
|
||||
// in order of height, if the blocks are mostly linear there is a
|
||||
// very good chance the previous header processed is the parent.
|
||||
var parent *blockNode
|
||||
parents := newSet()
|
||||
if lastNode == nil {
|
||||
blockHash := header.BlockHash()
|
||||
if !blockHash.IsEqual(dag.dagParams.GenesisHash) {
|
||||
@ -1010,23 +1007,25 @@ func (dag *BlockDAG) initDAGState() error {
|
||||
"first entry in block index to be genesis block, "+
|
||||
"found %s", blockHash))
|
||||
}
|
||||
} else if *header.SelectedPrevBlock() == lastNode.hash {
|
||||
// Since we iterate block headers in order of height, if the
|
||||
// blocks are mostly linear there is a very good chance the
|
||||
// previous header processed is the parent.
|
||||
parent = lastNode
|
||||
} else {
|
||||
parent = dag.index.LookupNode(header.SelectedPrevBlock())
|
||||
if parent == nil {
|
||||
for _, hash := range header.PrevBlocks {
|
||||
parent := dag.index.LookupNode(&hash)
|
||||
if parent == nil {
|
||||
return AssertError(fmt.Sprintf("initDAGState: Could "+
|
||||
"not find parent %s for block %s", hash, header.BlockHash()))
|
||||
}
|
||||
parents.add(parent)
|
||||
}
|
||||
if len(parents) == 0 {
|
||||
return AssertError(fmt.Sprintf("initDAGState: Could "+
|
||||
"not find parent for block %s", header.BlockHash()))
|
||||
"not find any parent for block %s", header.BlockHash()))
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the block node for the block, connect it,
|
||||
// and add it to the block index.
|
||||
node := &blockNodes[i]
|
||||
initBlockNode(node, header, setFromSlice(parent), dag.dagParams.K) // TODO: (Stas) This is wrong. Modified only to satisfy compilation.
|
||||
initBlockNode(node, header, parents, dag.dagParams.K)
|
||||
node.status = status
|
||||
dag.index.addNode(node)
|
||||
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig/daghash"
|
||||
"github.com/daglabs/btcd/database"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
"github.com/daglabs/btcd/dagconfig/daghash"
|
||||
)
|
||||
|
||||
// TestErrNotInDAG ensures the functions related to errNotInDAG work
|
||||
|
Loading…
x
Reference in New Issue
Block a user