Updated Commit Revocation

This commit is contained in:
Joseph Poon 2016-03-17 16:51:30 -07:00
parent 4b8a8f410a
commit 48667bdcbe
4 changed files with 15 additions and 33 deletions

View File

@ -11,16 +11,11 @@ type CommitRevocation struct {
// We can use a different data type for this if necessary...
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
RevocationProof [20]byte
//Next revocation to use
NextRevocationHash [20]byte
}
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)
err := readElements(r,
&c.ChannelID,
&c.CommitmentHeight,
&c.RevocationProof,
&c.NextRevocationHash,
)
if err != nil {
return err
@ -49,8 +44,8 @@ func NewCommitRevocation() *CommitRevocation {
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.CommitmentHeight,
c.RevocationProof,
c.NextRevocationHash,
)
if err != nil {
return err
@ -64,7 +59,7 @@ func (c *CommitRevocation) Command() 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)
@ -76,7 +71,7 @@ func (c *CommitRevocation) Validate() error {
func (c *CommitRevocation) String() string {
return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") +
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("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
fmt.Sprintf("--- End CommitRevocation ---\n")
}

View File

@ -7,14 +7,15 @@ import (
var (
// Need to to do this here
_ = copy(revocationHash[:], revocationHashBytes)
_ = copy(nextHop[:], nextHopBytes)
commitRevocation = &CommitRevocation{
ChannelID: uint64(12345678),
CommitmentHeight: uint64(12345),
RevocationProof: revocationHash, // technically it's not a hash... fix later
ChannelID: uint64(12345678),
RevocationProof: revocationHash, // technically it's not a hash... fix later
NextRevocationHash: nextHop, // technically it's not a hash... fix later
}
commitRevocationSerializedString = "0000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41"
commitRevocationSerializedMessage = "0709110b000007da000000240000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41"
commitRevocationSerializedString = "0000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440"
commitRevocationSerializedMessage = "0709110b000007da000000300000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440"
)
func TestCommitRevocationEncodeDecode(t *testing.T) {

View File

@ -12,8 +12,8 @@ var (
commitSignature = &CommitSignature{
ChannelID: uint64(12345678),
CommitmentHeight: uint64(12345),
LastCommittedKeyAlice: uint64(12345),
LastCommittedKeyBob: uint64(54321),
LastCommittedKeyAlice: HTLCKey(12345),
LastCommittedKeyBob: HTLCKey(54321),
RevocationHash: revocationHash,
Fee: btcutil.Amount(10000),
CommitSig: commitSig,

View File

@ -9,20 +9,6 @@ import (
"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
const MessageHeaderSize = 12