Change 'height' types from Long -> Int. Int.MaxValue is 2147483647, which is an order of magnitude more than current block heights on mainnet/testnet bitcoin (#685)

This commit is contained in:
Chris Stewart 2019-08-09 09:22:00 -05:00 committed by GitHub
parent 020a935618
commit 762168127c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 15 deletions

View file

@ -216,7 +216,7 @@ class ChainHandlerTest extends ChainUnitTest {
final def processHeaders(
processorF: Future[ChainHandler],
remainingHeaders: List[BlockHeader],
height: Long): Future[Assertion] = {
height: Int): Future[Assertion] = {
remainingHeaders match {
case header :: headersTail =>
val newProcessorF = processorF.flatMap(_.processHeader(header))

View file

@ -57,7 +57,7 @@ case class BlockHeaderDAO()(
*/
def getAncestorAtHeight(
child: BlockHeaderDb,
height: Long): Future[Option[BlockHeaderDb]] = {
height: Int): Future[Option[BlockHeaderDb]] = {
/*
* To avoid making many database reads, we make one database read for all
* possibly useful block headers.
@ -112,12 +112,12 @@ case class BlockHeaderDAO()(
}
/** Retrieves a [[BlockHeaderDb]] at the given height */
def getAtHeight(height: Long): Future[Vector[BlockHeaderDb]] = {
def getAtHeight(height: Int): Future[Vector[BlockHeaderDb]] = {
val query = getAtHeightQuery(height)
database.runVec(query)
}
def getAtHeightQuery(height: Long): SQLiteProfile.StreamingProfileAction[
def getAtHeightQuery(height: Int): SQLiteProfile.StreamingProfileAction[
Seq[BlockHeaderDb],
BlockHeaderDb,
Effect.Read] = {
@ -125,14 +125,14 @@ case class BlockHeaderDAO()(
}
/** Gets Block Headers between (inclusive) from and to, could be out of order */
def getBetweenHeights(from: Long, to: Long): Future[Vector[BlockHeaderDb]] = {
def getBetweenHeights(from: Int, to: Int): Future[Vector[BlockHeaderDb]] = {
val query = getBetweenHeightsQuery(from, to)
database.runVec(query)
}
def getBetweenHeightsQuery(
from: Long,
to: Long): SQLiteProfile.StreamingProfileAction[
from: Int,
to: Int): SQLiteProfile.StreamingProfileAction[
Seq[BlockHeaderDb],
BlockHeaderDb,
Effect.Read] = {
@ -140,17 +140,17 @@ case class BlockHeaderDAO()(
}
/** Returns the maximum block height from our database */
def maxHeight: Future[Long] = {
def maxHeight: Future[Int] = {
val query = maxHeightQuery
val result = database.run(query)
result
}
private def maxHeightQuery: SQLiteProfile.ProfileAction[
Long,
Int,
NoStream,
Effect.Read] = {
val query = table.map(_.height).max.getOrElse(0L).result
val query = table.map(_.height).max.getOrElse(0).result
query
}

View file

@ -6,7 +6,7 @@ import org.bitcoins.core.protocol.blockchain.BlockHeader
import slick.jdbc.SQLiteProfile.api._
case class BlockHeaderDb(
height: Long,
height: Int,
hashBE: DoubleSha256DigestBE,
version: Int32,
previousBlockHashBE: DoubleSha256DigestBE,
@ -31,7 +31,7 @@ case class BlockHeaderDb(
object BlockHeaderDbHelper {
def fromBlockHeader(height: Long, bh: BlockHeader): BlockHeaderDb = {
def fromBlockHeader(height: Int, bh: BlockHeader): BlockHeaderDb = {
BlockHeaderDb(
height = height,
hashBE = bh.hashBE,
@ -51,7 +51,7 @@ class BlockHeaderTable(tag: Tag)
extends Table[BlockHeaderDb](tag, "block_headers") {
import org.bitcoins.db.DbCommonsColumnMappers._
def height = column[Long]("height")
def height = column[Int]("height")
def hash = column[DoubleSha256DigestBE]("hash", O.PrimaryKey)

View file

@ -182,8 +182,8 @@ sealed abstract class ChainParams {
/** In bitcoin [[MainNetChainParams mainnet]], the network recalculates the difficulty for the network every 2016 blocks
* [[https://github.com/bitcoin/bitcoin/blob/eb7daf4d600eeb631427c018a984a77a34aca66e/src/consensus/params.h#L75 bitcoin core implementation]]
* */
def difficultyChangeInterval: Long = {
powTargetTimeSpan.toSeconds / powTargetSpacing.toSeconds
def difficultyChangeInterval: Int = {
(powTargetTimeSpan.toSeconds / powTargetSpacing.toSeconds).toInt
}
/**