Skip to content

Commit

Permalink
Update confirmation scaling factor post-halving
Browse files Browse the repository at this point in the history
We were still using values from before the halving. We update those
values and change the scaling factor to a reasonable scaling. This
protects channels against attackers with significant mining power.
  • Loading branch information
t-bast committed Dec 19, 2024
1 parent c390560 commit 825ca9b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ object ChannelParams {
// small amount: not scaled
defaultMinDepth
} else {
val blockReward = 6.25 // this is true as of ~May 2020, but will be too large after 2024
val scalingFactor = 15
val blockReward = 3.125 // this will be too large after the halving in 2028
val scalingFactor = 10
val blocksToReachFunding = (((scalingFactor * amount.toBtc.toDouble) / blockReward).ceil + 1).toInt
defaultMinDepth.max(blocksToReachFunding)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class HelpersSpec extends TestKitBaseClass with AnyFunSuiteLike with ChannelStat
implicit val log: akka.event.LoggingAdapter = akka.event.NoLogging

test("scale funding tx min depth according to funding amount") {
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(1)) == 4)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 6, Btc(1)) == 6) // 4 conf would be enough but we use min-depth=6
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(6.25)) == 16) // we use scaling_factor=15 and a fixed block reward of 6.25BTC
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(12.5)) == 31)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(12.6)) == 32)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(30)) == 73)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(50)) == 121)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(1)) == 5)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 6, Btc(1)) == 6) // 5 conf would be enough but we use min-depth=6
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(3.125)) == 11) // we use scaling_factor=10 and a fixed block reward of 3.125BTC
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(6.25)) == 21)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(10)) == 33)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(25)) == 81)
assert(ChannelParams.minDepthScaled(defaultMinDepth = 3, Btc(50)) == 161)
}

test("compute refresh delay") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class WaitForAcceptChannelStateSpec extends TestKitBaseClass with FixtureAnyFunS
test("recv AcceptChannel (large channel)", Tag(LargeChannel)) { f =>
import f._
val accept = bob2alice.expectMsgType[AcceptChannel]
assert(accept.minimumDepth == 13) // with large channel tag we create a 5BTC channel
assert(accept.minimumDepth == 17) // with large channel tag we create a 5BTC channel
bob2alice.forward(alice, accept)
awaitCond(alice.stateName == WAIT_FOR_FUNDING_INTERNAL)
aliceOpenReplyTo.expectNoMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ class StandardChannelIntegrationSpec extends ChannelIntegrationSpec {
fundeeState == WAIT_FOR_FUNDING_CONFIRMED && funderState == WAIT_FOR_CHANNEL_READY
}, max = 30 seconds, interval = 10 seconds)

// 5 extra blocks make it 13, just the amount of confirmations needed
generateBlocks(5)
// 10 extra blocks make it 18, which should be enough confirmations
generateBlocks(10)

awaitCond({
fundee.register ! Register.Forward(sender.ref.toTyped[Any], channelId, CMD_GET_CHANNEL_STATE(ActorRef.noSender))
Expand Down

0 comments on commit 825ca9b

Please sign in to comment.