mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 01:40:55 +01:00
Revert the unique outpoint index DB migration (#4652)
* Revert the unique outpoint index DB migration * fix tests Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
This commit is contained in:
parent
328e1653a9
commit
2448fe13e8
@ -18,7 +18,6 @@ import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.server.util.CallbackUtil
|
||||
import org.bitcoins.wallet.WalletHolder
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
import org.bitcoins.wallet.models.SpendingInfoDAO
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
@ -114,35 +113,6 @@ sealed trait DLCWalletLoaderApi extends Logging with StartStopAsync[Unit] {
|
||||
nodeStateDAO.updateWalletName(walletNameOpt)
|
||||
}
|
||||
|
||||
protected def handleDuplicateSpendingInfoDb(
|
||||
wallet: DLCNeutrinoHDWalletApi,
|
||||
walletConfig: WalletAppConfig)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
val spendingInfoDAO = SpendingInfoDAO()(ec, walletConfig)
|
||||
for {
|
||||
rescanNeeded <- spendingInfoDAO.hasDuplicates()
|
||||
_ <-
|
||||
if (rescanNeeded) {
|
||||
logger.warn("Found duplicate UTXOs. Rescanning...")
|
||||
wallet
|
||||
.rescanNeutrinoWallet(startOpt = None,
|
||||
endOpt = None,
|
||||
addressBatchSize =
|
||||
wallet.discoveryBatchSize(),
|
||||
useCreationTime = true,
|
||||
force = true)
|
||||
.recover { case scala.util.control.NonFatal(exn) =>
|
||||
logger.error(s"Failed to handleDuplicateSpendingInfoDb rescan",
|
||||
exn)
|
||||
RescanState.RescanDone
|
||||
}
|
||||
} else {
|
||||
Future.successful(RescanState.RescanDone)
|
||||
}
|
||||
_ <- spendingInfoDAO.createOutPointsIndexIfNeeded()
|
||||
} yield ()
|
||||
}
|
||||
|
||||
protected def restartRescanIfNeeded(wallet: DLCNeutrinoHDWalletApi)(implicit
|
||||
ec: ExecutionContext): Future[RescanState] = {
|
||||
for {
|
||||
@ -331,7 +301,6 @@ case class DLCWalletNeutrinoBackendLoader(
|
||||
CallbackUtil.createNeutrinoNodeCallbacksForWallet(walletHolder)
|
||||
_ = nodeConf.replaceCallbacks(nodeCallbacks)
|
||||
_ <- updateWalletName(walletNameOpt)
|
||||
_ <- handleDuplicateSpendingInfoDb(walletHolder, walletConfig)
|
||||
rescanState <- restartRescanIfNeeded(walletHolder)
|
||||
_ = setRescanState(rescanState)
|
||||
} yield {
|
||||
@ -382,7 +351,6 @@ case class DLCWalletBitcoindBackendLoader(
|
||||
_ = nodeConf.replaceCallbacks(nodeCallbacks)
|
||||
_ <- walletHolder.replaceWallet(dlcWallet)
|
||||
//do something with possible rescan?
|
||||
_ <- handleDuplicateSpendingInfoDb(walletHolder, walletConfig)
|
||||
rescanState <- restartRescanIfNeeded(walletHolder)
|
||||
_ = setRescanState(rescanState)
|
||||
} yield {
|
||||
|
@ -106,13 +106,13 @@ class DbManagementTest extends BitcoinSAsyncTest with EmbeddedPg {
|
||||
val result = walletDbManagement.migrate()
|
||||
walletAppConfig.driver match {
|
||||
case SQLite =>
|
||||
val expected = 15
|
||||
val expected = 16
|
||||
assert(result.migrationsExecuted == expected)
|
||||
val flywayInfo = walletDbManagement.info()
|
||||
assert(flywayInfo.applied().length == expected)
|
||||
assert(flywayInfo.pending().length == 0)
|
||||
case PostgreSQL =>
|
||||
val expected = 13
|
||||
val expected = 14
|
||||
assert(result.migrationsExecuted == expected)
|
||||
val flywayInfo = walletDbManagement.info()
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS utxo_outpoints ON txo_spending_info (tx_outpoint);
|
@ -0,0 +1 @@
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "utxo_outpoints" ON "txo_spending_info" ("tx_outpoint");
|
@ -669,15 +669,6 @@ case class SpendingInfoDAO()(implicit
|
||||
safeDatabase.run(markAsReservedAction(ts))
|
||||
}
|
||||
|
||||
def createOutPointsIndexIfNeeded(): Future[Unit] = Future {
|
||||
withStatement(
|
||||
s"CREATE UNIQUE INDEX IF NOT EXISTS utxo_outpoints ON $fullTableName (tx_outpoint)") {
|
||||
st =>
|
||||
st.executeUpdate()
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
def hasDuplicates(): Future[Boolean] = FutureUtil.makeAsync { () =>
|
||||
withStatement(
|
||||
s"SELECT EXISTS (SELECT tx_outpoint, COUNT(*) FROM $fullTableName GROUP BY tx_outpoint HAVING COUNT(*) > 1)") {
|
||||
|
Loading…
Reference in New Issue
Block a user