Skip to content

Commit

Permalink
Fixup! Add metrics on splicing (#2756) (#2759)
Browse files Browse the repository at this point in the history
We were considering all local outputs as splice outputs, but some may be change.
  • Loading branch information
pm47 authored Sep 29, 2023
1 parent e4103a2 commit db8e0f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ object Monitoring {
}
}

/**
* This is best effort! It is not possible to attribute a type to a splice in all cases. For example, if remote provides
* both inputs and outputs, it could be a splice-in (with change), or a combined splice-in + splice-out.
*/
def recordSplice(fundingParams: InteractiveTxParams, sharedTx: SharedTransaction): Unit = {
if (fundingParams.localContribution > 0.sat) {
Metrics.Splices.withTag(Tags.Origin, Tags.Origins.Local).withTag(Tags.SpliceType, Tags.SpliceTypes.SpliceIn).record(fundingParams.localContribution.toLong)
}
if (fundingParams.remoteContribution > 0.sat) {
Metrics.Splices.withTag(Tags.Origin, Tags.Origins.Remote).withTag(Tags.SpliceType, Tags.SpliceTypes.SpliceIn).record(fundingParams.remoteContribution.toLong)
}
if (sharedTx.localOutputs.nonEmpty) {
Metrics.Splices.withTag(Tags.Origin, Tags.Origins.Local).withTag(Tags.SpliceType, Tags.SpliceTypes.SpliceOut).record(sharedTx.localOutputs.map(_.amount).sum.toLong)
if (sharedTx.localOnlyNonChangeOutputs.nonEmpty) {
Metrics.Splices.withTag(Tags.Origin, Tags.Origins.Local).withTag(Tags.SpliceType, Tags.SpliceTypes.SpliceOut).record(sharedTx.localOnlyNonChangeOutputs.map(_.amount).sum.toLong)
}
if (sharedTx.remoteOutputs.nonEmpty) {
Metrics.Splices.withTag(Tags.Origin, Tags.Origins.Remote).withTag(Tags.SpliceType, Tags.SpliceTypes.SpliceOut).record(sharedTx.remoteOutputs.map(_.amount).sum.toLong)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import fr.acinq.eclair.blockchain.fee.FeeratePerKw
import fr.acinq.eclair.channel.Helpers.Closing.MutualClose
import fr.acinq.eclair.channel.Helpers.Funding
import fr.acinq.eclair.channel._
import fr.acinq.eclair.channel.fund.InteractiveTxBuilder.Output.Local
import fr.acinq.eclair.channel.fund.InteractiveTxBuilder.Purpose
import fr.acinq.eclair.channel.fund.InteractiveTxSigningSession.UnsignedLocalCommit
import fr.acinq.eclair.crypto.keymanager.ChannelKeyManager
Expand Down Expand Up @@ -290,6 +291,8 @@ object InteractiveTxBuilder {
// Note that the truncation is a no-op: sub-satoshi balances are carried over from inputs to outputs and cancel out.
val fees: Satoshi = (localFees + remoteFees).truncateToSatoshi

def localOnlyNonChangeOutputs: List[Output.Local.NonChange] = localOutputs.collect { case o: Local.NonChange => o }

def buildUnsignedTx(): Transaction = {
val sharedTxIn = sharedInput_opt.map(i => (i.serialId, TxIn(i.outPoint, ByteVector.empty, i.sequence))).toSeq
val localTxIn = localInputs.map(i => (i.serialId, TxIn(i.outPoint, ByteVector.empty, i.sequence)))
Expand Down

0 comments on commit db8e0f9

Please sign in to comment.