breacharbiter: add chainhash to retributionInfo struct

In this commit we add a chainhash field to the retributionInfo struct
as within the database, channels are now further namespaced by their
chain hash, and all ChannelCloseSummary structs now also carry the
chain hash of their respective chain.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 15:23:02 -08:00
parent 2862b6e6f1
commit ce7a981b4f
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -777,6 +777,7 @@ func (b *breachArbiter) breachObserver(contract *lnwallet.LightningChannel,
// BreachClose.
closeInfo := &channeldb.ChannelCloseSummary{
ChanPoint: *chanPoint,
ChainHash: breachInfo.ChainHash,
ClosingTXID: breachInfo.BreachTransaction.TxHash(),
RemotePub: &chanInfo.RemoteIdentity,
Capacity: chanInfo.Capacity,
@ -918,6 +919,7 @@ var _ SpendableOutput = (*breachedOutput)(nil)
type retributionInfo struct {
commitHash chainhash.Hash
chanPoint wire.OutPoint
chainHash chainhash.Hash
// TODO(conner): remove the following group of fields after decoupling
// the breach arbiter from the wallet.
@ -1007,6 +1009,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
return &retributionInfo{
commitHash: breachInfo.BreachTransaction.TxHash(),
chainHash: chanInfo.ChainHash,
chanPoint: *chanPoint,
remoteIdentity: &chanInfo.RemoteIdentity,
capacity: chanInfo.Capacity,
@ -1325,6 +1328,10 @@ func (ret *retributionInfo) Encode(w io.Writer) error {
return err
}
if _, err := w.Write(ret.chainHash[:]); err != nil {
return err
}
if _, err := w.Write(
ret.remoteIdentity.SerializeCompressed()); err != nil {
return err
@ -1371,6 +1378,15 @@ func (ret *retributionInfo) Decode(r io.Reader) error {
return err
}
if _, err := io.ReadFull(r, scratch[:32]); err != nil {
return err
}
chainHash, err := chainhash.NewHash(scratch[:32])
if err != nil {
return err
}
ret.chainHash = *chainHash
if _, err = io.ReadFull(r, scratch[:33]); err != nil {
return err
}