Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
adjust for dcrutil Block changes. (decred#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi authored May 18, 2017
1 parent f54151c commit 3428a40
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 108 deletions.
8 changes: 1 addition & 7 deletions blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,7 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block,
return false, err
}

// The height of this block is one more than the referenced previous
// block.
blockHeight := int64(0)
if prevNode != nil {
blockHeight = prevNode.height + 1
}
block.SetHeight(blockHeight)
blockHeight := block.Height()

// The block must pass all of the validation rules which depend on the
// position of the block within the block chain.
Expand Down
1 change: 0 additions & 1 deletion blockchain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestBlockchainFunctions(t *testing.T) {
if err != nil {
t.Errorf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i))

_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1587,10 +1587,10 @@ func (b *BlockChain) HeaderByHeight(height int64) (*wire.BlockHeader, error) {
// block for the provided hash, deserialize it, retrieve the appropriate height
// from the index, and return a dcrutil.Block with the height set.
func dbFetchBlockByHash(dbTx database.Tx, hash *chainhash.Hash) (*dcrutil.Block, error) {
// First find the height associated with the provided hash in the index.
blockHeight, err := dbFetchHeightByHash(dbTx, hash)
if err != nil {
return nil, err
// Check if the block is in the main chain.
if !dbMainChainHasBlock(dbTx, hash) {
str := fmt.Sprintf("block %s is not in the main chain", hash)
return nil, errNotInMainChain(str)
}

// Load the raw block bytes from the database.
Expand All @@ -1604,7 +1604,6 @@ func dbFetchBlockByHash(dbTx database.Tx, hash *chainhash.Hash) (*dcrutil.Block,
if err != nil {
return nil, err
}
block.SetHeight(blockHeight)

return block, nil
}
Expand All @@ -1630,7 +1629,6 @@ func dbFetchBlockByHeight(dbTx database.Tx, height int64) (*dcrutil.Block, error
if err != nil {
return nil, err
}
block.SetHeight(height)

return block, nil
}
Expand Down
6 changes: 0 additions & 6 deletions blockchain/reorganization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func reorgTestLong(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i))

_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
if err != nil {
Expand Down Expand Up @@ -99,7 +98,6 @@ func reorgTestLong(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i))

_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
if err != nil {
Expand Down Expand Up @@ -196,7 +194,6 @@ func reorgTestShort(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i))

_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
if err != nil {
Expand All @@ -213,7 +210,6 @@ func reorgTestShort(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i + j))

_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
if err != nil {
Expand Down Expand Up @@ -291,7 +287,6 @@ func reorgTestForced(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
bl.SetHeight(int64(i))
if i == finalIdx1 {
oldBestHash = bl.Hash()
}
Expand Down Expand Up @@ -328,7 +323,6 @@ func reorgTestForced(t *testing.T) {
if err != nil {
t.Fatalf("NewBlockFromBytes error: %v", err.Error())
}
forkBl.SetHeight(forkPoint)

_, _, err = chain.ProcessBlock(forkBl, blockchain.BFNone)
if err != nil {
Expand Down
Loading

0 comments on commit 3428a40

Please sign in to comment.