@@ -856,7 +856,7 @@ case class Commitments(params: ChannelParams,
856856 * @param cmd add HTLC command
857857 * @return either Left(failure, error message) where failure is a failure message (see BOLT #4 and the Failure Message class) or Right(new commitments, updateAddHtlc)
858858 */
859- def sendAdd (cmd : CMD_ADD_HTLC , currentHeight : BlockHeight , channelConf : ChannelConf , feerates : FeeratesPerKw , feeConf : OnChainFeeConf ): Either [ChannelException , (Commitments , UpdateAddHtlc )] = {
859+ def sendAdd (cmd : CMD_ADD_HTLC , currentHeight : BlockHeight , channelConf : ChannelConf , feerates : FeeratesPerKw , feeConf : OnChainFeeConf )( implicit log : LoggingAdapter ) : Either [ChannelException , (Commitments , UpdateAddHtlc )] = {
860860 // we must ensure we're not relaying htlcs that are already expired, otherwise the downstream channel will instantly close
861861 // NB: we add a 3 blocks safety to reduce the probability of running into this when our bitcoin node is slightly outdated
862862 val minExpiry = CltvExpiry (currentHeight + 3 )
@@ -880,20 +880,28 @@ case class Commitments(params: ChannelParams,
880880 val changes1 = changes.addLocalProposal(add).copy(localNextHtlcId = changes.localNextHtlcId + 1 )
881881 val originChannels1 = originChannels + (add.id -> cmd.origin)
882882 // we verify that this htlc is allowed in every active commitment
883- active.map(_.canSendAdd(add.amountMsat, params, changes1, feerates, feeConf, cmd.confidence))
884- .collectFirst { case Left (f) =>
883+ val canSendAdds = active.map(_.canSendAdd(add.amountMsat, params, changes1, feerates, feeConf, cmd.confidence))
884+ // Log only for jamming protection.
885+ canSendAdds.collectFirst {
886+ case Left (f : TooManySmallHtlcs ) =>
887+ log.info(" TooManySmallHtlcs: {} outgoing HTLCs are below {}}" , f.number, f.below)
885888 Metrics .dropHtlc(f, Tags .Directions .Outgoing )
886- Left (f)
887- }
888- // TODO: Delete these lines to activate jamming protections
889- .flatMap {
889+ case Left (f : ConfidenceTooLow ) =>
890+ log.info(" ConfidenceTooLow: confidence is {}% while channel is {}% full" , (100 * f.confidence).toInt, (100 * f.occupancy).toInt)
891+ Metrics .dropHtlc(f, Tags .Directions .Outgoing )
892+ }
893+ canSendAdds.flatMap { // TODO: We ignore jamming protection, delete this flatMap to activate jamming protection.
890894 case Left (_ : TooManySmallHtlcs ) | Left (_ : ConfidenceTooLow ) => None
891895 case x => Some (x)
892896 }
897+ .collectFirst { case Left (f) =>
898+ Metrics .dropHtlc(f, Tags .Directions .Outgoing )
899+ Left (f)
900+ }
893901 .getOrElse(Right (copy(changes = changes1, originChannels = originChannels1), add))
894902 }
895903
896- def receiveAdd (add : UpdateAddHtlc , feerates : FeeratesPerKw , feeConf : OnChainFeeConf ): Either [ChannelException , Commitments ] = {
904+ def receiveAdd (add : UpdateAddHtlc , feerates : FeeratesPerKw , feeConf : OnChainFeeConf )( implicit log : LoggingAdapter ) : Either [ChannelException , Commitments ] = {
897905 if (add.id != changes.remoteNextHtlcId) {
898906 return Left (UnexpectedHtlcId (channelId, expected = changes.remoteNextHtlcId, actual = add.id))
899907 }
@@ -906,16 +914,21 @@ case class Commitments(params: ChannelParams,
906914
907915 val changes1 = changes.addRemoteProposal(add).copy(remoteNextHtlcId = changes.remoteNextHtlcId + 1 )
908916 // we verify that this htlc is allowed in every active commitment
909- active.map(_.canReceiveAdd(add.amountMsat, params, changes1, feerates, feeConf))
910- .collectFirst { case Left (f) =>
917+ val canReceiveAdds = active.map(_.canReceiveAdd(add.amountMsat, params, changes1, feerates, feeConf))
918+ // Log only for jamming protection.
919+ canReceiveAdds.collectFirst {
920+ case Left (f : TooManySmallHtlcs ) =>
921+ log.info(" TooManySmallHtlcs: {} incoming HTLCs are below {}}" , f.number, f.below)
911922 Metrics .dropHtlc(f, Tags .Directions .Incoming )
912- Left (f)
913- }
914- // TODO: Delete these lines to activate jamming protections
915- .flatMap {
923+ }
924+ canReceiveAdds.flatMap { // TODO: We ignore jamming protection, delete this flatMap to activate jamming protection.
916925 case Left (_ : TooManySmallHtlcs ) | Left (_ : ConfidenceTooLow ) => None
917926 case x => Some (x)
918927 }
928+ .collectFirst { case Left (f) =>
929+ Metrics .dropHtlc(f, Tags .Directions .Incoming )
930+ Left (f)
931+ }
919932 .getOrElse(Right (copy(changes = changes1)))
920933 }
921934
0 commit comments