Skip to content

Commit e8da6dd

Browse files
committed
channeldb: convert concurrent channel state machine calls to use Batch
1 parent 3555d3d commit e8da6dd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

channeldb/channel.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment) error {
10271027
return ErrNoRestoredChannelMutation
10281028
}
10291029

1030-
err := c.Db.Update(func(tx *bbolt.Tx) error {
1030+
err := c.Db.Batch(func(tx *bbolt.Tx) error {
10311031
chanBucket, err := fetchChanBucket(
10321032
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
10331033
)
@@ -1465,7 +1465,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
14651465
return ErrNoRestoredChannelMutation
14661466
}
14671467

1468-
return c.Db.Update(func(tx *bbolt.Tx) error {
1468+
return c.Db.Batch(func(tx *bbolt.Tx) error {
14691469
// First, we'll grab the writable bucket where this channel's
14701470
// data resides.
14711471
chanBucket, err := fetchChanBucket(
@@ -1608,7 +1608,9 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg) error {
16081608

16091609
var newRemoteCommit *ChannelCommitment
16101610

1611-
err := c.Db.Update(func(tx *bbolt.Tx) error {
1611+
err := c.Db.Batch(func(tx *bbolt.Tx) error {
1612+
newRemoteCommit = nil
1613+
16121614
chanBucket, err := fetchChanBucket(
16131615
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
16141616
)
@@ -1746,7 +1748,7 @@ func (c *OpenChannel) AckAddHtlcs(addRefs ...AddRef) error {
17461748
c.Lock()
17471749
defer c.Unlock()
17481750

1749-
return c.Db.Update(func(tx *bbolt.Tx) error {
1751+
return c.Db.Batch(func(tx *bbolt.Tx) error {
17501752
return c.Packager.AckAddHtlcs(tx, addRefs...)
17511753
})
17521754
}
@@ -1759,7 +1761,7 @@ func (c *OpenChannel) AckSettleFails(settleFailRefs ...SettleFailRef) error {
17591761
c.Lock()
17601762
defer c.Unlock()
17611763

1762-
return c.Db.Update(func(tx *bbolt.Tx) error {
1764+
return c.Db.Batch(func(tx *bbolt.Tx) error {
17631765
return c.Packager.AckSettleFails(tx, settleFailRefs...)
17641766
})
17651767
}
@@ -1770,7 +1772,7 @@ func (c *OpenChannel) SetFwdFilter(height uint64, fwdFilter *PkgFilter) error {
17701772
c.Lock()
17711773
defer c.Unlock()
17721774

1773-
return c.Db.Update(func(tx *bbolt.Tx) error {
1775+
return c.Db.Batch(func(tx *bbolt.Tx) error {
17741776
return c.Packager.SetFwdFilter(tx, height, fwdFilter)
17751777
})
17761778
}
@@ -1783,14 +1785,15 @@ func (c *OpenChannel) RemoveFwdPkg(height uint64) error {
17831785
c.Lock()
17841786
defer c.Unlock()
17851787

1786-
return c.Db.Update(func(tx *bbolt.Tx) error {
1788+
return c.Db.Batch(func(tx *bbolt.Tx) error {
17871789
return c.Packager.RemovePkg(tx, height)
17881790
})
17891791
}
17901792

17911793
// RevocationLogTail returns the "tail", or the end of the current revocation
17921794
// log. This entry represents the last previous state for the remote node's
1793-
// commitment chain. The ChannelDelta returned by this method will always lag one state behind the most current (unrevoked) state of the remote node's
1795+
// commitment chain. The ChannelDelta returned by this method will always lag
1796+
// one state behind the most current (unrevoked) state of the remote node's
17941797
// commitment chain.
17951798
func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) {
17961799
c.RLock()

0 commit comments

Comments
 (0)