-
Notifications
You must be signed in to change notification settings - Fork 267
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
Handle fees increases when channel is OFFLINE #1080
Changes from 12 commits
8dc20b1
fee9f52
e98301f
21dda40
f336104
fcfacd9
e8d538f
a3bf320
84e33d7
3000b63
230c0a7
ba4e27a
beee05b
2e6a211
3d6252c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -854,15 +854,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) | ||
|
@@ -1135,16 +1127,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) | ||
|
||
|
@@ -1419,6 +1403,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) if nodeParams.onChainFeeConf.closeOnOfflineMismatch => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively we can do the check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's better, we want to see the warning even if we do nothing. |
||
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) => | ||
|
@@ -1553,6 +1540,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) if nodeParams.onChainFeeConf.closeOnOfflineMismatch => | ||
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) | ||
|
@@ -1722,6 +1712,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 | ||
pm47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 to fee mismatch: currentFeeratePerKw=$currentFeeratePerKw networkFeeratePerKw=$networkFeeratePerKw") | ||
handleLocalError(FeerateTooDifferent(d.channelId, localFeeratePerKw = currentFeeratePerKw, remoteFeeratePerKw = networkFeeratePerKw), d, Some(c)) | ||
} else { | ||
stay | ||
} | ||
} | ||
|
||
def handleCommandSuccess(sender: ActorRef, newData: Data) = { | ||
stay using newData replying "ok" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment adds much information. How about the good old "do not change this unless you know what you are doing" instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried my best :) but in fact this config key should be self explanatory, will add.