Skip to content

Commit

Permalink
Apollo: Release source code for 51.8
Browse files Browse the repository at this point in the history
  • Loading branch information
acrespo committed Feb 26, 2024
1 parent 56769ff commit 23f45fa
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 25 deletions.
14 changes: 13 additions & 1 deletion android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ follow [https://changelog.md/](https://changelog.md/) guidelines.

## [Unreleased]

## [51.6] - 2024-01-24
## [51.8] - 2024-02-23

### CHANGED

- Made the payment address (aka payment secret) flag required in our invoices (and also
the TLV onion as payment secret depends on it). Having the flag as optional was causing some strict
services to block zero amount invoices from Muun. If the secret is optional, the last hop (us) can
forward a fake sphinx without a payment secret and for 1 sat, the app will accept it since the
secret is optional and the last hop keeps the rest of the payment. Payment secret has been widely
adopted for quite a bit now. Major impls all require it.
- Small changes to make data available for Effective Fee Rate calculation in Libwallet.

## [51.7] - 2024-01-24

### FIXED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@ public void initNtsOutpoints() {

setTransactionSize(nts.initOutpoints());
}

/**
* Migration to init utxo status for pre-existing NTSs.
*/
public void initNtsUtxoStatus() {
final boolean hasNts = sharedPreferences.contains(KEY_TRANSACTION_SIZE);

if (!hasNts) {
return;
}

final NextTransactionSize nts = getNextTransactionSize();

Preconditions.checkNotNull(nts);

setTransactionSize(nts.initUtxoStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ public class PreferencesMigrationManager {
this::migrateToRecentEmergencyKitVerificationCodes,

// Sept 2021, Apollo 700 introduces EmergencyKit version and its own model
this::addEmergencyKitVersion
this::addEmergencyKitVersion,

// Feb 2024, Apollo 1108 add local migration that we missed in 2020 (when we
// added UtxoStatus to NTS but never used it).
this::initNtsUtxoStatus
};

/**
Expand Down Expand Up @@ -326,4 +330,8 @@ private void addEmergencyKitVersion() {
keysRepositoryPrefs.edit().remove("ek_recent_verification_codes").apply();
}
}

private void initNtsUtxoStatus() {
transactionSizeRepository.initNtsUtxoStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.muun.common.crypto.hd.PrivateKey
import io.muun.common.crypto.hd.PublicKey
import io.muun.common.utils.Encodings
import org.bitcoinj.core.NetworkParameters
import timber.log.Timber

open class IncomingSwap(
id: Long?,
Expand All @@ -16,7 +17,7 @@ open class IncomingSwap(
private val sphinxPacket: ByteArray?,
val collectInSats: Long,
val paymentAmountInSats: Long,
private var preimage: ByteArray?
private var preimage: ByteArray?,
) : HoustonUuidModel(id, houstonUuid) {

fun getPaymentHash() =
Expand Down Expand Up @@ -51,14 +52,16 @@ open class IncomingSwap(
data: IncomingSwapFulfillmentData,
userKey: PrivateKey,
muunKey: PublicKey,
network: NetworkParameters
network: NetworkParameters,
): FulfillmentResult {

val libwalletUserKey = userKey.toLibwallet(network)
val libwalletMuunKey = muunKey.toLibwallet(network)
val libwalletNetwork = network.toLibwallet()
val libwalletFullfillmentData = data.toLibwalletModel()

debugLog(htlc!!, libwalletFullfillmentData, libwalletUserKey, libwalletMuunKey)

try {
val result = toLibwalletModel().fulfill(
libwalletFullfillmentData,
Expand All @@ -76,6 +79,46 @@ open class IncomingSwap(
}
}

/**
* Debugging info for verifying fullfilmentTxs, htlcTxs, etc...
* Note: if you're looking at this you'll probably be interested in some data that's only
* available in libwallet. See: libwallet/incoming_swap.go.
*/
private fun debugLog(
htlc: IncomingSwapHtlc,
fullfillmentData: libwallet.IncomingSwapFulfillmentData,
userKey: libwallet.HDPrivateKey,
muunKey: libwallet.HDPublicKey,
) {
Timber.d("---IncomingSwap---")
Timber.d("SphinxPacket: $sphinxPacketHex")
Timber.d("PaymentHash: ${Encodings.bytesToHex(paymentHash)}")
Timber.d("HtlcTx: ${Encodings.bytesToHex(htlc.htlcTx)}")
Timber.d("HtlcExpirationHeight: ${htlc.expirationHeight}")
Timber.d("HtlcSwapServerPublicKey: ${Encodings.bytesToHex(htlc.swapServerPublicKey)}")

val merkleTree = fullfillmentData.merkleTree ?: byteArrayOf()
val htlcBlock = fullfillmentData.htlcBlock ?: byteArrayOf()
Timber.d("---IncomingSwapFulfillmentData---")
Timber.d("FullfilmentTx: ${Encodings.bytesToHex(fullfillmentData.fulfillmentTx)}")
Timber.d("MuunSignature: ${Encodings.bytesToHex(fullfillmentData.muunSignature)}")
Timber.d("OuputVersion: ${fullfillmentData.outputVersion}")
Timber.d("OuputPath: ${fullfillmentData.outputPath}")
Timber.d("MerkleTree: ${Encodings.bytesToHex(merkleTree)}")
Timber.d("HtlcBlock: ${Encodings.bytesToHex(htlcBlock)}")
Timber.d("ConfTarget: ${fullfillmentData.confirmationTarget}")

Timber.d("---UserKey---")
Timber.d("Base58: ${userKey.string()}")
Timber.d("Path: ${userKey.path}")
Timber.d("Network: ${userKey.network.name()}")

Timber.d("---muunKey---")
Timber.d("Base58: ${muunKey.string()}")
Timber.d("Path: ${muunKey.path}")
Timber.d("Network: ${muunKey.network.name()}")
}

open fun fulfillFullDebt(): FulfillmentResult {
val result = toLibwalletModel().fulfillFullDebt()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,22 @@ public NextTransactionSize initOutpoints() {

final List<SizeForAmount> newSizeProgression = new ArrayList<>();
for (SizeForAmount sizeForAmount : sizeProgression) {
newSizeProgression.add(sizeForAmount.initOutpoint());
newSizeProgression.add(sizeForAmount.initOutpointForApollo());
}

this.sizeProgression = newSizeProgression;

return this;
}

/**
* Migration to init utxo status for pre-existing NTSs.
*/
public NextTransactionSize initUtxoStatus() {

final List<SizeForAmount> newSizeProgression = new ArrayList<>();
for (SizeForAmount sizeForAmount : sizeProgression) {
newSizeProgression.add(sizeForAmount.initUtxoStatusForApollo());
}

this.sizeProgression = newSizeProgression;
Expand Down Expand Up @@ -173,6 +188,7 @@ private newop.SizeForAmount toLibwallet(SizeForAmount sizeForAmount) {
libwalletSizeForAmount.setAmountInSat(sizeForAmount.amountInSatoshis);
libwalletSizeForAmount.setSizeInVByte(getSizeInVirtualBytes(sizeForAmount));
libwalletSizeForAmount.setOutpoint(sizeForAmount.outpoint);
libwalletSizeForAmount.setUtxoStatus(sizeForAmount.status.toString());

return libwalletSizeForAmount;
}
Expand Down
4 changes: 2 additions & 2 deletions android/apolloui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ android {
applicationId "io.muun.apollo"
minSdkVersion 19
targetSdkVersion 33
versionCode 1107
versionName "51.7"
versionCode 1108
versionName "51.8"

// Needed to make sure these classes are available in the main DEX file for API 19
// See: https://spin.atomicobject.com/2018/07/16/support-kitkat-multidex/
Expand Down
17 changes: 16 additions & 1 deletion common/src/main/java/io/muun/common/model/SizeForAmount.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ public SizeForAmount() {
* Migration to init outpoints for pre-existing sizeForAmounts. Will be properly initialized
* after first NTS refresh (e.g first newOperation, incoming operation, or any operationUpdate).
*/
public SizeForAmount initOutpoint() {
public SizeForAmount initOutpointForApollo() {
if (outpoint == null) {
outpoint = "uninitialized";
}
return this;
}

/**
* Migration to init utxo status for pre-existing sizeForAmounts. Will be properly initialized
* after first NTS refresh (e.g first newOperation, incoming operation, or any operationUpdate).
* NOTE: we're choosing to init status as CONFIRMED as this field has existed for a while now
* in the codebase, and only users with a REALLY old version (circa mid-2020) should have null
* here.
*/
public SizeForAmount initUtxoStatusForApollo() {
if (status == null) {
status = UtxoStatus.CONFIRMED;
}
return this;
}


@Override
public String toString() {
return "[SizeForAmount " + sizeInBytes + " for " + amountInSatoshis + "]";
Expand Down
4 changes: 3 additions & 1 deletion libwallet/incoming_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func (s *IncomingSwap) Fulfill(
return nil, fmt.Errorf("Fulfill: missing swap htlc data")
}

// TODO: add debug logs (e.g debug logging capabilities in libwallet)

err := s.VerifyFulfillable(userKey, net)
if err != nil {
return nil, err
Expand Down Expand Up @@ -155,7 +157,7 @@ func (s *IncomingSwap) Fulfill(
Sphinx: s.SphinxPacket,
HtlcTx: s.Htlc.HtlcTx,
PaymentHash256: s.PaymentHash,
SwapServerPublicKey: []byte(s.Htlc.SwapServerPublicKey),
SwapServerPublicKey: s.Htlc.SwapServerPublicKey,
ExpirationHeight: s.Htlc.ExpirationHeight,
VerifyOutputAmount: true,
Collect: btcutil.Amount(s.CollectSat),
Expand Down
Loading

0 comments on commit 23f45fa

Please sign in to comment.