-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Channels data format migration (#1849)
There are three otherwise unrelated changes, that we group together to only have one migration: - remove local signatures for local commitments (this PR) - separate internal channel config from channel features (#1848) - upfront shutdown script (#1846) We increase database version number in sqlite and postgres to force a full data migration. The goal of removing local signatures from the channel data is that even if the node database or a backup is compromised, the attacker won't be able to force close channels from the outside.
- Loading branch information
Showing
57 changed files
with
1,740 additions
and
860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 49 additions & 47 deletions
96
eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala
Large diffs are not rendered by default.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2021 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.channel | ||
|
||
/** | ||
* Created by t-bast on 24/06/2021. | ||
*/ | ||
|
||
/** | ||
* Internal configuration option impacting the channel's structure or behavior. | ||
* This must be set when creating the channel and cannot be changed afterwards. | ||
*/ | ||
trait ChannelConfigOption { | ||
// @formatter:off | ||
def supportBit: Int | ||
def name: String | ||
// @formatter:on | ||
} | ||
|
||
case class ChannelConfig(options: Set[ChannelConfigOption]) { | ||
|
||
def hasOption(option: ChannelConfigOption): Boolean = options.contains(option) | ||
|
||
} | ||
|
||
object ChannelConfig { | ||
|
||
val standard: ChannelConfig = ChannelConfig(options = Set(FundingPubKeyBasedChannelKeyPath)) | ||
|
||
def apply(opts: ChannelConfigOption*): ChannelConfig = ChannelConfig(Set.from(opts)) | ||
|
||
/** | ||
* If set, the channel's BIP32 key path will be deterministically derived from the funding public key. | ||
* It makes it very easy to retrieve funds when channel data has been lost: | ||
* - connect to your peer and use option_data_loss_protect to get them to publish their remote commit tx | ||
* - retrieve the commit tx from the bitcoin network, extract your funding pubkey from its witness data | ||
* - recompute your channel keys and spend your output | ||
*/ | ||
case object FundingPubKeyBasedChannelKeyPath extends ChannelConfigOption { | ||
override val supportBit: Int = 0 | ||
override val name: String = "funding_pubkey_based_channel_keypath" | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelFeatures.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2021 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.channel | ||
|
||
import fr.acinq.eclair.Features.{AnchorOutputs, StaticRemoteKey, Wumbo} | ||
import fr.acinq.eclair.transactions.Transactions.{AnchorOutputsCommitmentFormat, CommitmentFormat, DefaultCommitmentFormat} | ||
import fr.acinq.eclair.{Feature, Features} | ||
|
||
/** | ||
* Created by t-bast on 24/06/2021. | ||
*/ | ||
|
||
/** | ||
* Subset of Bolt 9 features used to configure a channel and applicable over the lifetime of that channel. | ||
* Even if one of these features is later disabled at the connection level, it will still apply to the channel until the | ||
* channel is upgraded or closed. | ||
*/ | ||
case class ChannelFeatures(activated: Set[Feature]) { | ||
|
||
/** True if our main output in the remote commitment is directly sent (without any delay) to one of our wallet addresses. */ | ||
val paysDirectlyToWallet: Boolean = { | ||
hasFeature(Features.StaticRemoteKey) && !hasFeature(Features.AnchorOutputs) | ||
} | ||
|
||
/** Format of the channel transactions. */ | ||
val commitmentFormat: CommitmentFormat = { | ||
if (hasFeature(AnchorOutputs)) { | ||
AnchorOutputsCommitmentFormat | ||
} else { | ||
DefaultCommitmentFormat | ||
} | ||
} | ||
|
||
def hasFeature(feature: Feature): Boolean = activated.contains(feature) | ||
|
||
override def toString: String = activated.mkString(",") | ||
|
||
} | ||
|
||
object ChannelFeatures { | ||
|
||
def apply(features: Feature*): ChannelFeatures = ChannelFeatures(Set.from(features)) | ||
|
||
/** Pick the channel features that should be used based on local and remote feature bits. */ | ||
def pickChannelFeatures(localFeatures: Features, remoteFeatures: Features): ChannelFeatures = { | ||
// NB: we don't include features that can be safely activated/deactivated without impacting the channel's operation, | ||
// such as option_dataloss_protect or option_shutdown_anysegwit. | ||
val availableFeatures = Set[Feature]( | ||
StaticRemoteKey, | ||
Wumbo, | ||
AnchorOutputs, | ||
).filter(f => Features.canUseFeature(localFeatures, remoteFeatures, f)) | ||
|
||
ChannelFeatures(availableFeatures) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.