channeldb: modify UpdateCommitment to accept a ChannelCommitment
In this commit, we modify the UpdateCommitment method to accept a full ChannelCommitment rather than a new transaction, the sig, and a ChannelDelta. This new structure of this method also takes advantage of the new bucket structure of the storage schema. Additionally, this method will now atomically swap in the new passed commitment to point to the LocalCommitment value within the struct.
This commit is contained in:
parent
2dcd82e779
commit
3e3969eb66
@ -610,79 +610,33 @@ func (c *OpenChannel) SyncPending(addr *net.TCPAddr, pendingHeight uint32) error
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCommitment updates the on-disk state of our currently broadcastable
|
// UpdateCommitment updates the commitment state for the specified party
|
||||||
// commitment state. This method is to be called once we have revoked our prior
|
// (remote or local). The commitment stat completely describes the balance
|
||||||
// commitment state, accepting the new state as defined by the passed
|
// state at this point in the commitment chain. This method its to be called on
|
||||||
// parameters.
|
// two occasions: when we revoke our prior commitment state, and when the
|
||||||
func (c *OpenChannel) UpdateCommitment(newCommitment *wire.MsgTx,
|
// remote party revokes their prior commitment state.
|
||||||
newSig []byte, delta *ChannelDelta) error {
|
func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment) error {
|
||||||
|
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||||
chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
|
chanBucket, err := updateChanBucket(tx, c.IdentityPub,
|
||||||
|
&c.FundingOutpoint, c.ChainHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
id := c.IdentityPub.SerializeCompressed()
|
// With the proper bucket fetched, we'll now write toe latest
|
||||||
nodeChanBucket, err := chanBucket.CreateBucketIfNotExists(id)
|
// commitment state to dis for the target party.
|
||||||
if err != nil {
|
return putChanCommitment(chanBucket, newCommitment, true)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(roasbeef): modify the funcs below to take values
|
|
||||||
// directly, otherwise need to roll back to prior state. Could
|
|
||||||
// also make copy above, then modify to pass in.
|
|
||||||
c.CommitTx = *newCommitment
|
|
||||||
c.CommitSig = newSig
|
|
||||||
c.LocalBalance = delta.LocalBalance
|
|
||||||
c.RemoteBalance = delta.RemoteBalance
|
|
||||||
c.NumUpdates = delta.UpdateNum
|
|
||||||
c.OurMessageIndex = delta.OurMessageIndex
|
|
||||||
c.TheirMessageIndex = delta.TheirMessageIndex
|
|
||||||
c.Htlcs = delta.Htlcs
|
|
||||||
c.CommitFee = delta.CommitFee
|
|
||||||
c.FeePerKw = delta.FeePerKw
|
|
||||||
|
|
||||||
// First we'll write out the current latest dynamic channel
|
|
||||||
// state: the current channel balance, the number of updates,
|
|
||||||
// and our latest commitment transaction+sig.
|
|
||||||
// TODO(roasbeef): re-make schema s.t this is a single put
|
|
||||||
if err := putChanCapacity(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putChanAmountsTransferred(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putChanNumUpdates(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putOurMessageIndex(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putTheirMessageIndex(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putChanCommitFee(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putChanFeePerKw(chanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putChanCommitTxns(nodeChanBucket, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := putCurrentHtlcs(nodeChanBucket, delta.Htlcs,
|
|
||||||
&c.FundingOutpoint); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.LocalCommitment = *newCommitment
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTLC is the on-disk representation of a hash time-locked contract. HTLCs are
|
// HTLC is the on-disk representation of a hash time-locked contract. HTLCs are
|
||||||
|
Loading…
Reference in New Issue
Block a user