-
Notifications
You must be signed in to change notification settings - Fork 276
Handle fees increases when channel is OFFLINE #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8dc20b1
Add test for feerate increase in OfflineStateSpec
araspitzu fee9f52
Handle feerate changes when OFFLINE
araspitzu e98301f
Handle feerates in SYNCING, refactor feerate handlers
araspitzu 21dda40
Renaming, factor out `currentFeeratePerKw`
araspitzu f336104
Add log entry
araspitzu fcfacd9
Merge branch 'master' into handle_fees_while_offline
araspitzu e8d538f
Merge cleanup
araspitzu a3bf320
Merge branch 'master' into handle_fees_while_offline
araspitzu 84e33d7
Merge branch 'master' into handle_fees_while_offline
araspitzu 3000b63
Merge branch 'master' into handle_fees_while_offline
araspitzu 230c0a7
Fix log entry
araspitzu ba4e27a
Add 'close-on-offline-feerate-mismatch' configuration to avoid closin…
araspitzu beee05b
Update comment on config key, print log line when the fee mismatch is…
araspitzu 2e6a211
Update eclair-core/src/test/scala/fr/acinq/eclair/channel/states/e/Of…
araspitzu 3d6252c
Merge branch 'master' into handle_fees_while_offline
araspitzu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -852,15 +852,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId | |||||
| case Event(c: CurrentBlockCount, d: DATA_NORMAL) => handleNewBlock(c, d) | ||||||
|
|
||||||
| case Event(c@CurrentFeerates(feeratesPerKw), d: DATA_NORMAL) => | ||||||
| val networkFeeratePerKw = feeratesPerKw.feePerBlock(target = nodeParams.onChainFeeConf.feeTargets.commitmentBlockTarget) | ||||||
| d.commitments.localParams.isFunder match { | ||||||
| case true if Helpers.shouldUpdateFee(d.commitments.localCommit.spec.feeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.updateFeeMinDiffRatio) => | ||||||
| self ! CMD_UPDATE_FEE(networkFeeratePerKw, commit = true) | ||||||
| stay | ||||||
| case false if Helpers.isFeeDiffTooHigh(d.commitments.localCommit.spec.feeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.maxFeerateMismatch) => | ||||||
| handleLocalError(FeerateTooDifferent(d.channelId, localFeeratePerKw = networkFeeratePerKw, remoteFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw), d, Some(c)) | ||||||
| case _ => stay | ||||||
| } | ||||||
| handleCurrentFeerate(c, d) | ||||||
|
|
||||||
| case Event(WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, blockHeight, txIndex, _), d: DATA_NORMAL) if d.channelAnnouncement.isEmpty => | ||||||
| val shortChannelId = ShortChannelId(blockHeight, txIndex, d.commitments.commitInput.outPoint.index.toInt) | ||||||
|
|
@@ -1133,16 +1125,8 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId | |||||
|
|
||||||
| case Event(c: CurrentBlockCount, d: DATA_SHUTDOWN) => handleNewBlock(c, d) | ||||||
|
|
||||||
| case Event(c@CurrentFeerates(feeratesPerKw), d: DATA_SHUTDOWN) => | ||||||
| val networkFeeratePerKw = feeratesPerKw.feePerBlock(target = nodeParams.onChainFeeConf.feeTargets.commitmentBlockTarget) | ||||||
| d.commitments.localParams.isFunder match { | ||||||
| case true if Helpers.shouldUpdateFee(d.commitments.localCommit.spec.feeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.updateFeeMinDiffRatio) => | ||||||
| self ! CMD_UPDATE_FEE(networkFeeratePerKw, commit = true) | ||||||
| stay | ||||||
| case false if Helpers.isFeeDiffTooHigh(d.commitments.localCommit.spec.feeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.maxFeerateMismatch) => | ||||||
| handleLocalError(FeerateTooDifferent(d.channelId, localFeeratePerKw = networkFeeratePerKw, remoteFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw), d, Some(c)) | ||||||
| case _ => stay | ||||||
| } | ||||||
| case Event(c@CurrentFeerates(feerates), d: DATA_SHUTDOWN) => | ||||||
| handleCurrentFeerate(c, d) | ||||||
|
|
||||||
| case Event(WatchEventSpent(BITCOIN_FUNDING_SPENT, tx), d: DATA_SHUTDOWN) if tx.txid == d.commitments.remoteCommit.txid => handleRemoteSpentCurrent(tx, d) | ||||||
|
|
||||||
|
|
@@ -1425,6 +1409,9 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId | |||||
| // -> in CLOSING we either have mutual closed (so no more htlcs), or already have unilaterally closed (so no action required), and we can't be in OFFLINE state anyway | ||||||
| case Event(c: CurrentBlockCount, d: HasCommitments) => handleNewBlock(c, d) | ||||||
|
|
||||||
| case Event(c: CurrentFeerates, d: HasCommitments) => | ||||||
| handleOfflineFeerate(c, d) | ||||||
|
|
||||||
| case Event(c: CMD_ADD_HTLC, d: DATA_NORMAL) => handleAddDisconnected(c, d) | ||||||
|
|
||||||
| case Event(CMD_UPDATE_RELAY_FEE(feeBaseMsat, feeProportionalMillionths), d: DATA_NORMAL) => | ||||||
|
|
@@ -1559,6 +1546,9 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId | |||||
|
|
||||||
| case Event(c: CurrentBlockCount, d: HasCommitments) => handleNewBlock(c, d) | ||||||
|
|
||||||
| case Event(c: CurrentFeerates, d: HasCommitments) => | ||||||
| handleOfflineFeerate(c, d) | ||||||
|
|
||||||
| case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.commitInput.outPoint.txid => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx) | ||||||
|
|
||||||
| case Event(BITCOIN_FUNDING_PUBLISH_FAILED, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => handleFundingPublishFailed(d) | ||||||
|
|
@@ -1728,6 +1718,37 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId | |||||
| origin_opt.foreach(_ ! m) | ||||||
| } | ||||||
|
|
||||||
| def handleCurrentFeerate(c: CurrentFeerates, d: HasCommitments) = { | ||||||
| val networkFeeratePerKw = c.feeratesPerKw.feePerBlock(target = nodeParams.onChainFeeConf.feeTargets.commitmentBlockTarget) | ||||||
| val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw | ||||||
| d.commitments.localParams.isFunder match { | ||||||
| case true if Helpers.shouldUpdateFee(currentFeeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.updateFeeMinDiffRatio) => | ||||||
| self ! CMD_UPDATE_FEE(networkFeeratePerKw, commit = true) | ||||||
| stay | ||||||
| case false if Helpers.isFeeDiffTooHigh(currentFeeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.maxFeerateMismatch) => | ||||||
| handleLocalError(FeerateTooDifferent(d.channelId, localFeeratePerKw = networkFeeratePerKw, remoteFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw), d, Some(c)) | ||||||
| case _ => stay | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * This is used to check for the commitment fees when the channel is not operational but we have something at stake | ||||||
| * @param c the new feerates | ||||||
| * @param d the channel commtiments | ||||||
| * @return | ||||||
| */ | ||||||
| def handleOfflineFeerate(c: CurrentFeerates, d: HasCommitments) = { | ||||||
| val networkFeeratePerKw = c.feeratesPerKw.feePerBlock(target = nodeParams.onChainFeeConf.feeTargets.commitmentBlockTarget) | ||||||
| val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw | ||||||
| // if the fees are too high we risk to not be able to confirm our current commitment | ||||||
| if(networkFeeratePerKw > currentFeeratePerKw && Helpers.isFeeDiffTooHigh(currentFeeratePerKw, networkFeeratePerKw, nodeParams.onChainFeeConf.maxFeerateMismatch)){ | ||||||
| log.warning(s"closing OFFLINE ${d.channelId} due fee mismatch: currentFeeratePerKw=$currentFeeratePerKw networkFeeratePerKw=$networkFeeratePerKw") | ||||||
|
||||||
| log.warning(s"closing OFFLINE ${d.channelId} due fee mismatch: currentFeeratePerKw=$currentFeeratePerKw networkFeeratePerKw=$networkFeeratePerKw") | |
| log.warning(s"closing OFFLINE ${d.channelId} due to fee mismatch: currentFeeratePerKw=$currentFeeratePerKw networkFeeratePerKw=$networkFeeratePerKw") |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.