lnwire: rename CommitRevocation to RevokeAndAck

This commit renames the prior CommitRevocation message to RevokeAndAck
in order to better align the set of wire messages implemented by the
`lnwire` message with those currently defined within the specification.
This commit is contained in:
Olaoluwa Osuntokun 2017-02-09 15:28:32 -08:00
parent 0bbb072ceb
commit 9a61bb3ae1
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
4 changed files with 130 additions and 131 deletions

@ -1,122 +0,0 @@
package lnwire
import (
"io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
)
// CommitRevocation is sent by either side once a CommitSignature message has
// been received, and validated. This message serves to revoke the prior
// commitment transaction, which was the most up to date version until a
// CommitSignature message referencing the specified ChannelPoint was received.
// Additionally, this message also piggyback's the next revocation hash that
// Alice should use when constructing the Bob's version of the next commitment
// transaction (which would be done before sending a CommitSignature message).
// This piggybacking allows Alice to send the next CommitSignature message
// modifying Bob's commitment transaction without first asking for a revocation
// hash initially.
// TODO(roasbeef): update docs everywhere
type CommitRevocation struct {
// ChannelPoint uniquely identifies to which currently active channel this
// CommitRevocation applies to.
ChannelPoint *wire.OutPoint
// Revocation is the preimage to the revocation hash of the now prior
// commitment transaction.
//
// If the received revocation is the all zeroes hash ('0' * 32), then
// this CommitRevocation is being sent in order to build up the
// sender's initial revocation window (IRW). In this case, the
// CommitRevocation should be added to the receiver's queue of unused
// revocations to be used to construct future commitment transactions.
Revocation [32]byte
// NextRevocationKey is the next revocation key which should be added
// to the queue of unused revocation keys for the remote peer. This key
// will be used within the revocation clause for any new commitment
// transactions created for the remote peer.
NextRevocationKey *btcec.PublicKey
// NextRevocationHash is the next revocation hash which should be added
// to the queue on unused revocation hashes for the remote peer. This
// revocation hash will be used within any HTLCs included within this
// next commitment transaction.
NextRevocationHash [32]byte
}
// NewCommitRevocation creates a new CommitRevocation message.
func NewCommitRevocation() *CommitRevocation {
return &CommitRevocation{}
}
// A compile time check to ensure CommitRevocation implements the lnwire.Message
// interface.
var _ Message = (*CommitRevocation)(nil)
// Decode deserializes a serialized CommitRevocation message stored in the
// passed io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
// ChannelPoint (8)
// Revocation (32)
// NextRevocationKey (33)
// NextRevocationHash (32)
err := readElements(r,
&c.ChannelPoint,
&c.Revocation,
&c.NextRevocationKey,
&c.NextRevocationHash,
)
if err != nil {
return err
}
return nil
}
// Encode serializes the target CommitRevocation into the passed io.Writer
// observing the protocol version specified.
//
// This is part of the lnwire.Message interface.
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelPoint,
c.Revocation,
c.NextRevocationKey,
c.NextRevocationHash,
)
if err != nil {
return err
}
return nil
}
// Command returns the integer uniquely identifying this message type on the
// wire.
//
// This is part of the lnwire.Message interface.
func (c *CommitRevocation) Command() uint32 {
return CmdCommitRevocation
}
// MaxPayloadLength returns the maximum allowed payload size for a
// CommitRevocation complete message observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 {
// 36 + 32 + 33 + 32
return 133
}
// Validate performs any necessary sanity checks to ensure all fields present
// on the CommitRevocation are valid.
//
// This is part of the lnwire.Message interface.
func (c *CommitRevocation) Validate() error {
// We're good!
return nil
}

