sidecar: add multisig key index and lease duration

For proper and safe channel acceptance the recipient node also needs to
know which key index it used for a ticket's multisig key so it can sign
the authentication flow with the auctioneer correctly (which takes a key
locator and not key descriptor).

To make the offer and sidecar contract more explicit, we also include
the lease duration in blocks in the offer part. This field will
overwrite any value set when using the CLI to submit the bid order.
This commit is contained in:
Oliver Gugger 2021-03-19 11:50:01 +01:00
parent b81cd319b2
commit 363ddd5a8e
No known key found for this signature in database
GPG key ID: 8E4256593F177720
3 changed files with 45 additions and 21 deletions

View file

@ -9,15 +9,15 @@ import (
)
var (
hardcodedTicket = "sidecarAAQgHBgUEAwIBAAIBYwMBAgp5CwgAAAAAAAADCQwIAA" +
"AAAAAAA3gNIQLVLm5gAB7Vh7eEvz8Y3CkF2DsvNuSWJj8oOxp1iSh5xw5AAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAFhRGFSEC1S5uYAAe1Ye3hL8_GNwpBdg7Lzbkli" +
"Y_KDsadYkoeccWIQMZ1hb2o3OyT-XUX7KWS-pAVBloIPQe8aCTqcjiNOV89x" +
"5kHyALFiEsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
"AAAAAAAAAAAAAAISgiKSBjWE0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
"AAAA3VE-c="
hardcodedTicket = "sidecarAAQgHBgUEAwIBAAIBYwMBAgp_CwgAAAAAAAADCQwIAA" +
"AAAAAAA3gNBAAAB-AOIQLVLm5gAB7Vh7eEvz8Y3CkF2DsvNuSWJj8oOxp1iS" +
"h5xw9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhRMFSEC1S5uYAAe1Ye3hL8_GNwpBd" +
"g7LzbkliY_KDsadYkoeccWIQMZ1hb2o3OyT-XUX7KWS-pAVBloIPQe8aCTqc" +
"jiNOV89xcEAAAAAB5kHyALFiEsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
"AAACBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAISgiKSBjWE0AAAAAAAAAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAHcU6Y4="
)
// TestEncodeDecode tests that a ticket can be encoded and decoded from/to a
@ -29,9 +29,10 @@ func TestEncodeDecode(t *testing.T) {
Version: Version(99),
State: StateRegistered,
Offer: Offer{
Capacity: 777,
PushAmt: 888,
SignPubKey: testPubKey,
Capacity: 777,
PushAmt: 888,
LeaseDurationBlocks: 2016,
SignPubKey: testPubKey,
SigOfferDigest: &btcec.Signature{
R: new(big.Int).SetInt64(44),
S: new(big.Int).SetInt64(22),

View file

@ -102,6 +102,10 @@ type Offer struct {
// reduce the matching chances somewhat.
PushAmt btcutil.Amount
// LeaseDurationBlocks is the number of blocks the offered channel in
// this offer would be leased for.
LeaseDurationBlocks uint32
// SignPubKey is the public key for corresponding to the private key
// that signed the SigOfferDigest below and, in a later state, the
// SigOrderDigest of the Order struct.
@ -124,6 +128,9 @@ type Recipient struct {
// multisig keys of the channel funding transaction output and is
// advertised in the bid order.
MultiSigPubKey *btcec.PublicKey
// MultiSigKeyIndex is the derivation index of the MultiSigPubKey.
MultiSigKeyIndex uint32
}
// Order is a struct holding the information about the sidecar bid order after
@ -189,15 +196,16 @@ type Ticket struct {
// NewTicket creates a new sidecar ticket with the given version and offer
// information.
func NewTicket(version Version, capacity, pushAmt btcutil.Amount,
offerPubKey *btcec.PublicKey) (*Ticket, error) {
duration uint32, offerPubKey *btcec.PublicKey) (*Ticket, error) {
t := &Ticket{
Version: version,
State: StateOffered,
Offer: Offer{
Capacity: capacity,
PushAmt: pushAmt,
SignPubKey: offerPubKey,
Capacity: capacity,
PushAmt: pushAmt,
LeaseDurationBlocks: duration,
SignPubKey: offerPubKey,
},
}

View file

@ -19,12 +19,14 @@ const (
offerType tlv.Type = 10
capacityType tlv.Type = 11
pushAmtType tlv.Type = 12
signPubKeyType tlv.Type = 13
sigOfferDigestType tlv.Type = 14
leaseDurationType tlv.Type = 13
signPubKeyType tlv.Type = 14
sigOfferDigestType tlv.Type = 15
recipientType tlv.Type = 20
nodePubKeyType tlv.Type = 21
multiSigPubKeyType tlv.Type = 22
recipientType tlv.Type = 20
nodePubKeyType tlv.Type = 21
multiSigPubKeyType tlv.Type = 22
multiSigKeyIndexType tlv.Type = 23
orderType tlv.Type = 30
bidNonceType tlv.Type = 31
@ -177,6 +179,9 @@ func serializeOffer(o Offer) ([]byte, error) {
tlvRecords := []tlv.Record{
tlv.MakePrimitiveRecord(capacityType, &capacity),
tlv.MakePrimitiveRecord(pushAmtType, &pushAmt),
tlv.MakePrimitiveRecord(
leaseDurationType, &o.LeaseDurationBlocks,
),
}
if o.SignPubKey != nil {
@ -206,6 +211,9 @@ func deserializeOffer(offerBytes []byte) (Offer, error) {
offerBytes,
tlv.MakePrimitiveRecord(capacityType, &capacity),
tlv.MakePrimitiveRecord(pushAmtType, &pushAmt),
tlv.MakePrimitiveRecord(
leaseDurationType, &o.LeaseDurationBlocks,
),
tlv.MakePrimitiveRecord(signPubKeyType, &o.SignPubKey),
tlv.MakeStaticRecord(
sigOfferDigestType, &o.SigOfferDigest, 64, ESig, DSig,
@ -236,6 +244,10 @@ func serializeRecipient(r Recipient) ([]byte, error) {
))
}
tlvRecords = append(tlvRecords, tlv.MakePrimitiveRecord(
multiSigKeyIndexType, &r.MultiSigKeyIndex,
))
return encodeBytes(tlvRecords...)
}
@ -247,6 +259,9 @@ func deserializeRecipient(recipientBytes []byte) (Recipient, error) {
recipientBytes,
tlv.MakePrimitiveRecord(nodePubKeyType, &r.NodePubKey),
tlv.MakePrimitiveRecord(multiSigPubKeyType, &r.MultiSigPubKey),
tlv.MakePrimitiveRecord(
multiSigKeyIndexType, &r.MultiSigKeyIndex,
),
)
}