Skip to content
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

RFQ cleanup #1124

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions rfqmsg/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rfqmsg

import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -391,33 +390,3 @@ func IdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {

return tlv.NewTypeForDecodingErr(val, "MessageID", l, idBytesLen)
}

func AssetIdEncoder(w io.Writer, val any, buf *[8]byte) error {
if t, ok := val.(**asset.ID); ok {
id := [sha256.Size]byte(**t)
return tlv.EBytes32(w, &id, buf)
}

return tlv.NewTypeForEncodingErr(val, "assetId")
}

func AssetIdDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
const assetIDBytesLen = sha256.Size

if typ, ok := val.(**asset.ID); ok {
var idBytes [assetIDBytesLen]byte

err := tlv.DBytes32(r, &idBytes, buf, assetIDBytesLen)
if err != nil {
return err
}

id := asset.ID(idBytes)
assetId := &id

*typ = assetId
return nil
}

return tlv.NewTypeForDecodingErr(val, "assetId", l, sha256.Size)
}
14 changes: 0 additions & 14 deletions rfqmsg/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ var (
Code: 1,
Msg: "price oracle unavailable",
}

// ErrNoSuitableSellOffer is the error code for when there is no
// suitable sell offer available.
ErrNoSuitableSellOffer = RejectErr{
Code: 2,
Msg: "no suitable sell offer available",
}

// ErrNoSuitableBuyOffer is the error code for when there is no suitable
// buy offer available.
ErrNoSuitableBuyOffer = RejectErr{
Code: 3,
Msg: "no suitable buy offer available",
}
)

const (
Expand Down
10 changes: 8 additions & 2 deletions rfqmsg/reject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ func TestRejectEncodeDecode(t *testing.T) {
peer: route.Vertex{1, 2, 3},
version: 0,
id: id,
err: ErrNoSuitableSellOffer,
},
{
testName: "all fields populated with basic values",
peer: route.Vertex{1, 2, 3},
version: 5,
id: id,
err: ErrNoSuitableBuyOffer,
},
{
testName: "all fields populated with basic values; " +
"error field populated",
peer: route.Vertex{1, 2, 3},
version: 5,
id: id,
err: ErrPriceOracleUnavailable,
},
}

Expand Down
9 changes: 1 addition & 8 deletions rfqmsg/sell_accept.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rfqmsg

import (
"encoding/binary"
"fmt"

"github.com/lightningnetwork/lnd/lnwire"
Expand Down Expand Up @@ -94,13 +93,7 @@ func newSellAcceptFromWireMsg(wireMsg WireMessage,
// ShortChannelId returns the short channel ID associated with the asset sale
// event.
func (q *SellAccept) ShortChannelId() SerialisedScid {
// Given valid RFQ message id, we then define a RFQ short chain id
// (SCID) by taking the last 8 bytes of the RFQ message id and
// interpreting them as a 64-bit integer.
scidBytes := q.ID[24:]

scidInteger := binary.BigEndian.Uint64(scidBytes)
return SerialisedScid(scidInteger)
return q.ID.Scid()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for commit message:

This code should be relevant for generating RFQ scids within range: lnd/aliasmgr/aliasmgr.go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have that code in a WIP branch (lnd-0-19-staging-rebased already:

minBlock := uint32(aliasmgr.AliasStartBlockHeight)

}

// ToWire returns a wire message with a serialized data field.
Expand Down
Loading