@@ -856,7 +856,7 @@ case class Commitments(params: ChannelParams,
856
856
* @param cmd add HTLC command
857
857
* @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)
858
858
*/
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 )] = {
860
860
// we must ensure we're not relaying htlcs that are already expired, otherwise the downstream channel will instantly close
861
861
// NB: we add a 3 blocks safety to reduce the probability of running into this when our bitcoin node is slightly outdated
862
862
val minExpiry = CltvExpiry (currentHeight + 3 )
@@ -880,20 +880,28 @@ case class Commitments(params: ChannelParams,
880
880
val changes1 = changes.addLocalProposal(add).copy(localNextHtlcId = changes.localNextHtlcId + 1 )
881
881
val originChannels1 = originChannels + (add.id -> cmd.origin)
882
882
// 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)
885
888
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.
890
894
case Left (_ : TooManySmallHtlcs ) | Left (_ : ConfidenceTooLow ) => None
891
895
case x => Some (x)
892
896
}
897
+ .collectFirst { case Left (f) =>
898
+ Metrics .dropHtlc(f, Tags .Directions .Outgoing )
899
+ Left (f)
900
+ }
893
901
.getOrElse(Right (copy(changes = changes1, originChannels = originChannels1), add))
894
902
}
895
903
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 ] = {
897
905
if (add.id != changes.remoteNextHtlcId) {
898
906
return Left (UnexpectedHtlcId (channelId, expected = changes.remoteNextHtlcId, actual = add.id))
899
907
}
@@ -906,16 +914,21 @@ case class Commitments(params: ChannelParams,
906
914
907
915
val changes1 = changes.addRemoteProposal(add).copy(remoteNextHtlcId = changes.remoteNextHtlcId + 1 )
908
916
// 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)
911
922
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.
916
925
case Left (_ : TooManySmallHtlcs ) | Left (_ : ConfidenceTooLow ) => None
917
926
case x => Some (x)
918
927
}
928
+ .collectFirst { case Left (f) =>
929
+ Metrics .dropHtlc(f, Tags .Directions .Incoming )
930
+ Left (f)
931
+ }
919
932
.getOrElse(Right (copy(changes = changes1)))
920
933
}
921
934
0 commit comments