@ -21,6 +21,7 @@ const MessageHeaderSize = 12
const MaxMessagePayload = 1024 * 1024 * 32 // 32MB
// Commands used in lightning message headers which detail the type of message.
// TODO(roasbeef): update with latest type numbering from spec
const (
CmdInit = uint32(1)
@ -44,7 +45,7 @@ const (
// Commands for modifying commitment transactions.
CmdCommitSignature = uint32(2000)
CmdCommitRevocation = uint32(2010)
CmdRevokeAndAck = uint32(2010)
// Commands for reporting protocol errors.
CmdErrorGeneric = uint32(4000)
@ -116,8 +117,8 @@ func makeEmptyMessage(command uint32) (Message, error) {
msg = &CancelHTLC{}
case CmdCommitSignature:
msg = &CommitSignature{}
case CmdCommitRevocation:
msg = &CommitRevocation{}
case CmdRevokeAndAck:
msg = &RevokeAndAck{}
case CmdErrorGeneric:
msg = &ErrorGeneric{}
case CmdChannelAnnoucmentMessage:

120
lnwire/revoke_and_ack.go Normal file

@ -0,0 +1,120 @@
package lnwire
import (
"io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
)
// RevokeAndAck is sent by either side once a CommitSig message has been
// received, and validated. This message serves to revoke the prior commitment
// transaction, which was the most up to date version until a CommitSig message
// referencing the specified ChannelPoint was received. Additionally, this
// message also piggyback's the next revocation hash that Alice should use when
// constructing the Bob's version of the next commitment transaction (which
// would be done before sending a CommitSig message). This piggybacking allows
// Alice to send the next CommitSig message modifying Bob's commitment
// transaction without first asking for a revocation hash initially.
type RevokeAndAck struct {
// ChannelPoint uniquely identifies to which currently active channel
// this RevokeAndAck applies to.
ChannelPoint wire.OutPoint
// Revocation is the preimage to the revocation hash of the now prior
// commitment transaction.
//
// If the received revocation is the all zeroes hash ('0' * 32), then
// this RevokeAndAck is being sent in order to build up the sender's
// initial revocation window (IRW). In this case, the RevokeAndAck
// should be added to the receiver's queue of unused revocations to be
// used to construct future commitment transactions.
Revocation [32]byte
// NextRevocationKey is the next revocation key which should be added
// to the queue of unused revocation keys for the remote peer. This key
// will be used within the revocation clause for any new commitment
// transactions created for the remote peer.
NextRevocationKey *btcec.PublicKey
// NextRevocationHash is the next revocation hash which should be added
// to the queue on unused revocation hashes for the remote peer. This
// revocation hash will be used within any HTLCs included within this
// next commitment transaction.
NextRevocationHash [32]byte
}
// NewRevokeAndAck creates a new RevokeAndAck message.
func NewRevokeAndAck() *RevokeAndAck {
return &RevokeAndAck{}
}
// A compile time check to ensure RevokeAndAck implements the lnwire.Message
// interface.
var _ Message = (*RevokeAndAck)(nil)
// Decode deserializes a serialized RevokeAndAck message stored in the
// passed io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
// ChannelPoint (8)
// Revocation (32)
// NextRevocationKey (33)
// NextRevocationHash (32)
err := readElements(r,
&c.ChannelPoint,
c.Revocation[:],
&c.NextRevocationKey,
c.NextRevocationHash[:],
)
if err != nil {
return err
}
return nil
}
// Encode serializes the target RevokeAndAck into the passed io.Writer
// observing the protocol version specified.
//
// This is part of the lnwire.Message interface.
func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelPoint,
c.Revocation[:],
c.NextRevocationKey,
c.NextRevocationHash[:],
)
if err != nil {
return err
}
return nil
}
// Command returns the integer uniquely identifying this message type on the
// wire.
//
// This is part of the lnwire.Message interface.
func (c *RevokeAndAck) Command() uint32 {
return CmdRevokeAndAck
}
// MaxPayloadLength returns the maximum allowed payload size for a
// RevokeAndAck complete message observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *RevokeAndAck) MaxPayloadLength(uint32) uint32 {
// 36 + 32 + 33 + 32
return 133
}
// Validate performs any necessary sanity checks to ensure all fields present
// on the RevokeAndAck are valid.
//
// This is part of the lnwire.Message interface.
func (c *RevokeAndAck) Validate() error {
// We're good!
return nil
}

@ -6,9 +6,9 @@ import (
"testing"
)
func TestCommitRevocationEncodeDecode(t *testing.T) {
cr := &CommitRevocation{
ChannelPoint: outpoint1,
func TestRevokeAndAckEncodeDecode(t *testing.T) {
cr := &RevokeAndAck{
ChannelPoint: *outpoint1,
Revocation: revHash,
NextRevocationKey: pubKey,
NextRevocationHash: revHash,
@ -17,13 +17,13 @@ func TestCommitRevocationEncodeDecode(t *testing.T) {
// Next encode the CR message into an empty bytes buffer.
var b bytes.Buffer
if err := cr.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode CommitRevocation: %v", err)
t.Fatalf("unable to encode RevokeAndAck: %v", err)
}
// Deserialize the encoded EG message into a new empty struct.
cr2 := &CommitRevocation{}
cr2 := &RevokeAndAck{}
if err := cr2.Decode(&b, 0); err != nil {
t.Fatalf("unable to decode CommitRevocation: %v", err)
t.Fatalf("unable to decode RevokeAndAck: %v", err)
}
// Assert equality of the two instances.