mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
[NOD-126] Removed BlockHeader.SelectedParentHash() method (#274)
* [NOD-126] Removed BlockHeader.SelectedParentHash() method * [NOD-126] Added TODO comments
This commit is contained in:
parent
1362fc45e0
commit
8592ae9641
@ -606,7 +606,8 @@ func (g *testGenerator) saveSpendableCoinbaseOuts() {
|
||||
// reaching the block that has already had the coinbase outputs
|
||||
// collected.
|
||||
var collectBlocks []*wire.MsgBlock
|
||||
for b := g.tip; b != nil; b = g.blocks[*b.Header.SelectedParentHash()] {
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
for b := g.tip; b != nil; b = g.blocks[*b.Header.ParentHashes[0]] {
|
||||
if b.BlockHash() == g.prevCollectedHash {
|
||||
break
|
||||
}
|
||||
@ -1553,9 +1554,11 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b33(9) -> b35(10) -> b39(11) -> b42(12) -> b43(13) -> b53(14)
|
||||
// \-> b54(15)
|
||||
g.nextBlock("b54", outs[15], func(b *wire.MsgBlock) {
|
||||
medianBlock := g.blocks[*b.Header.SelectedParentHash()]
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
medianBlock := g.blocks[*b.Header.ParentHashes[0]]
|
||||
for i := 0; i < medianTimeBlocks/2; i++ {
|
||||
medianBlock = g.blocks[*medianBlock.Header.SelectedParentHash()]
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
medianBlock = g.blocks[*medianBlock.Header.ParentHashes[0]]
|
||||
}
|
||||
b.Header.Timestamp = medianBlock.Header.Timestamp
|
||||
})
|
||||
@ -1567,9 +1570,11 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b33(9) -> b35(10) -> b39(11) -> b42(12) -> b43(13) -> b53(14) -> b55(15)
|
||||
g.setTip("b53")
|
||||
g.nextBlock("b55", outs[15], func(b *wire.MsgBlock) {
|
||||
medianBlock := g.blocks[*b.Header.SelectedParentHash()]
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
medianBlock := g.blocks[*b.Header.ParentHashes[0]]
|
||||
for i := 0; i < medianTimeBlocks/2; i++ {
|
||||
medianBlock = g.blocks[*medianBlock.Header.SelectedParentHash()]
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
medianBlock = g.blocks[*medianBlock.Header.ParentHashes[0]]
|
||||
}
|
||||
medianBlockTime := medianBlock.Header.Timestamp
|
||||
b.Header.Timestamp = medianBlockTime.Add(time.Second)
|
||||
@ -1717,7 +1722,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
g.nextBlock("b61", outs[18], func(b *wire.MsgBlock) {
|
||||
// Duplicate the coinbase of the parent block to force the
|
||||
// condition.
|
||||
parent := g.blocks[*b.Header.SelectedParentHash()]
|
||||
// TODO: (Evgeny) This is wrong. Modified only to satisfy compilation.
|
||||
parent := g.blocks[*b.Header.ParentHashes[0]]
|
||||
b.Transactions[0] = parent.Transactions[0]
|
||||
})
|
||||
rejected(blockdag.ErrOverwriteTx)
|
||||
|
@ -176,14 +176,19 @@ func storeFilter(dbTx database.Tx, block *util.Block, f *gcs.Filter,
|
||||
if header.IsGenesis() {
|
||||
prevHeader = &daghash.ZeroHash
|
||||
} else {
|
||||
ph := header.SelectedParentHash()
|
||||
pfh, err := dbFetchFilterIdxEntry(dbTx, hkey, ph)
|
||||
// TODO(Evgeny): Current implementation of GCS filter inherited from chain
|
||||
// (single parent) and must be ported to DAG (multiple parents)
|
||||
var parentHash *daghash.Hash
|
||||
if header.NumParentBlocks() != 0 {
|
||||
parentHash = header.ParentHashes[0]
|
||||
}
|
||||
prevFilterHashBytes, err := dbFetchFilterIdxEntry(dbTx, hkey, parentHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Construct the new block's filter header, and store it.
|
||||
prevHeader, err = daghash.NewHash(pfh)
|
||||
prevHeader, err = daghash.NewHash(prevFilterHashBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -70,15 +70,6 @@ func (h *BlockHeader) BlockHash() *daghash.Hash {
|
||||
return daghash.DoubleHashP(buf.Bytes())
|
||||
}
|
||||
|
||||
// SelectedParentHash returns the hash of the selected block header.
|
||||
func (h *BlockHeader) SelectedParentHash() *daghash.Hash {
|
||||
if h.NumParentBlocks() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return h.ParentHashes[0]
|
||||
}
|
||||
|
||||
// IsGenesis returns true iff this block is a genesis block
|
||||
func (h *BlockHeader) IsGenesis() bool {
|
||||
return h.NumParentBlocks() == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user