lnwire: fix bug in wire.OutPoint -> lnwire.ChannelID conversion
This commit fixes an existing, unnoticed bug within the lnwire. NewChanIDFromOutPoint function. Two lingering issues cause the function to not do anything at all, meaning that the channel ID, would be the exact same as the actual txid passed in. The first issue was that the xorTxid function wasn’t actually XOR’ing the last two bytes. This was due to the fact that the function wasn’t taking a pointer to the target ChannelID, meaning that the mutation wouldn’t be seen outside of the scope of the function. Second, we had our slicing reversed, rather than buf[30:], we were using buf[:30], meaning that we were weren’t properly filling the buffer with the lower 2-bytes of the passed index.
This commit is contained in:
parent
b58ef85513
commit
e3717485f5
@ -41,7 +41,7 @@ func NewChanIDFromOutPoint(op *wire.OutPoint) ChannelID {
|
|||||||
|
|
||||||
// With the txid copied over, we'll now XOR the lower 2-bytes of the
|
// With the txid copied over, we'll now XOR the lower 2-bytes of the
|
||||||
// partial channelID with big-endian serialization of output index.
|
// partial channelID with big-endian serialization of output index.
|
||||||
xorTxid(cid, uint16(op.Index))
|
xorTxid(&cid, uint16(op.Index))
|
||||||
|
|
||||||
return cid
|
return cid
|
||||||
}
|
}
|
||||||
@ -49,12 +49,12 @@ func NewChanIDFromOutPoint(op *wire.OutPoint) ChannelID {
|
|||||||
// xorTxid performs the transformation needed to transform an OutPoint into a
|
// xorTxid performs the transformation needed to transform an OutPoint into a
|
||||||
// ChannelID. To do this, we expect the cid parameter to contain the txid
|
// ChannelID. To do this, we expect the cid parameter to contain the txid
|
||||||
// unaltered and the outputIndex to be the output index
|
// unaltered and the outputIndex to be the output index
|
||||||
func xorTxid(cid ChannelID, outputIndex uint16) {
|
func xorTxid(cid *ChannelID, outputIndex uint16) {
|
||||||
var buf [32]byte
|
var buf [32]byte
|
||||||
binary.BigEndian.PutUint16(buf[:30], outputIndex)
|
binary.BigEndian.PutUint16(buf[30:], outputIndex)
|
||||||
|
|
||||||
buf[30] = cid[30] ^ buf[30]
|
cid[30] = cid[30] ^ buf[30]
|
||||||
buf[31] = cid[31] ^ buf[31]
|
cid[31] = cid[31] ^ buf[31]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenPossibleOutPoints generates all the possible outputs given a channel ID.
|
// GenPossibleOutPoints generates all the possible outputs given a channel ID.
|
||||||
@ -65,7 +65,7 @@ func (c *ChannelID) GenPossibleOutPoints() [MaxFundingTxOutputs]wire.OutPoint {
|
|||||||
var possiblePoints [MaxFundingTxOutputs]wire.OutPoint
|
var possiblePoints [MaxFundingTxOutputs]wire.OutPoint
|
||||||
for i := uint32(0); i < MaxFundingTxOutputs; i++ {
|
for i := uint32(0); i < MaxFundingTxOutputs; i++ {
|
||||||
cidCopy := *c
|
cidCopy := *c
|
||||||
xorTxid(cidCopy, uint16(i))
|
xorTxid(&cidCopy, uint16(i))
|
||||||
|
|
||||||
possiblePoints[i] = wire.OutPoint{
|
possiblePoints[i] = wire.OutPoint{
|
||||||
Hash: chainhash.Hash(cidCopy),
|
Hash: chainhash.Hash(cidCopy),
|
||||||
|
Loading…
Reference in New Issue
Block a user