Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBF improvements #654

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BalanceFragment : Fragment() {
}
else -> {
balanceValue.text = NumberFormatHelper.cryptoAmountFormat.format(balance.spendable / 100_000_000.0)
balanceUnspendableValue.text = NumberFormatHelper.cryptoAmountFormat.format(balance.unspendable / 100_000_000.0)
balanceUnspendableValue.text = NumberFormatHelper.cryptoAmountFormat.format((balance.unspendableTimeLocked + balance.unspendableNotRelayed) / 100_000_000.0)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class BitcoinCoreBuilder {
val signer = TransactionSigner(ecdsaInputSigner, schnorrInputSigner)
transactionCreator = TransactionCreator(transactionBuilder, pendingTransactionProcessor, transactionSenderInstance, signer, bloomFilterManager)
replacementTransactionBuilder = ReplacementTransactionBuilder(
storage, transactionSizeCalculator, dustCalculator, metadataExtractor, pluginManager, unspentOutputProvider, publicKeyManager, conflictsResolver
storage, transactionSizeCalculator, dustCalculator, metadataExtractor, pluginManager, unspentOutputProvider, publicKeyManager, conflictsResolver, lockTimeSetter
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ class UnspentOutputProvider(
}
}

private fun getUnspendableUtxo(): List<UnspentOutput> {
return allUtxo().filter {
!pluginManager.isSpendable(it) || it.transaction.status != Transaction.Status.RELAYED
}
private fun getUnspendableTimeLockedUtxo() = allUtxo().filter {
!pluginManager.isSpendable(it)
}

private fun getUnspendableNotRelayedUtxo() = allUtxo().filter {
it.transaction.status != Transaction.Status.RELAYED
}

fun getBalance(): BalanceInfo {
val spendable = getSpendableUtxo().sumOf { it.output.value }
val unspendable = getUnspendableUtxo().sumOf { it.output.value }
val unspendableTimeLocked = getUnspendableTimeLockedUtxo().sumOf { it.output.value }
val unspendableNotRelayed = getUnspendableNotRelayedUtxo().sumOf { it.output.value }

return BalanceInfo(spendable, unspendable)
return BalanceInfo(spendable, unspendableTimeLocked, unspendableNotRelayed)
}

// Only confirmed spendable outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ data class BlockInfo(
val timestamp: Long
)

data class BalanceInfo(val spendable: Long, val unspendable: Long)
data class BalanceInfo(val spendable: Long, val unspendableTimeLocked: Long, val unspendableNotRelayed: Long)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.horizontalsystems.bitcoincore.storage.InputWithPreviousOutput
import io.horizontalsystems.bitcoincore.storage.UnspentOutput
import io.horizontalsystems.bitcoincore.transactions.TransactionConflictsResolver
import io.horizontalsystems.bitcoincore.transactions.TransactionSizeCalculator
import io.horizontalsystems.bitcoincore.transactions.builder.LockTimeSetter
import io.horizontalsystems.bitcoincore.transactions.builder.MutableTransaction
import io.horizontalsystems.bitcoincore.transactions.extractors.TransactionMetadataExtractor
import io.horizontalsystems.bitcoincore.utils.ShuffleSorter
Expand All @@ -32,7 +33,8 @@ class ReplacementTransactionBuilder(
private val pluginManager: PluginManager,
private val unspentOutputProvider: UnspentOutputProvider,
private val publicKeyManager: IPublicKeyManager,
private val conflictsResolver: TransactionConflictsResolver
private val conflictsResolver: TransactionConflictsResolver,
private val lockTimeSetter: LockTimeSetter
) {

private fun replacementTransaction(
Expand Down Expand Up @@ -181,6 +183,7 @@ class ReplacementTransactionBuilder(
mutableTransaction = mutableTransaction,
outputs = fixedOutputs + outputs
)
lockTimeSetter.setLockTime(mutableTransaction)
mutableTransaction
}
}
Expand Down Expand Up @@ -382,9 +385,13 @@ class ReplacementTransactionBuilder(
}

val confirmedUtxoTotalValue = unspentOutputProvider.getConfirmedSpendableUtxo().sumOf { it.output.value }
val feeRange = LongRange(absoluteFee, originalFee + removableOutputsValue + confirmedUtxoTotalValue)
val maxFeeAmount = originalFee + removableOutputsValue + confirmedUtxoTotalValue

return ReplacementTransactionInfo(replacementTxMinSize, feeRange)
return if (absoluteFee > maxFeeAmount) {
null
} else {
ReplacementTransactionInfo(replacementTxMinSize, LongRange(absoluteFee, maxFeeAmount))
}
}

sealed class BuildError : Throwable() {
Expand Down
Loading