order: introduce channel type field

Previously, the channel type was being recorded by the auctioneer only,
but there was no way for a trader to set its preference. Now that we
want to support that, we move the ChannelType definition to the Pool
source code, as done in this commit.

As part of introducing this new field, a new version bump was required
to compute the proper digest of each order.

To remain backwards compatible, we define the default channel type to be
"peer dependent". This implies that the channel type will vary based on
the node features shared between the asker and bidder. We also define a
new channel type to denote that channels resulting from matched orders
must have their lease expiration enforced in the scripts of their
commitment transactions.
This commit is contained in:
Wilmer Paulino 2021-07-26 15:57:21 -07:00 committed by Olaoluwa Osuntokun
parent f566f3ad74
commit f7dce585ba
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -59,6 +59,11 @@ const (
// accounting or whatever) can opt out by explicitly submitting their
// ask orders with a version previous to this one.
VersionSidecarChannel Version = 4
// VersionChannelType is the order version that added use of the channel
// type field. Only orders with this version are allowed to use the
// channel type field.
VersionChannelType Version = 5
)
// Type is the type of an order. We don't use iota for the constants due to the
@ -216,6 +221,24 @@ func (s MatchState) String() string {
}
}
// ChannelType is a numerical type that represents all possible channel types
// that are supported to be opened through the auction process.
type ChannelType uint8
// NOTE: We avoid the use of iota as this type is stored on disk.
const (
// ChannelTypePeerDependent denotes that the resulting channel type from
// an order match will depend on the shared features between its
// participants.
ChannelTypePeerDependent ChannelType = 0
// ChannelTypeScriptEnforced represents a new channel type that builds
// upon the anchors commitment format to enforce the maturity of a
// leased channel in the commitment and HTLC outputs that pay directly
// to the channel initiator.
ChannelTypeScriptEnforced ChannelType = 1
)
var (
// ErrInsufficientBalance is the error that is returned if an account
// has insufficient balance to perform a requested action.
@ -305,6 +328,10 @@ type Kit struct {
// MinUnitsMatch signals the minimum number of units that must be
// matched against an order.
MinUnitsMatch SupplyUnit
// ChannelType denotes the channel type that must be used for the
// resulting matched channels.
ChannelType ChannelType
}
// Nonce is the unique identifier of each order and MUST be created by hashing a
@ -391,6 +418,16 @@ func (a *Ask) Digest() ([sha256.Size]byte, error) {
return result, err
}
case VersionChannelType:
err := lnwire.WriteElements(
&msg, a.nonce[:], uint32(a.Version), a.FixedRate,
a.Amt, a.LeaseDuration, uint64(a.MaxBatchFeeRate),
uint32(a.MinUnitsMatch), uint8(a.ChannelType),
)
if err != nil {
return result, err
}
default:
return result, fmt.Errorf("unknown version %d", a.Kit.Version)
}
@ -605,6 +642,23 @@ func (b *Bid) Digest() ([sha256.Size]byte, error) {
return result, err
}
case VersionChannelType:
var isSidecar uint8
if b.SidecarTicket != nil {
isSidecar = 1
}
err := lnwire.WriteElements(
&msg, b.nonce[:], uint32(b.Version), b.FixedRate,
b.Amt, b.LeaseDuration, uint64(b.MaxBatchFeeRate),
uint32(b.MinNodeTier), uint32(b.MinUnitsMatch),
uint64(b.SelfChanBalance), isSidecar,
uint8(b.ChannelType),
)
if err != nil {
return result, err
}
default:
return result, fmt.Errorf("unknown version %d", b.Kit.Version)
}