[NOD-126] Removed BlockHeader.SelectedParentHash() method (#274)

* [NOD-126] Removed BlockHeader.SelectedParentHash() method

* [NOD-126] Added TODO comments
This commit is contained in:
Evgeny Khirin 2019-05-01 14:51:16 +03:00 committed by stasatdaglabs
parent 1362fc45e0
commit 8592ae9641
3 changed files with 20 additions and 18 deletions

View File

@ -606,7 +606,8 @@ func (g *testGenerator) saveSpendableCoinbaseOuts() {
// reaching the block that has already had the coinbase outputs // reaching the block that has already had the coinbase outputs
// collected. // collected.
var collectBlocks []*wire.MsgBlock 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 { if b.BlockHash() == g.prevCollectedHash {
break 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) // ... -> b33(9) -> b35(10) -> b39(11) -> b42(12) -> b43(13) -> b53(14)
// \-> b54(15) // \-> b54(15)
g.nextBlock("b54", outs[15], func(b *wire.MsgBlock) { 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++ { 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 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) // ... -> b33(9) -> b35(10) -> b39(11) -> b42(12) -> b43(13) -> b53(14) -> b55(15)
g.setTip("b53") g.setTip("b53")
g.nextBlock("b55", outs[15], func(b *wire.MsgBlock) { 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++ { 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 medianBlockTime := medianBlock.Header.Timestamp
b.Header.Timestamp = medianBlockTime.Add(time.Second) 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) { g.nextBlock("b61", outs[18], func(b *wire.MsgBlock) {
// Duplicate the coinbase of the parent block to force the // Duplicate the coinbase of the parent block to force the
// condition. // 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] b.Transactions[0] = parent.Transactions[0]
}) })
rejected(blockdag.ErrOverwriteTx) rejected(blockdag.ErrOverwriteTx)

View File

@ -176,14 +176,19 @@ func storeFilter(dbTx database.Tx, block *util.Block, f *gcs.Filter,
if header.IsGenesis() { if header.IsGenesis() {
prevHeader = &daghash.ZeroHash prevHeader = &daghash.ZeroHash
} else { } else {
ph := header.SelectedParentHash() // TODO(Evgeny): Current implementation of GCS filter inherited from chain
pfh, err := dbFetchFilterIdxEntry(dbTx, hkey, ph) // (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 { if err != nil {
return err return err
} }
// Construct the new block's filter header, and store it. // Construct the new block's filter header, and store it.
prevHeader, err = daghash.NewHash(pfh) prevHeader, err = daghash.NewHash(prevFilterHashBytes)
if err != nil { if err != nil {
return err return err
} }

View File

@ -70,15 +70,6 @@ func (h *BlockHeader) BlockHash() *daghash.Hash {
return daghash.DoubleHashP(buf.Bytes()) 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 // IsGenesis returns true iff this block is a genesis block
func (h *BlockHeader) IsGenesis() bool { func (h *BlockHeader) IsGenesis() bool {
return h.NumParentBlocks() == 0 return h.NumParentBlocks() == 0