channeldb: remove theirCommitTx, store latest commit sig
This commit is contained in:
parent
927db9cfd5
commit
06af4b130f
@ -115,11 +115,10 @@ type OpenChannel struct {
|
|||||||
OurBalance btcutil.Amount
|
OurBalance btcutil.Amount
|
||||||
TheirBalance btcutil.Amount
|
TheirBalance btcutil.Amount
|
||||||
|
|
||||||
// Commitment transactions for both sides (they're asymmetric). Our
|
// Our current commitment transaction along with their signature for
|
||||||
// commitment transaction includes a valid sigScript, and is ready for
|
// our commitment transaction.
|
||||||
// broadcast.
|
OurCommitTx *wire.MsgTx
|
||||||
TheirCommitTx *wire.MsgTx
|
OurCommitSig []byte
|
||||||
OurCommitTx *wire.MsgTx
|
|
||||||
|
|
||||||
// The outpoint of the final funding transaction.
|
// The outpoint of the final funding transaction.
|
||||||
FundingOutpoint *wire.OutPoint
|
FundingOutpoint *wire.OutPoint
|
||||||
@ -150,7 +149,7 @@ type OpenChannel struct {
|
|||||||
TotalNetFees uint64 // TODO(roasbeef): total fees paid too?
|
TotalNetFees uint64 // TODO(roasbeef): total fees paid too?
|
||||||
CreationTime time.Time // TODO(roasbeef): last update time?
|
CreationTime time.Time // TODO(roasbeef): last update time?
|
||||||
|
|
||||||
// isPrevState denotes if this instane of an OpenChannel is a previous,
|
// isPrevState denotes if this instance of an OpenChannel is a previous,
|
||||||
// revoked channel state. If so, then the FullSynv, and UpdateState
|
// revoked channel state. If so, then the FullSynv, and UpdateState
|
||||||
// methods are disabled in order to prevent overiding the latest channel
|
// methods are disabled in order to prevent overiding the latest channel
|
||||||
// state.
|
// state.
|
||||||
@ -845,11 +844,11 @@ func putChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error
|
|||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
|
||||||
if err := channel.TheirCommitTx.Serialize(&b); err != nil {
|
if err := channel.OurCommitTx.Serialize(&b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := channel.OurCommitTx.Serialize(&b); err != nil {
|
if err := wire.WriteVarBytes(&b, 0, channel.OurCommitSig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -875,7 +874,8 @@ func deleteChanCommitTxns(nodeChanBucket *bolt.Bucket, chanID []byte) error {
|
|||||||
|
|
||||||
func fetchChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error {
|
func fetchChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||||
var bc bytes.Buffer
|
var bc bytes.Buffer
|
||||||
if err := writeOutpoint(&bc, channel.ChanID); err != nil {
|
var err error
|
||||||
|
if err = writeOutpoint(&bc, channel.ChanID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
txnsKey := make([]byte, len(commitTxnsKey)+bc.Len())
|
txnsKey := make([]byte, len(commitTxnsKey)+bc.Len())
|
||||||
@ -884,13 +884,13 @@ func fetchChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) erro
|
|||||||
|
|
||||||
txnBytes := bytes.NewReader(nodeChanBucket.Get(txnsKey))
|
txnBytes := bytes.NewReader(nodeChanBucket.Get(txnsKey))
|
||||||
|
|
||||||
channel.TheirCommitTx = wire.NewMsgTx()
|
channel.OurCommitTx = wire.NewMsgTx()
|
||||||
if err := channel.TheirCommitTx.Deserialize(txnBytes); err != nil {
|
if err = channel.OurCommitTx.Deserialize(txnBytes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.OurCommitTx = wire.NewMsgTx()
|
channel.OurCommitSig, err = wire.ReadVarBytes(txnBytes, 0, 80, "")
|
||||||
if err := channel.OurCommitTx.Deserialize(txnBytes); err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,33 +141,34 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
state := OpenChannel{
|
state := OpenChannel{
|
||||||
TheirLNID: key,
|
TheirLNID: key,
|
||||||
ChanID: id,
|
ChanID: id,
|
||||||
MinFeePerKb: btcutil.Amount(5000),
|
MinFeePerKb: btcutil.Amount(5000),
|
||||||
OurCommitKey: privKey,
|
OurCommitKey: privKey,
|
||||||
TheirCommitKey: pubKey,
|
TheirCommitKey: pubKey,
|
||||||
Capacity: btcutil.Amount(10000),
|
Capacity: btcutil.Amount(10000),
|
||||||
OurBalance: btcutil.Amount(3000),
|
OurBalance: btcutil.Amount(3000),
|
||||||
TheirBalance: btcutil.Amount(9000),
|
TheirBalance: btcutil.Amount(9000),
|
||||||
TheirCommitTx: testTx,
|
OurCommitTx: testTx,
|
||||||
OurCommitTx: testTx,
|
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
LocalElkrem: sender,
|
LocalElkrem: sender,
|
||||||
RemoteElkrem: receiver,
|
RemoteElkrem: receiver,
|
||||||
FundingOutpoint: testOutpoint,
|
FundingOutpoint: testOutpoint,
|
||||||
OurMultiSigKey: privKey,
|
OurMultiSigKey: privKey,
|
||||||
TheirMultiSigKey: privKey.PubKey(),
|
TheirMultiSigKey: privKey.PubKey(),
|
||||||
FundingRedeemScript: script,
|
FundingRedeemScript: script,
|
||||||
TheirCurrentRevocation: privKey.PubKey(),
|
TheirCurrentRevocation: privKey.PubKey(),
|
||||||
OurDeliveryScript: script,
|
TheirCurrentRevocationHash: key,
|
||||||
TheirDeliveryScript: script,
|
OurDeliveryScript: script,
|
||||||
LocalCsvDelay: 5,
|
TheirDeliveryScript: script,
|
||||||
RemoteCsvDelay: 9,
|
LocalCsvDelay: 5,
|
||||||
NumUpdates: 1,
|
RemoteCsvDelay: 9,
|
||||||
TotalSatoshisSent: 8,
|
NumUpdates: 1,
|
||||||
TotalSatoshisReceived: 2,
|
TotalSatoshisSent: 8,
|
||||||
TotalNetFees: 9,
|
TotalSatoshisReceived: 2,
|
||||||
CreationTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
TotalNetFees: 9,
|
||||||
Db: cdb,
|
CreationTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||||
|
Db: cdb,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := state.FullSync(); err != nil {
|
if err := state.FullSync(); err != nil {
|
||||||
@ -215,19 +216,6 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var b1, b2 bytes.Buffer
|
var b1, b2 bytes.Buffer
|
||||||
if err := state.TheirCommitTx.Serialize(&b1); err != nil {
|
|
||||||
t.Fatalf("unable to serialize transaction")
|
|
||||||
}
|
|
||||||
if err := newState.TheirCommitTx.Serialize(&b2); err != nil {
|
|
||||||
t.Fatalf("unable to serialize transaction")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
|
||||||
t.Fatalf("theirCommitTx doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
b1.Reset()
|
|
||||||
b2.Reset()
|
|
||||||
|
|
||||||
if err := state.OurCommitTx.Serialize(&b1); err != nil {
|
if err := state.OurCommitTx.Serialize(&b1); err != nil {
|
||||||
t.Fatalf("unable to serialize transaction")
|
t.Fatalf("unable to serialize transaction")
|
||||||
}
|
}
|
||||||
@ -237,9 +225,9 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
||||||
t.Fatalf("ourCommitTx doesn't match")
|
t.Fatalf("ourCommitTx doesn't match")
|
||||||
}
|
}
|
||||||
|
if !bytes.Equal(newState.OurCommitSig, state.OurCommitSig) {
|
||||||
b1.Reset()
|
t.Fatalf("commit sigs don't match")
|
||||||
b2.Reset()
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): replace with a single equal?
|
// TODO(roasbeef): replace with a single equal?
|
||||||
if !reflect.DeepEqual(state.FundingOutpoint, newState.FundingOutpoint) {
|
if !reflect.DeepEqual(state.FundingOutpoint, newState.FundingOutpoint) {
|
||||||
|
Loading…
Reference in New Issue
Block a user