From ce7a981b4f51ed1a6a470494b507e78372725c5f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 10 Nov 2017 15:23:02 -0800 Subject: [PATCH] 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. --- breacharbiter.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/breacharbiter.go b/breacharbiter.go index 683655d7..13fced4a 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -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 }