-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Design Doc for Dynamic Commitments #10076
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
Open
yyforyongyu
wants to merge
3
commits into
lightningnetwork:yy-dyn
Choose a base branch
from
yyforyongyu:yy-design-dyn
base: yy-dyn
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dyn | ||
|
||
import ( | ||
"github.com/btcsuite/btclog/v2" | ||
"github.com/lightningnetwork/lnd/build" | ||
) | ||
|
||
// log is a logger that is initialized with no output filters. This means the | ||
// package will not perform any logging by default until the caller requests it. | ||
var log btclog.Logger | ||
|
||
// Subsystem defines the logging code for this subsystem. | ||
const Subsystem = "DYNC" | ||
|
||
// The default amount of logging is none. | ||
func init() { | ||
logger := build.NewSubLogger(Subsystem, nil) | ||
|
||
UseLogger(logger) | ||
} | ||
|
||
// DisableLog disables all library log output. Logging output is disabled by | ||
// default until UseLogger is called. | ||
func DisableLog() { | ||
UseLogger(btclog.Disabled) | ||
} | ||
|
||
// UseLogger uses a specified Logger to output package logging info. This should | ||
// be used in preference to SetLogWriter if the caller is also using btclog. | ||
func UseLogger(logger btclog.Logger) { | ||
log = logger | ||
} |
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package dyn | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/btcutil" | ||
"github.com/lightningnetwork/lnd/fn/v2" | ||
"github.com/lightningnetwork/lnd/lnwire" | ||
) | ||
|
||
// UpdateLinkStatus is used in the `UpdateLinkResponse` to indicate the current | ||
// status of a given update request. | ||
type UpdateLinkStatus uint8 | ||
|
||
const ( | ||
// UpdateLinkStatusInitialized is the status the update flow is in when | ||
// the request is received by the Updater. | ||
UpdateLinkStatusInitialized UpdateLinkStatus = iota | ||
|
||
// UpdateLinkStatusPending defines the status when the request is being | ||
// processed by the Updater. | ||
UpdateLinkStatusPending | ||
|
||
// UpdateLinkStatusSucceeded defines the status when the update finished | ||
// successfully. | ||
UpdateLinkStatusSucceeded | ||
|
||
// UpdateLinkStatusFailed defines the status when the update failed. | ||
UpdateLinkStatusFailed | ||
) | ||
|
||
// String returns a human readable string that represents the status. | ||
func (u UpdateLinkStatus) String() string { | ||
switch u { | ||
case UpdateLinkStatusInitialized: | ||
return "Initialized" | ||
|
||
case UpdateLinkStatusPending: | ||
return "Pending" | ||
|
||
case UpdateLinkStatusSucceeded: | ||
return "Succeeded" | ||
|
||
case UpdateLinkStatusFailed: | ||
return "Failed" | ||
|
||
default: | ||
return "Unknown" | ||
} | ||
} | ||
|
||
// UpdateLinkRequest defines a request that contains the channel params to be | ||
// changed. | ||
type UpdateLinkRequest struct { | ||
// ChanID identifies the channel link to be updated. | ||
ChanID lnwire.ChannelID | ||
|
||
// DustLimit is the threshold (in satoshis) below which any outputs | ||
// should be trimmed. When an output is trimmed, it isn't materialized | ||
// as an actual output, but is instead burned to miner's fees. | ||
DustLimit fn.Option[btcutil.Amount] | ||
|
||
// MaxPendingAmount is the maximum pending HTLC value that the | ||
// owner of these constraints can offer the remote node at a | ||
// particular time. | ||
MaxPendingAmount fn.Option[lnwire.MilliSatoshi] | ||
|
||
// ChanReserve is an absolute reservation on the channel for the | ||
// owner of this set of constraints. This means that the current | ||
// settled balance for this node CANNOT dip below the reservation | ||
// amount. This acts as a defense against costless attacks when | ||
// either side no longer has any skin in the game. | ||
ChanReserve fn.Option[btcutil.Amount] | ||
|
||
// MinHTLC is the minimum HTLC value that the owner of these | ||
// constraints can offer the remote node. If any HTLCs below this | ||
// amount are offered, then the HTLC will be rejected. This, in | ||
// tandem with the dust limit allows a node to regulate the | ||
// smallest HTLC that it deems economically relevant. | ||
MinHTLC fn.Option[lnwire.MilliSatoshi] | ||
|
||
// CsvDelay is the relative time lock delay expressed in blocks. Any | ||
// settled outputs that pay to the owner of this channel configuration | ||
// MUST ensure that the delay branch uses this value as the relative | ||
// time lock. Similarly, any HTLC's offered by this node should use | ||
// this value as well. | ||
CsvDelay fn.Option[uint16] | ||
|
||
// MaxAcceptedHtlcs is the maximum number of HTLCs that the owner of | ||
// this set of constraints can offer the remote node. This allows each | ||
// node to limit their over all exposure to HTLCs that may need to be | ||
// acted upon in the case of a unilateral channel closure or a contract | ||
// breach. | ||
MaxAcceptedHtlcs fn.Option[uint16] | ||
} | ||
|
||
// UpdateLinkResponse defines a response to be returned to the caller. | ||
type UpdateLinkResponse struct { | ||
// Status gives the current status of the update flow. | ||
Status UpdateLinkStatus | ||
|
||
// Err gives the details about a failed update request. | ||
Err error | ||
} | ||
|
||
// UpdateReq is a `fn.Req` type that wraps the request and response into a | ||
// single struct. | ||
type UpdateReq = fn.Req[UpdateLinkRequest, UpdateLinkResponse] | ||
|
||
// Updater defines an interface that is used to update the channel link params. | ||
// It provides the basic flow control methods like Start and Stop. In addition, | ||
// `InitReq` is used for the user to initialize an upgrade request flow, and | ||
// `ReceiveMsg` should be called in the link when a related msg is received, | ||
// such as DynProposal, DynAck, DynCommit, DynReject, CommitSig, and | ||
// RevokeAndAck. | ||
type Updater interface { | ||
// Start starts the updater so it can accept update requests. | ||
Start() | ||
|
||
// Stop stops the updater. | ||
Stop() | ||
|
||
// InitReq initializes a channel update request, which is used by the | ||
// user to start the update flow via RPC. | ||
InitReq(r *UpdateReq) error | ||
|
||
// ReceiveMsg takes a msg sent from the peer and processes it. | ||
ReceiveMsg(msg lnwire.Message) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
According to the style guide, function comments should begin with the function name and be a complete sentence explaining the function's purpose.1
The
init
function is a special function in Go, but it's good practice to document its purpose, especially in a library package.Style Guide References
Footnotes
The style guide requires every function to be commented with its purpose, and the comment must begin with the function name and be a complete sentence. (link) ↩