mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 13:35:17 +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
89bb16a4e2
commit
383aaa7639
1 changed files with 7 additions and 6 deletions
|
@ -1,11 +1,10 @@
|
||||||
package org.bitcoins.chain.blockchain
|
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.ChainVerificationLogger
|
||||||
import org.bitcoins.chain.validation.TipUpdateResult
|
import org.bitcoins.chain.config.ChainAppConfig
|
||||||
import org.bitcoins.chain.validation.TipValidation
|
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.core.util.SeqWrapper
|
||||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||||
|
|
||||||
|
@ -38,7 +37,9 @@ private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] {
|
||||||
protected[blockchain] def compObjectfromHeaders(
|
protected[blockchain] def compObjectfromHeaders(
|
||||||
headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain
|
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 */
|
/** The height of the chain */
|
||||||
val height: Int = tip.height
|
val height: Int = tip.height
|
||||||
|
|
Loading…
Add table
Reference in a new issue