diff --git a/lnwire/funding_request.go b/lnwire/funding_request.go index 279acd4b..4c7ce715 100644 --- a/lnwire/funding_request.go +++ b/lnwire/funding_request.go @@ -46,7 +46,7 @@ type FundingRequest struct { // 2: channel responder FeePayer uint8 - RevocationHash [20]byte + RevocationHash [32]byte Pubkey *btcec.PublicKey DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH ChangePkScript PkScript // *MUST* be either P2PKH or P2SH diff --git a/lnwire/funding_request_test.go b/lnwire/funding_request_test.go index c5d3235e..345ab618 100644 --- a/lnwire/funding_request_test.go +++ b/lnwire/funding_request_test.go @@ -9,8 +9,6 @@ import ( ) func TestFundingRequestEncodeDecode(t *testing.T) { - copy(revocationHash[:], revocationHashBytes) - // funding request fr := &FundingRequest{ ReservationID: uint64(12345678), @@ -23,7 +21,7 @@ func TestFundingRequestEncodeDecode(t *testing.T) { FeePayer: uint8(0), PaymentAmount: btcutil.Amount(1234567), MinDepth: uint32(6), - RevocationHash: revocationHash, + RevocationHash: revHash, Pubkey: pubKey, DeliveryPkScript: deliveryPkScript, ChangePkScript: changePkScript, diff --git a/lnwire/funding_response.go b/lnwire/funding_response.go index 90416728..2f50041c 100644 --- a/lnwire/funding_response.go +++ b/lnwire/funding_response.go @@ -30,7 +30,7 @@ type FundingResponse struct { // 2: channel responder FeePayer uint8 - RevocationHash [20]byte + RevocationHash [32]byte Pubkey *btcec.PublicKey CommitSig *btcec.Signature // Requester's Commitment DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH diff --git a/lnwire/funding_response_test.go b/lnwire/funding_response_test.go index e3e35713..a7f526eb 100644 --- a/lnwire/funding_response_test.go +++ b/lnwire/funding_response_test.go @@ -21,7 +21,7 @@ func TestFundingResponseEncodeDecode(t *testing.T) { MinDepth: uint32(6), LockTime: uint32(4320), // 30 block-days FeePayer: uint8(1), - RevocationHash: revocationHash, + RevocationHash: revHash, Pubkey: pubKey, CommitSig: commitSig, DeliveryPkScript: deliveryPkScript, diff --git a/lnwire/htlc_addrequest.go b/lnwire/htlc_addrequest.go index dbbb421b..5b9dfa93 100644 --- a/lnwire/htlc_addrequest.go +++ b/lnwire/htlc_addrequest.go @@ -45,7 +45,7 @@ type HTLCAddRequest struct { // number of pre-images for each of the listed hashes. For regular HTLC's // this slice only has one hash. However, for "multi-sig" HTLC's, the // length of this slice should be N. - RedemptionHashes [][20]byte + RedemptionHashes [][32]byte // OnionBlob is the raw serialized mix header used to route an HTLC in // a privacy-preserving manner. The mix header is defined currently to @@ -78,7 +78,7 @@ func (c *HTLCAddRequest) Decode(r io.Reader, pver uint32) error { // Expiry(4) // Amount(4) // ContractType(1) - // RedemptionHashes (numOfHashes * 20 + numOfHashes) + // RedemptionHashes (numOfHashes * 32 + numOfHashes) // OnionBlog err := readElements(r, &c.ChannelPoint, diff --git a/lnwire/htlc_addrequest_test.go b/lnwire/htlc_addrequest_test.go index da8258ca..8558c61b 100644 --- a/lnwire/htlc_addrequest_test.go +++ b/lnwire/htlc_addrequest_test.go @@ -7,8 +7,8 @@ import ( ) func TestHTLCAddRequestEncodeDecode(t *testing.T) { - redemptionHashes := make([][20]byte, 1) - copy(redemptionHashes[0][:], bytes.Repeat([]byte{0x09}, 20)) + redemptionHashes := make([][32]byte, 1) + redemptionHashes[0] = revHash // First create a new HTLCAR message. addReq := &HTLCAddRequest{ diff --git a/lnwire/htlc_settlerequest.go b/lnwire/htlc_settlerequest.go index 0184f024..1b7c2bbf 100644 --- a/lnwire/htlc_settlerequest.go +++ b/lnwire/htlc_settlerequest.go @@ -21,17 +21,18 @@ type HTLCSettleRequest struct { // HTLCKey denotes the exact HTLC stage within the receiving node's // commitment transaction to be removed. + // TODO(roasbeef): rename to LogIndex HTLCKey HTLCKey // RedemptionProofs are the R-value preimages required to fully settle // an HTLC. The number of preimages in the slice will depend on the // specific ContractType of the referenced HTLC. - RedemptionProofs [][20]byte + RedemptionProofs [][32]byte } // NewHTLCSettleRequest returns a new empty HTLCSettleRequest. func NewHTLCSettleRequest(chanPoint *wire.OutPoint, key HTLCKey, - redemptionProofs [][20]byte) *HTLCSettleRequest { + redemptionProofs [][32]byte) *HTLCSettleRequest { return &HTLCSettleRequest{ ChannelPoint: chanPoint, @@ -51,7 +52,7 @@ var _ Message = (*HTLCSettleRequest)(nil) func (c *HTLCSettleRequest) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) // HTLCKey(8) - // RedemptionProofs(N*20) + // RedemptionProofs(N*32) err := readElements(r, &c.ChannelPoint, &c.HTLCKey, @@ -94,8 +95,8 @@ func (c *HTLCSettleRequest) Command() uint32 { // // This is part of the lnwire.Message interface. func (c *HTLCSettleRequest) MaxPayloadLength(uint32) uint32 { - // 36 + 8 + (21 * 15) - return 359 + // 36 + 8 + (32 * 15) + return 524 } // Validate performs any necessary sanity checks to ensure all fields present diff --git a/lnwire/htlc_settlerequest_test.go b/lnwire/htlc_settlerequest_test.go index 92d96d71..566c06d1 100644 --- a/lnwire/htlc_settlerequest_test.go +++ b/lnwire/htlc_settlerequest_test.go @@ -7,8 +7,8 @@ import ( ) func TestHTLCSettleRequestEncodeDecode(t *testing.T) { - redemptionProofs := make([][20]byte, 1) - copy(redemptionProofs[0][:], bytes.Repeat([]byte{0x09}, 20)) + redemptionProofs := make([][32]byte, 1) + redemptionProofs[0] = revHash // First create a new HTLCSR message. settleReq := NewHTLCSettleRequest(outpoint1, HTLCKey(23), redemptionProofs) diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index 08c4ffcd..8e6d1f06 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -169,7 +169,7 @@ func writeElement(w io.Writer, element interface{}) error { if _, err := w.Write(e[:]); err != nil { return err } - case [][20]byte: + case [][32]byte: // First write out the number of elements in the slice. sliceSize := len(e) if err := writeElement(w, uint16(sliceSize)); err != nil { @@ -182,7 +182,7 @@ func writeElement(w io.Writer, element interface{}) error { return err } } - case [20]byte: + case [32]byte: // TODO(roasbeef): should be factor out to caller logic... if _, err := w.Write(e[:]); err != nil { return err @@ -408,7 +408,7 @@ func readElement(r io.Reader, element interface{}) error { return err } *e = sig - case *[][20]byte: + case *[][32]byte: // How many to read var sliceSize uint16 err = readElement(r, &sliceSize) @@ -416,10 +416,10 @@ func readElement(r io.Reader, element interface{}) error { return err } - data := make([][20]byte, 0, sliceSize) + data := make([][32]byte, 0, sliceSize) // Append the actual for i := uint16(0); i < sliceSize; i++ { - var element [20]byte + var element [32]byte err = readElement(r, &element) if err != nil { return err @@ -427,7 +427,7 @@ func readElement(r io.Reader, element interface{}) error { data = append(data, element) } *e = data - case *[20]byte: + case *[32]byte: if _, err = io.ReadFull(r, e[:]); err != nil { return err } diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index d6a195a4..08cc01b0 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -15,6 +15,13 @@ import ( // Common variables and functions for the message tests var ( + revHash = [32]byte{ + 0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab, + 0x4d, 0x92, 0x73, 0xd1, 0x90, 0x63, 0x81, 0xb4, + 0x4f, 0x2f, 0x6f, 0x25, 0x88, 0xa3, 0xef, 0xb9, + 0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53, + } + // For debugging, writes to /dev/shm/ // Maybe in the future do it if you do "go test -v" WRITE_FILE = false