mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
Remove need to parse every header in a blockchain on instantiation (#1704)
* Remove need to parse every header in a blockchain on instantiation * Require height is descending * Fix invariant
This commit is contained in:
parent
b6efa76186
commit
f41039b31b
1 changed files with 7 additions and 6 deletions
|
@ -1,11 +1,10 @@
|
|||
package org.bitcoins.chain.blockchain
|
||||
|
||||
import org.bitcoins.chain.models.BlockHeaderDb
|
||||
import org.bitcoins.core.protocol.blockchain.BlockHeader
|
||||
import org.bitcoins.chain.config.ChainAppConfig
|
||||
import org.bitcoins.chain.ChainVerificationLogger
|
||||
import org.bitcoins.chain.validation.TipUpdateResult
|
||||
import org.bitcoins.chain.validation.TipValidation
|
||||
import org.bitcoins.chain.config.ChainAppConfig
|
||||
import org.bitcoins.chain.models.BlockHeaderDb
|
||||
import org.bitcoins.chain.validation.{TipUpdateResult, TipValidation}
|
||||
import org.bitcoins.core.protocol.blockchain.BlockHeader
|
||||
import org.bitcoins.core.util.SeqWrapper
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
|
||||
|
@ -38,7 +37,9 @@ private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] {
|
|||
protected[blockchain] def compObjectfromHeaders(
|
||||
headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain
|
||||
|
||||
val tip: BlockHeaderDb = headers.maxBy(_.height)
|
||||
val tip: BlockHeaderDb = headers.head
|
||||
|
||||
require(headers.size <= 1 || headers(1).height == tip.height - 1)
|
||||
|
||||
/** The height of the chain */
|
||||
val height: Int = tip.height
|
||||
|
|
Loading…
Add table
Reference in a new issue