mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 01:40:55 +01:00
Refactoring chain
(#2662)
This commit is contained in:
parent
931a528723
commit
85087b0f70
@ -25,7 +25,6 @@ import org.bitcoins.core.protocol.script.EmptyScriptWitness
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp, P2PKHAddress}
|
||||
import org.bitcoins.core.psbt.PSBT
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.core.wallet.fee.{FeeUnit, SatoshisPerVirtualByte}
|
||||
import org.bitcoins.core.wallet.utxo._
|
||||
import org.bitcoins.crypto.{
|
||||
@ -757,7 +756,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
(mockNode
|
||||
.broadcastTransaction(_: Transaction))
|
||||
.expects(tx)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route =
|
||||
@ -805,7 +804,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -877,7 +876,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -958,7 +957,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -1059,7 +1058,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -1080,7 +1079,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -1102,7 +1101,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
|
||||
(mockWalletApi.broadcastTransaction _)
|
||||
.expects(EmptyTransaction)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
.anyNumberOfTimes()
|
||||
|
||||
val route = walletRoutes.handleCommand(
|
||||
@ -1161,7 +1160,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
_: Int,
|
||||
_: Boolean)(_: ExecutionContext))
|
||||
.expects(None, None, 100, false, executor)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
|
||||
val route1 =
|
||||
walletRoutes.handleCommand(
|
||||
@ -1188,7 +1187,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
100,
|
||||
false,
|
||||
executor)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
|
||||
val route2 =
|
||||
walletRoutes.handleCommand(
|
||||
@ -1215,7 +1214,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
100,
|
||||
false,
|
||||
executor)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
|
||||
val route3 =
|
||||
walletRoutes.handleCommand(
|
||||
@ -1242,7 +1241,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
100,
|
||||
false,
|
||||
executor)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
|
||||
val route4 =
|
||||
walletRoutes.handleCommand(
|
||||
@ -1298,7 +1297,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||
_: Int,
|
||||
_: Boolean)(_: ExecutionContext))
|
||||
.expects(None, None, 55, false, executor)
|
||||
.returning(FutureUtil.unit)
|
||||
.returning(Future.unit)
|
||||
|
||||
val route8 =
|
||||
walletRoutes.handleCommand(
|
||||
|
@ -10,7 +10,7 @@ import org.bitcoins.core.Core
|
||||
import org.bitcoins.core.api.chain.ChainApi
|
||||
import org.bitcoins.core.api.feeprovider.FeeRateApi
|
||||
import org.bitcoins.core.api.node.NodeApi
|
||||
import org.bitcoins.core.util.{FutureUtil, NetworkUtil}
|
||||
import org.bitcoins.core.util.NetworkUtil
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
|
||||
import org.bitcoins.feeprovider.FeeProviderName._
|
||||
import org.bitcoins.feeprovider.MempoolSpaceTarget.HourFeeTarget
|
||||
@ -209,7 +209,7 @@ class BitcoinSServerMain(override val args: Array[String])
|
||||
}
|
||||
lazy val onHeaders: OnBlockHeadersReceived = { headers =>
|
||||
if (headers.isEmpty) {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
} else {
|
||||
wallet.updateUtxoPendingStates().map(_ => ())
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.nio.file._
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.db._
|
||||
import org.bitcoins.node.NodeType
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
@ -42,11 +41,11 @@ case class BitcoindRpcAppConfig(
|
||||
case NodeType.BitcoindBackend =>
|
||||
client.start().map(_ => ())
|
||||
case NodeType.SpvNode | NodeType.NeutrinoNode | NodeType.FullNode =>
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
}
|
||||
|
||||
override def stop(): Future[Unit] = FutureUtil.unit
|
||||
override def stop(): Future[Unit] = Future.unit
|
||||
|
||||
lazy val DEFAULT_BINARY_PATH: File =
|
||||
BitcoindInstance.DEFAULT_BITCOIND_LOCATION
|
||||
|
@ -61,7 +61,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
|
||||
utxos <- wallet.listUtxos()
|
||||
lastConfirmedOpt = utxos.filter(_.blockHash.isDefined).lastOption
|
||||
_ <- lastConfirmedOpt match {
|
||||
case None => FutureUtil.unit
|
||||
case None => Future.unit
|
||||
case Some(utxo) =>
|
||||
for {
|
||||
heightOpt <- bitcoind.getBlockHeight(utxo.blockHash.get)
|
||||
@ -70,7 +70,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
|
||||
logger.info(
|
||||
s"Last utxo occurred at block $height, syncing from there")
|
||||
doSync(height, bitcoindHeight)
|
||||
case None => FutureUtil.unit
|
||||
case None => Future.unit
|
||||
}
|
||||
} yield ()
|
||||
}
|
||||
@ -240,7 +240,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
|
||||
} else if (prevCount > count) {
|
||||
Future.failed(new RuntimeException(
|
||||
s"Bitcoind is at a block height ($count) before the wallet's ($prevCount)"))
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
}
|
||||
()
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.bitcoins.core.p2p.CompactFilterMessage
|
||||
import org.bitcoins.core.protocol.BlockStamp
|
||||
import org.bitcoins.core.protocol.blockchain.BlockHeader
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.core.wallet.fee.FeeUnit
|
||||
import org.bitcoins.crypto.{
|
||||
DoubleSha256Digest,
|
||||
@ -123,7 +122,7 @@ class BitcoindRpcClient(val instance: BitcoindInstance)(implicit
|
||||
sendRawTransaction(transaction).map(_ => ())
|
||||
|
||||
override def downloadBlocks(
|
||||
blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = FutureUtil.unit
|
||||
blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.unit
|
||||
|
||||
override def processHeaders(headers: Vector[BlockHeader]): Future[ChainApi] =
|
||||
Future.successful(this)
|
||||
|
@ -20,7 +20,7 @@ import org.bitcoins.core.config.{
|
||||
TestNet3
|
||||
}
|
||||
import org.bitcoins.core.crypto.ECPrivateKeyUtil
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStopAsync}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
||||
import org.bitcoins.crypto.ECPrivateKey
|
||||
import org.bitcoins.rpc.BitcoindException
|
||||
import org.bitcoins.rpc.config.BitcoindAuthCredentials.{
|
||||
@ -227,7 +227,7 @@ trait Client extends BitcoinSLogger with StartStopAsync[BitcoindRpcClient] {
|
||||
_ <- {
|
||||
if (system.name == BitcoindRpcClient.ActorSystemName) {
|
||||
system.terminate()
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
}
|
||||
} yield this.asInstanceOf[BitcoindRpcClient]
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.bitcoins.rpc.util
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration.{DurationInt, FiniteDuration}
|
||||
@ -87,7 +87,7 @@ abstract class AsyncUtil extends BitcoinSLogger {
|
||||
|
||||
conditionF().flatMap { condition =>
|
||||
if (condition) {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
} else if (counter == maxTries) {
|
||||
Future.failed(RpcRetryException(
|
||||
s"Condition timed out after $maxTries attempts with interval=$interval waiting periods",
|
||||
@ -99,7 +99,7 @@ abstract class AsyncUtil extends BitcoinSLogger {
|
||||
system.scheduler.scheduleOnce(delay = interval, runnable = runnable)
|
||||
|
||||
p.future.flatMap {
|
||||
case true => FutureUtil.unit
|
||||
case true => Future.unit
|
||||
case false =>
|
||||
retryUntilSatisfiedWithCounter(conditionF = conditionF,
|
||||
interval = interval,
|
||||
|
@ -7,7 +7,7 @@ import scala.collection.mutable
|
||||
/** @inheritdoc */
|
||||
case class Blockchain(headers: Vector[BlockHeaderDb]) extends BaseBlockChain {
|
||||
|
||||
protected[blockchain] def compObjectfromHeaders(
|
||||
protected[blockchain] def compObjectFromHeaders(
|
||||
headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain =
|
||||
Blockchain.fromHeaders(headers)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import org.bitcoins.core.api.chain.db.BlockHeaderDb
|
||||
/** @inheritdoc */
|
||||
case class Blockchain(headers: Vector[BlockHeaderDb]) extends BaseBlockChain {
|
||||
|
||||
protected[blockchain] def compObjectfromHeaders(
|
||||
protected[blockchain] def compObjectFromHeaders(
|
||||
headers: scala.collection.immutable.Seq[BlockHeaderDb]) =
|
||||
Blockchain.fromHeaders(headers)
|
||||
|
||||
|
@ -33,7 +33,7 @@ import scala.annotation.tailrec
|
||||
*/
|
||||
private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] {
|
||||
|
||||
protected[blockchain] def compObjectfromHeaders(
|
||||
protected[blockchain] def compObjectFromHeaders(
|
||||
headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain
|
||||
|
||||
lazy val tip: BlockHeaderDb = headers.head
|
||||
@ -58,7 +58,7 @@ private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] {
|
||||
def fromHeader(header: BlockHeaderDb): Option[Blockchain] = {
|
||||
val headerIdxOpt = findHeaderIdx(header.hashBE)
|
||||
headerIdxOpt.map { idx =>
|
||||
val newChain = this.compObjectfromHeaders(headers.splitAt(idx)._2)
|
||||
val newChain = this.compObjectFromHeaders(headers.splitAt(idx)._2)
|
||||
require(newChain.tip == header)
|
||||
newChain
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class ChainHandler(
|
||||
//since we have same chainwork, just take the oldest tip
|
||||
//as that's "more likely" to have been propagated first
|
||||
//and had more miners building on top of it
|
||||
chainsByWork.sortBy(_.tip.time).head.tip
|
||||
chainsByWork.minBy(_.tip.time).tip
|
||||
}
|
||||
}
|
||||
bestHeader
|
||||
@ -153,7 +153,7 @@ class ChainHandler(
|
||||
|
||||
createdF.map { headers =>
|
||||
if (chainConfig.chainCallbacks.onBlockHeaderConnected.nonEmpty) {
|
||||
headersToBeCreated.reverseIterator.foldLeft(FutureUtil.unit) {
|
||||
headersToBeCreated.reverseIterator.foldLeft(Future.unit) {
|
||||
(acc, header) =>
|
||||
for {
|
||||
_ <- acc
|
||||
@ -198,38 +198,26 @@ class ChainHandler(
|
||||
protected def nextBlockHeaderBatchRangeWithChains(
|
||||
prevStopHash: DoubleSha256DigestBE,
|
||||
batchSize: Int,
|
||||
blockchains: Vector[Blockchain]): Future[Option[FilterSyncMarker]] = {
|
||||
for {
|
||||
prevBlockHeaderOpt <- getHeader(prevStopHash)
|
||||
headerOpt <- prevBlockHeaderOpt match {
|
||||
case Some(_) =>
|
||||
findNextHeader(prevBlockHeaderOpt, batchSize, blockchains)
|
||||
case None =>
|
||||
if (prevStopHash == DoubleSha256DigestBE.empty) {
|
||||
for {
|
||||
next <- findNextHeader(None, batchSize, blockchains)
|
||||
} yield next
|
||||
} else {
|
||||
Future.successful(None)
|
||||
}
|
||||
}
|
||||
} yield {
|
||||
headerOpt
|
||||
}
|
||||
}
|
||||
blockchains: Vector[Blockchain]): Future[Option[FilterSyncMarker]] = for {
|
||||
prevBlockHeaderOpt <- getHeader(prevStopHash)
|
||||
headerOpt <-
|
||||
if (prevBlockHeaderOpt.isDefined)
|
||||
findNextHeader(prevBlockHeaderOpt, batchSize, blockchains)
|
||||
else if (prevStopHash == DoubleSha256DigestBE.empty)
|
||||
findNextHeader(None, batchSize, blockchains)
|
||||
else Future.successful(None)
|
||||
} yield headerOpt
|
||||
|
||||
/** @inheritdoc */
|
||||
override def nextBlockHeaderBatchRange(
|
||||
prevStopHash: DoubleSha256DigestBE,
|
||||
batchSize: Int): Future[Option[FilterSyncMarker]] = {
|
||||
val blockchainsF = blockHeaderDAO.getBlockchains()
|
||||
batchSize: Int): Future[Option[FilterSyncMarker]] =
|
||||
for {
|
||||
blockchains <- blockchainsF
|
||||
blockchains <- blockHeaderDAO.getBlockchains()
|
||||
syncMarkerOpt <- nextBlockHeaderBatchRangeWithChains(prevStopHash,
|
||||
batchSize,
|
||||
blockchains)
|
||||
} yield syncMarkerOpt
|
||||
}
|
||||
|
||||
/** Finds the next header in the chain. Uses chain work to break ties
|
||||
* returning only the header in the chain with the most work
|
||||
@ -384,7 +372,7 @@ class ChainHandler(
|
||||
s"Previous filter header does not exist: $firstFilter"
|
||||
)
|
||||
}
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
_ <- filterHeaderDAO.createAll(filterHeadersToCreate)
|
||||
} yield {
|
||||
val minHeightOpt = filterHeadersToCreate.minByOption(_.height)
|
||||
|
@ -6,7 +6,7 @@ import org.bitcoins.chain.db.ChainDbManagement
|
||||
import org.bitcoins.chain.models.BlockHeaderDAO
|
||||
import org.bitcoins.chain.pow.Pow
|
||||
import org.bitcoins.core.api.chain.db.BlockHeaderDbHelper
|
||||
import org.bitcoins.core.util.{FutureUtil, Mutable}
|
||||
import org.bitcoins.core.util.Mutable
|
||||
import org.bitcoins.db._
|
||||
|
||||
import java.nio.file.Path
|
||||
@ -73,7 +73,7 @@ case class ChainAppConfig(
|
||||
isInit <- isStarted()
|
||||
_ <- {
|
||||
if (isInit) {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
} else {
|
||||
val genesisHeader =
|
||||
BlockHeaderDbHelper.fromBlockHeader(
|
||||
@ -85,7 +85,7 @@ case class ChainAppConfig(
|
||||
val bhCreatedF = blockHeaderDAO.create(genesisHeader)
|
||||
bhCreatedF.flatMap { _ =>
|
||||
logger.info(s"Inserted genesis block header into DB")
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ case class ChainAppConfig(
|
||||
|
||||
override def stop(): Future[Unit] = {
|
||||
val _ = stopHikariLogger()
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
lazy val filterHeaderBatchSize: Int = {
|
||||
|
@ -59,7 +59,7 @@ case class BlockHeaderDAO()(implicit
|
||||
table.filter(_.hash.inSet(hashes))
|
||||
}
|
||||
|
||||
/** Retrives the ancestor for the given block header at the given height
|
||||
/** Retrieves the ancestor for the given block header at the given height
|
||||
* @param child
|
||||
* @param height
|
||||
* @return
|
||||
@ -71,37 +71,29 @@ case class BlockHeaderDAO()(implicit
|
||||
* To avoid making many database reads, we make one database read for all
|
||||
* possibly useful block headers.
|
||||
*/
|
||||
val headersF = getBetweenHeights(from = height, to = child.height - 1)
|
||||
lazy val headersF = getBetweenHeights(from = height, to = child.height - 1)
|
||||
|
||||
/*
|
||||
* We then bucket sort these headers by height so that any ancestor can be found
|
||||
* in linear time assuming a bounded number of contentious tips.
|
||||
*/
|
||||
val headersByHeight: Array[Vector[BlockHeaderDb]] =
|
||||
new Array[Vector[BlockHeaderDb]](_length = (child.height - height).toInt)
|
||||
|
||||
/*
|
||||
* I believe Array's of Objects are instantiated with null, which is evil,
|
||||
* and so we start by giving each element of the array a Vector.empty.
|
||||
*/
|
||||
headersByHeight.indices.foreach(index =>
|
||||
headersByHeight(index) = Vector.empty)
|
||||
Array.fill(child.height - height)(Vector.empty[BlockHeaderDb])
|
||||
|
||||
// Bucket sort
|
||||
headersF.map { headers =>
|
||||
headers.foreach { header =>
|
||||
val index = (header.height - height).toInt
|
||||
val index = header.height - height
|
||||
headersByHeight(index) = headersByHeight(index).:+(header)
|
||||
}
|
||||
|
||||
// Now that the bucket sort is done, we get rid of mutability
|
||||
val groupedByHeightHeaders: List[Vector[BlockHeaderDb]] =
|
||||
headersByHeight.toList
|
||||
val groupedByHeightHeaders: Array[Vector[BlockHeaderDb]] =
|
||||
headersByHeight.reverse
|
||||
|
||||
@tailrec
|
||||
def loop(
|
||||
currentHeader: BlockHeaderDb,
|
||||
headersByDescHeight: List[Vector[BlockHeaderDb]]): Option[
|
||||
headersByDescHeight: Array[Vector[BlockHeaderDb]]): Option[
|
||||
BlockHeaderDb] = {
|
||||
if (currentHeader.height == height) {
|
||||
Some(currentHeader)
|
||||
@ -116,7 +108,7 @@ case class BlockHeaderDAO()(implicit
|
||||
}
|
||||
}
|
||||
|
||||
loop(child, groupedByHeightHeaders.reverse)
|
||||
loop(child, groupedByHeightHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import org.bitcoins.core.util.NumberUtil
|
||||
sealed abstract class Pow {
|
||||
|
||||
/** Gets the next proof of work requirement for a block
|
||||
* @see [[https://github.com/bitcoin/bitcoin/blob/35477e9e4e3f0f207ac6fa5764886b15bf9af8d0/src/pow.cpp#L13 Mimics bitcoin core implmentation]]
|
||||
* @see [[https://github.com/bitcoin/bitcoin/blob/35477e9e4e3f0f207ac6fa5764886b15bf9af8d0/src/pow.cpp#L13 Mimics bitcoin core implementation]]
|
||||
*/
|
||||
def getNetworkWorkRequired(
|
||||
newPotentialTip: BlockHeader,
|
||||
@ -76,7 +76,7 @@ sealed abstract class Pow {
|
||||
chainParams)
|
||||
case None =>
|
||||
throw new RuntimeException(
|
||||
s"Could not find block at height=${firstHeight} out of ${blockchain.length} headers to calculate pow difficutly change")
|
||||
s"Could not find block at height=$firstHeight out of ${blockchain.length} headers to calculate pow difficulty change")
|
||||
}
|
||||
|
||||
}
|
||||
@ -120,7 +120,7 @@ sealed abstract class Pow {
|
||||
bnNew = powLimit
|
||||
}
|
||||
|
||||
val newTarget = NumberUtil.targetCompression(bnNew, false)
|
||||
val newTarget = NumberUtil.targetCompression(bnNew, isNegative = false)
|
||||
|
||||
newTarget
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.bitcoins.core.api
|
||||
|
||||
import grizzled.slf4j.Logger
|
||||
import org.bitcoins.core.util.{FutureUtil, SeqWrapper}
|
||||
import org.bitcoins.core.util.SeqWrapper
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.control.NonFatal
|
||||
@ -29,7 +29,7 @@ trait Callback3[T1, T2, T3] extends Callback[(T1, T2, T3)] {
|
||||
object Callback {
|
||||
|
||||
/** Does nothing */
|
||||
def noop[T]: T => Future[Unit] = _ => FutureUtil.unit
|
||||
def noop[T]: T => Future[Unit] = _ => Future.unit
|
||||
}
|
||||
|
||||
/** Manages a set of callbacks, should be used to manage execution and logging if needed */
|
||||
|
@ -30,8 +30,6 @@ object FutureUtil {
|
||||
FutureUtil.sequentially(items)(x => x)
|
||||
}
|
||||
|
||||
val unit: Future[Unit] = Future.successful(())
|
||||
|
||||
def none[T]: Future[Option[T]] = Future.successful(Option.empty[T])
|
||||
|
||||
def emptyVec[T]: Future[Vector[T]] = Future.successful(Vector.empty[T])
|
||||
|
@ -3,7 +3,7 @@ package org.bitcoins.db
|
||||
import com.typesafe.config._
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.protocol.blockchain.BitcoinChainParams
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStopAsync}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
||||
|
||||
import java.nio.file.{Files, Path, Paths}
|
||||
import scala.concurrent.Future
|
||||
@ -27,7 +27,7 @@ abstract class AppConfig extends StartStopAsync[Unit] with BitcoinSLogger {
|
||||
* something else entirely.
|
||||
*/
|
||||
override def start(): Future[Unit] = {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
/** Sub members of AppConfig should override this type with
|
||||
|
@ -122,7 +122,7 @@ trait DbManagement extends BitcoinSLogger {
|
||||
ec: ExecutionContext): Future[Unit] =
|
||||
appConfig.schemaName match {
|
||||
case None =>
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
case Some(schema) =>
|
||||
val sql =
|
||||
if (createIfNotExists)
|
||||
|
@ -5,7 +5,6 @@ import org.bitcoins.core.config.NetworkParameters
|
||||
import org.bitcoins.core.crypto.ExtKeyVersion.SegWitMainNetPriv
|
||||
import org.bitcoins.core.hd.HDPurpose
|
||||
import org.bitcoins.core.protocol.tlv.EnumEventDescriptorV0TLV
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.core.wallet.keymanagement.KeyManagerParams
|
||||
import org.bitcoins.crypto.AesPassword
|
||||
import org.bitcoins.db.DatabaseDriver._
|
||||
@ -86,7 +85,7 @@ case class DLCOracleAppConfig(
|
||||
_ <- eventDAO.upsertAll(updated)
|
||||
|
||||
} yield ()
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
|
||||
migrationWorkAroundF.map { _ =>
|
||||
if (isHikariLoggingEnabled) {
|
||||
|
@ -23,7 +23,7 @@ import org.bitcoins.core.protocol.ln.routing.{ChannelRoute, NodeRoute, Route}
|
||||
import org.bitcoins.core.protocol.ln.{LnInvoice, LnParams, PaymentPreimage}
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.{Address, BitcoinAddress}
|
||||
import org.bitcoins.core.util.{BytesUtil, FutureUtil, StartStopAsync}
|
||||
import org.bitcoins.core.util.{BytesUtil, StartStopAsync}
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerByte
|
||||
import org.bitcoins.crypto.{DoubleSha256DigestBE, Sha256Digest}
|
||||
import org.bitcoins.eclair.rpc.api._
|
||||
@ -815,7 +815,7 @@ class EclairRpcClient(
|
||||
val actorSystemF = if (system.name == EclairRpcClient.ActorSystemName) {
|
||||
system.terminate()
|
||||
} else {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
actorSystemF.map(_ => this)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.bitcoins.keymanager.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import org.bitcoins.core.config.NetworkParameters
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.AesPassword
|
||||
import org.bitcoins.db._
|
||||
import org.bitcoins.keymanager.WalletStorage
|
||||
@ -61,10 +60,10 @@ case class KeyManagerAppConfig(
|
||||
Files.createDirectories(newDefaultFile.getParent)
|
||||
Files.copy(oldDefaultFile, newDefaultFile)
|
||||
}
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
override def stop(): Future[Unit] = FutureUtil.unit
|
||||
override def stop(): Future[Unit] = Future.unit
|
||||
|
||||
lazy val aesPasswordOpt: Option[AesPassword] = {
|
||||
val passOpt = config.getStringOrNone(s"bitcoin-s.$moduleName.aesPassword")
|
||||
|
@ -3,7 +3,6 @@ package org.bitcoins.node.networking.peer
|
||||
import _root_.org.scalatest.compatible.Assertion
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, MerkleBlock}
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.node.{NodeCallbacks, OnMerkleBlockReceived}
|
||||
import org.bitcoins.testkit.core.gen.{
|
||||
BlockchainElementsGenerator,
|
||||
@ -36,7 +35,7 @@ class MerkleBuffersTest extends BitcoinSAsyncTest with CachedBitcoinSAppConfig {
|
||||
Try(assert(txs == merkleTxs,
|
||||
"Received TXs in callback was not the ones we put in")))
|
||||
callbackCount = callbackCount + 1
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
val callbacks = NodeCallbacks(onMerkleBlockReceived = Vector(callback))
|
||||
|
||||
|
@ -13,7 +13,6 @@ import org.bitcoins.core.api.chain._
|
||||
import org.bitcoins.core.api.node.NodeApi
|
||||
import org.bitcoins.core.p2p.{NetworkPayload, TypeIdentifier}
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.{DoubleSha256Digest, DoubleSha256DigestBE}
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
import org.bitcoins.node.models.{
|
||||
@ -257,7 +256,7 @@ trait Node extends NodeApi with ChainQueryApi with P2PLogger {
|
||||
override def downloadBlocks(
|
||||
blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = {
|
||||
if (blockHashes.isEmpty) {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
} else {
|
||||
for {
|
||||
peerMsgSender <- peerMsgSenderF
|
||||
|
@ -4,7 +4,7 @@ import akka.Done
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import org.bitcoins.chain.config.ChainAppConfig
|
||||
import org.bitcoins.core.util.{FutureUtil, Mutable}
|
||||
import org.bitcoins.core.util.Mutable
|
||||
import org.bitcoins.db.{AppConfigFactory, DbAppConfig, JdbcProfileComponent}
|
||||
import org.bitcoins.node._
|
||||
import org.bitcoins.node.db.NodeDbManagement
|
||||
@ -65,7 +65,7 @@ case class NodeAppConfig(
|
||||
|
||||
override def stop(): Future[Unit] = {
|
||||
val _ = stopHikariLogger()
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
lazy val nodeType: NodeType =
|
||||
|
@ -5,7 +5,6 @@ import org.bitcoins.chain.config.ChainAppConfig
|
||||
import org.bitcoins.core.api.chain.ChainApi
|
||||
import org.bitcoins.core.gcs.BlockFilter
|
||||
import org.bitcoins.core.p2p._
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
import org.bitcoins.node.models.BroadcastAbleTransactionDAO
|
||||
@ -138,7 +137,7 @@ case class DataMessageHandler(
|
||||
logger.info(
|
||||
s"Received maximum amount of filters in one batch. This means we are not synced, requesting more")
|
||||
sendNextGetCompactFilterCommand(peerMsgSender, newFilterHeight)
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
} yield {
|
||||
this.copy(
|
||||
chainApi = newChainApi,
|
||||
|
@ -10,7 +10,6 @@ import org.bitcoins.core.bloom.BloomFilter
|
||||
import org.bitcoins.core.number.Int32
|
||||
import org.bitcoins.core.p2p._
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.{
|
||||
DoubleSha256Digest,
|
||||
DoubleSha256DigestBE,
|
||||
@ -52,12 +51,12 @@ case class PeerMessageSender(client: P2PClient)(implicit conf: NodeAppConfig)
|
||||
case true =>
|
||||
logger.info(s"Disconnecting peer at socket=${socket}")
|
||||
(client.actor ! Tcp.Close)
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
case false =>
|
||||
val err =
|
||||
s"Cannot disconnect client that is not connected to socket=${socket}!"
|
||||
logger.warn(err)
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
}
|
||||
@ -237,7 +236,7 @@ case class PeerMessageSender(client: P2PClient)(implicit conf: NodeAppConfig)
|
||||
logger.debug(s"Sending msg=${msg.commandName} to peer=${socket}")
|
||||
val newtworkMsg = NetworkMessage(conf.network, msg)
|
||||
client.actor ! newtworkMsg
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.bitcoins.testkit.chain.fixture
|
||||
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.testkit.chain.ChainUnitTest
|
||||
import org.bitcoins.testkit.chain.fixture.ChainFixture.{
|
||||
BitcoindZmqChainHandlerWithBlock,
|
||||
@ -46,7 +45,7 @@ trait ChainFixtureHelper { this: ChainUnitTest =>
|
||||
|
||||
def destroyFixture(fixture: ChainFixture): Future[Any] = {
|
||||
fixture match {
|
||||
case Empty => FutureUtil.unit
|
||||
case Empty => Future.unit
|
||||
case GenisisBlockHeaderDAO(_) => ChainUnitTest.destroyAllTables()
|
||||
case PopulatedBlockHeaderDAO(_) => ChainUnitTest.destroyAllTables()
|
||||
case GenisisChainHandler(_) => ChainUnitTest.destroyAllTables()
|
||||
|
@ -22,7 +22,7 @@ import org.bitcoins.core.protocol.transaction.{
|
||||
TransactionInput,
|
||||
TransactionOutPoint
|
||||
}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil, FutureUtil}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil}
|
||||
import org.bitcoins.crypto.{
|
||||
DoubleSha256Digest,
|
||||
DoubleSha256DigestBE,
|
||||
@ -993,7 +993,7 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||
seenBlock <- hasSeenBlock(receiver, blockHash)
|
||||
_ <-
|
||||
if (seenBlock) {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
} else {
|
||||
sender
|
||||
.getBlockRaw(blockHash)
|
||||
|
@ -330,7 +330,7 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg {
|
||||
val destroy: WalletAppConfig => Future[Unit] = walletAppConfig => {
|
||||
FileUtil.deleteTmpDir(walletAppConfig.datadir)
|
||||
walletAppConfig.stop()
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
makeDependentFixture(builder, destroy = destroy)(test)
|
||||
}
|
||||
@ -356,10 +356,10 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
object MockNodeApi extends NodeApi {
|
||||
|
||||
override def broadcastTransaction(transaction: Transaction): Future[Unit] =
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
|
||||
override def downloadBlocks(
|
||||
blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = FutureUtil.unit
|
||||
blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.unit
|
||||
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ abstract class Wallet
|
||||
logger.info(
|
||||
s"Missing relevant ${utxos.size} wallet transactions, fetching their blocks..")
|
||||
nodeApi.downloadBlocks(blockHashes.distinct)
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
} yield ()
|
||||
|
||||
private def checkRootAccount: Future[Unit] = {
|
||||
@ -133,7 +133,7 @@ abstract class Wallet
|
||||
s"It is possible we have a different key manager being used than expected, key manager=$keyManager"
|
||||
Future.failed(new RuntimeException(errorMsg))
|
||||
} else {
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
case None =>
|
||||
val errorMsg = s"Missing root xpub for account $account in database"
|
||||
@ -187,7 +187,7 @@ abstract class Wallet
|
||||
val matcher = SimpleFilterMatcher(blockFilter)
|
||||
if (matcher.matchesAny(scriptPubKeys.toVector.map(_.asmBytes))) {
|
||||
nodeApi.downloadBlocks(Vector(blockHash))
|
||||
} else FutureUtil.unit
|
||||
} else Future.unit
|
||||
}
|
||||
hash = blockFilters.last._1.flip
|
||||
height <- chainQueryApi.getBlockHeight(hash)
|
||||
|
@ -5,7 +5,7 @@ import org.bitcoins.core.api.chain.ChainQueryApi
|
||||
import org.bitcoins.core.api.feeprovider.FeeRateApi
|
||||
import org.bitcoins.core.api.node.NodeApi
|
||||
import org.bitcoins.core.hd._
|
||||
import org.bitcoins.core.util.{FutureUtil, Mutable}
|
||||
import org.bitcoins.core.util.Mutable
|
||||
import org.bitcoins.core.wallet.keymanagement.{
|
||||
KeyManagerInitializeError,
|
||||
KeyManagerParams
|
||||
@ -166,7 +166,7 @@ case class WalletAppConfig(
|
||||
if (isHikariLoggingEnabled) {
|
||||
val _ = stopHikariLogger()
|
||||
}
|
||||
FutureUtil.unit
|
||||
Future.unit
|
||||
}
|
||||
|
||||
/** The path to our encrypted mnemonic seed */
|
||||
|
@ -110,7 +110,7 @@ trait FundTransactionHandling extends WalletLogger { self: Wallet =>
|
||||
}
|
||||
_ <-
|
||||
if (markAsReserved) markUTXOsAsReserved(selectedUtxos.map(_._1))
|
||||
else FutureUtil.unit
|
||||
else Future.unit
|
||||
} yield {
|
||||
logger.info {
|
||||
val utxosStr = utxoSpendingInfos
|
||||
|
@ -150,14 +150,14 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
||||
private def pruneUnusedAddresses(): Future[Unit] = {
|
||||
for {
|
||||
addressDbs <- addressDAO.findAll()
|
||||
_ <- addressDbs.foldLeft(FutureUtil.unit) { (prevF, addressDb) =>
|
||||
_ <- addressDbs.foldLeft(Future.unit) { (prevF, addressDb) =>
|
||||
for {
|
||||
_ <- prevF
|
||||
spendingInfoDbs <-
|
||||
spendingInfoDAO.findByScriptPubKeyId(addressDb.scriptPubKeyId)
|
||||
_ <-
|
||||
if (spendingInfoDbs.isEmpty) addressDAO.delete(addressDb)
|
||||
else FutureUtil.unit
|
||||
else Future.unit
|
||||
} yield ()
|
||||
}
|
||||
} yield ()
|
||||
@ -193,7 +193,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
||||
private def downloadAndProcessBlocks(
|
||||
blocks: Vector[DoubleSha256Digest]): Future[Unit] = {
|
||||
logger.info(s"Requesting ${blocks.size} block(s)")
|
||||
blocks.foldLeft(FutureUtil.unit) { (prevF, blockHash) =>
|
||||
blocks.foldLeft(Future.unit) { (prevF, blockHash) =>
|
||||
val completedF = subscribeForBlockProcessingCompletionSignal(blockHash)
|
||||
for {
|
||||
_ <- prevF
|
||||
|
Loading…
Reference in New Issue
Block a user