Updated Commit Revocation
This commit is contained in:
parent
4b8a8f410a
commit
48667bdcbe
@ -11,16 +11,11 @@ type CommitRevocation struct {
|
|||||||
// We can use a different data type for this if necessary...
|
// We can use a different data type for this if necessary...
|
||||||
ChannelID uint64
|
ChannelID uint64
|
||||||
|
|
||||||
// Height of the commitment
|
|
||||||
// You should have the most recent commitment height stored locally
|
|
||||||
// This should be validated!
|
|
||||||
// This is used for shachain.
|
|
||||||
// Each party increments their own CommitmentHeight, they can differ for
|
|
||||||
// each part of the Commitment.
|
|
||||||
CommitmentHeight uint64
|
|
||||||
|
|
||||||
// Revocation to use
|
// Revocation to use
|
||||||
RevocationProof [20]byte
|
RevocationProof [20]byte
|
||||||
|
|
||||||
|
//Next revocation to use
|
||||||
|
NextRevocationHash [20]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
|
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
|
||||||
@ -29,8 +24,8 @@ func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
|
|||||||
// RevocationProof(20)
|
// RevocationProof(20)
|
||||||
err := readElements(r,
|
err := readElements(r,
|
||||||
&c.ChannelID,
|
&c.ChannelID,
|
||||||
&c.CommitmentHeight,
|
|
||||||
&c.RevocationProof,
|
&c.RevocationProof,
|
||||||
|
&c.NextRevocationHash,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -49,8 +44,8 @@ func NewCommitRevocation() *CommitRevocation {
|
|||||||
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
|
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
|
||||||
err := writeElements(w,
|
err := writeElements(w,
|
||||||
c.ChannelID,
|
c.ChannelID,
|
||||||
c.CommitmentHeight,
|
|
||||||
c.RevocationProof,
|
c.RevocationProof,
|
||||||
|
c.NextRevocationHash,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -64,7 +59,7 @@ func (c *CommitRevocation) Command() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 {
|
func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 {
|
||||||
return 36
|
return 48
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
||||||
@ -76,7 +71,7 @@ func (c *CommitRevocation) Validate() error {
|
|||||||
func (c *CommitRevocation) String() string {
|
func (c *CommitRevocation) String() string {
|
||||||
return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") +
|
return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") +
|
||||||
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
||||||
fmt.Sprintf("CommitmentHeight:\t%d\n", c.CommitmentHeight) +
|
|
||||||
fmt.Sprintf("RevocationProof:\t%x\n", c.RevocationProof) +
|
fmt.Sprintf("RevocationProof:\t%x\n", c.RevocationProof) +
|
||||||
|
fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
|
||||||
fmt.Sprintf("--- End CommitRevocation ---\n")
|
fmt.Sprintf("--- End CommitRevocation ---\n")
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,15 @@ import (
|
|||||||
var (
|
var (
|
||||||
// Need to to do this here
|
// Need to to do this here
|
||||||
_ = copy(revocationHash[:], revocationHashBytes)
|
_ = copy(revocationHash[:], revocationHashBytes)
|
||||||
|
_ = copy(nextHop[:], nextHopBytes)
|
||||||
|
|
||||||
commitRevocation = &CommitRevocation{
|
commitRevocation = &CommitRevocation{
|
||||||
ChannelID: uint64(12345678),
|
ChannelID: uint64(12345678),
|
||||||
CommitmentHeight: uint64(12345),
|
|
||||||
RevocationProof: revocationHash, // technically it's not a hash... fix later
|
RevocationProof: revocationHash, // technically it's not a hash... fix later
|
||||||
|
NextRevocationHash: nextHop, // technically it's not a hash... fix later
|
||||||
}
|
}
|
||||||
commitRevocationSerializedString = "0000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41"
|
commitRevocationSerializedString = "0000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440"
|
||||||
commitRevocationSerializedMessage = "0709110b000007da000000240000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41"
|
commitRevocationSerializedMessage = "0709110b000007da000000300000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommitRevocationEncodeDecode(t *testing.T) {
|
func TestCommitRevocationEncodeDecode(t *testing.T) {
|
||||||
|
@ -12,8 +12,8 @@ var (
|
|||||||
commitSignature = &CommitSignature{
|
commitSignature = &CommitSignature{
|
||||||
ChannelID: uint64(12345678),
|
ChannelID: uint64(12345678),
|
||||||
CommitmentHeight: uint64(12345),
|
CommitmentHeight: uint64(12345),
|
||||||
LastCommittedKeyAlice: uint64(12345),
|
LastCommittedKeyAlice: HTLCKey(12345),
|
||||||
LastCommittedKeyBob: uint64(54321),
|
LastCommittedKeyBob: HTLCKey(54321),
|
||||||
RevocationHash: revocationHash,
|
RevocationHash: revocationHash,
|
||||||
Fee: btcutil.Amount(10000),
|
Fee: btcutil.Amount(10000),
|
||||||
CommitSig: commitSig,
|
CommitSig: commitSig,
|
||||||
|
@ -9,20 +9,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// message type identifyer bytes
|
|
||||||
const (
|
|
||||||
MSGID_FUNDREQUEST = 0x30
|
|
||||||
MSGID_FUNDRESPONSE = 0x31
|
|
||||||
|
|
||||||
MSGID_CLOSEREQUEST = 0x40
|
|
||||||
MSGID_CLOSERESPONSE = 0x41
|
|
||||||
|
|
||||||
MSGID_TEXTCHAT = 0x70
|
|
||||||
|
|
||||||
MSGID_FWDMSG = 0x20
|
|
||||||
MSGID_FWDAUTHREQ = 0x21
|
|
||||||
)
|
|
||||||
|
|
||||||
// 4-byte network + 4-byte message id + payload-length 4-byte
|
// 4-byte network + 4-byte message id + payload-length 4-byte
|
||||||
const MessageHeaderSize = 12
|
const MessageHeaderSize = 12
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user