Skip to content

Commit 9651ee6

Browse files
authored
Merge pull request #8452 from ProofOfKeags/refactor/contractcourt/naming-consistency
contractcourt: homogenize naming convention
2 parents 771d1f0 + 0f245bf commit 9651ee6

File tree

9 files changed

+102
-91
lines changed

9 files changed

+102
-91
lines changed

contractcourt/breacharbiter.go renamed to contractcourt/breach_arbitrator.go

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ var (
5353
// for the first and one for the second level).
5454
taprootRetributionBucket = []byte("tap-retribution")
5555

56-
// errBrarShuttingDown is an error returned if the breacharbiter has
56+
// errBrarShuttingDown is an error returned if the BreachArbitrator has
5757
// been signalled to exit.
58-
errBrarShuttingDown = errors.New("breacharbiter shutting down")
58+
errBrarShuttingDown = errors.New("BreachArbitrator shutting down")
5959
)
6060

61-
// ContractBreachEvent is an event the BreachArbiter will receive in case a
61+
// ContractBreachEvent is an event the BreachArbitrator will receive in case a
6262
// contract breach is observed on-chain. It contains the necessary information
6363
// to handle the breach, and a ProcessACK closure we will use to ACK the event
6464
// when we have safely stored all the necessary information.
@@ -71,7 +71,7 @@ type ContractBreachEvent struct {
7171
// store. In case storing the information to the store fails, a non-nil
7272
// error should be used. When this closure returns, it means that the
7373
// contract court has marked the channel pending close in the DB, and
74-
// it is safe for the BreachArbiter to carry on its duty.
74+
// it is safe for the BreachArbitrator to carry on its duty.
7575
ProcessACK func(error)
7676

7777
// BreachRetribution is the information needed to act on this contract
@@ -94,11 +94,12 @@ const (
9494
)
9595

9696
// RetributionStorer provides an interface for managing a persistent map from
97-
// wire.OutPoint -> retributionInfo. Upon learning of a breach, a BreachArbiter
98-
// should record the retributionInfo for the breached channel, which serves a
99-
// checkpoint in the event that retribution needs to be resumed after failure.
100-
// A RetributionStore provides an interface for managing the persisted set, as
101-
// well as mapping user defined functions over the entire on-disk contents.
97+
// wire.OutPoint -> retributionInfo. Upon learning of a breach, a
98+
// BreachArbitrator should record the retributionInfo for the breached channel,
99+
// which serves a checkpoint in the event that retribution needs to be resumed
100+
// after failure. A RetributionStore provides an interface for managing the
101+
// persisted set, as well as mapping user defined functions over the entire
102+
// on-disk contents.
102103
//
103104
// Calls to RetributionStore may occur concurrently. A concrete instance of
104105
// RetributionStore should use appropriate synchronization primitives, or
@@ -125,7 +126,8 @@ type RetributionStorer interface {
125126
}
126127

127128
// BreachConfig bundles the required subsystems used by the breach arbiter. An
128-
// instance of BreachConfig is passed to newBreachArbiter during instantiation.
129+
// instance of BreachConfig is passed to NewBreachArbitrator during
130+
// instantiation.
129131
type BreachConfig struct {
130132
// CloseLink allows the breach arbiter to shutdown any channel links for
131133
// which it detects a breach, ensuring now further activity will
@@ -154,9 +156,9 @@ type BreachConfig struct {
154156
// transaction to the network.
155157
PublishTransaction func(*wire.MsgTx, string) error
156158

157-
// ContractBreaches is a channel where the BreachArbiter will receive
159+
// ContractBreaches is a channel where the BreachArbitrator will receive
158160
// notifications in the event of a contract breach being observed. A
159-
// ContractBreachEvent must be ACKed by the BreachArbiter, such that
161+
// ContractBreachEvent must be ACKed by the BreachArbitrator, such that
160162
// the sending subsystem knows that the event is properly handed off.
161163
ContractBreaches <-chan *ContractBreachEvent
162164

@@ -171,15 +173,15 @@ type BreachConfig struct {
171173
Store RetributionStorer
172174
}
173175

174-
// BreachArbiter is a special subsystem which is responsible for watching and
176+
// BreachArbitrator is a special subsystem which is responsible for watching and
175177
// acting on the detection of any attempted uncooperative channel breaches by
176178
// channel counterparties. This file essentially acts as deterrence code for
177179
// those attempting to launch attacks against the daemon. In practice it's
178180
// expected that the logic in this file never gets executed, but it is
179181
// important to have it in place just in case we encounter cheating channel
180182
// counterparties.
181183
// TODO(roasbeef): closures in config for subsystem pointers to decouple?
182-
type BreachArbiter struct {
184+
type BreachArbitrator struct {
183185
started sync.Once
184186
stopped sync.Once
185187

@@ -192,19 +194,19 @@ type BreachArbiter struct {
192194
sync.Mutex
193195
}
194196

195-
// NewBreachArbiter creates a new instance of a BreachArbiter initialized with
196-
// its dependent objects.
197-
func NewBreachArbiter(cfg *BreachConfig) *BreachArbiter {
198-
return &BreachArbiter{
197+
// NewBreachArbitrator creates a new instance of a BreachArbitrator initialized
198+
// with its dependent objects.
199+
func NewBreachArbitrator(cfg *BreachConfig) *BreachArbitrator {
200+
return &BreachArbitrator{
199201
cfg: cfg,
200202
subscriptions: make(map[wire.OutPoint]chan struct{}),
201203
quit: make(chan struct{}),
202204
}
203205
}
204206

205-
// Start is an idempotent method that officially starts the BreachArbiter along
206-
// with all other goroutines it needs to perform its functions.
207-
func (b *BreachArbiter) Start() error {
207+
// Start is an idempotent method that officially starts the BreachArbitrator
208+
// along with all other goroutines it needs to perform its functions.
209+
func (b *BreachArbitrator) Start() error {
208210
var err error
209211
b.started.Do(func() {
210212
brarLog.Info("Breach arbiter starting")
@@ -213,7 +215,7 @@ func (b *BreachArbiter) Start() error {
213215
return err
214216
}
215217

216-
func (b *BreachArbiter) start() error {
218+
func (b *BreachArbitrator) start() error {
217219
// Load all retributions currently persisted in the retribution store.
218220
var breachRetInfos map[wire.OutPoint]retributionInfo
219221
if err := b.cfg.Store.ForAll(func(ret *retributionInfo) error {
@@ -305,10 +307,10 @@ func (b *BreachArbiter) start() error {
305307
return nil
306308
}
307309

308-
// Stop is an idempotent method that signals the BreachArbiter to execute a
310+
// Stop is an idempotent method that signals the BreachArbitrator to execute a
309311
// graceful shutdown. This function will block until all goroutines spawned by
310-
// the BreachArbiter have gracefully exited.
311-
func (b *BreachArbiter) Stop() error {
312+
// the BreachArbitrator have gracefully exited.
313+
func (b *BreachArbitrator) Stop() error {
312314
b.stopped.Do(func() {
313315
brarLog.Infof("Breach arbiter shutting down...")
314316
defer brarLog.Debug("Breach arbiter shutdown complete")
@@ -321,13 +323,13 @@ func (b *BreachArbiter) Stop() error {
321323

322324
// IsBreached queries the breach arbiter's retribution store to see if it is
323325
// aware of any channel breaches for a particular channel point.
324-
func (b *BreachArbiter) IsBreached(chanPoint *wire.OutPoint) (bool, error) {
326+
func (b *BreachArbitrator) IsBreached(chanPoint *wire.OutPoint) (bool, error) {
325327
return b.cfg.Store.IsBreached(chanPoint)
326328
}
327329

328330
// SubscribeBreachComplete is used by outside subsystems to be notified of a
329331
// successful breach resolution.
330-
func (b *BreachArbiter) SubscribeBreachComplete(chanPoint *wire.OutPoint,
332+
func (b *BreachArbitrator) SubscribeBreachComplete(chanPoint *wire.OutPoint,
331333
c chan struct{}) (bool, error) {
332334

333335
breached, err := b.cfg.Store.IsBreached(chanPoint)
@@ -353,9 +355,9 @@ func (b *BreachArbiter) SubscribeBreachComplete(chanPoint *wire.OutPoint,
353355
return false, nil
354356
}
355357

356-
// notifyBreachComplete is used by the BreachArbiter to notify outside
358+
// notifyBreachComplete is used by the BreachArbitrator to notify outside
357359
// subsystems that the breach resolution process is complete.
358-
func (b *BreachArbiter) notifyBreachComplete(chanPoint *wire.OutPoint) {
360+
func (b *BreachArbitrator) notifyBreachComplete(chanPoint *wire.OutPoint) {
359361
b.Lock()
360362
defer b.Unlock()
361363
if c, ok := b.subscriptions[*chanPoint]; ok {
@@ -366,15 +368,15 @@ func (b *BreachArbiter) notifyBreachComplete(chanPoint *wire.OutPoint) {
366368
delete(b.subscriptions, *chanPoint)
367369
}
368370

369-
// contractObserver is the primary goroutine for the BreachArbiter. This
371+
// contractObserver is the primary goroutine for the BreachArbitrator. This
370372
// goroutine is responsible for handling breach events coming from the
371373
// contractcourt on the ContractBreaches channel. If a channel breach is
372374
// detected, then the contractObserver will execute the retribution logic
373375
// required to sweep ALL outputs from a contested channel into the daemon's
374376
// wallet.
375377
//
376378
// NOTE: This MUST be run as a goroutine.
377-
func (b *BreachArbiter) contractObserver() {
379+
func (b *BreachArbitrator) contractObserver() {
378380
defer b.wg.Done()
379381

380382
brarLog.Infof("Starting contract observer, watching for breaches.")
@@ -406,7 +408,7 @@ type spend struct {
406408
// returns the spend details for those outputs. The spendNtfns map is a cache
407409
// used to store registered spend subscriptions, in case we must call this
408410
// method multiple times.
409-
func (b *BreachArbiter) waitForSpendEvent(breachInfo *retributionInfo,
411+
func (b *BreachArbitrator) waitForSpendEvent(breachInfo *retributionInfo,
410412
spendNtfns map[wire.OutPoint]*chainntnfs.SpendEvent) ([]spend, error) {
411413

412414
inputs := breachInfo.breachedOutputs
@@ -684,8 +686,10 @@ func updateBreachInfo(breachInfo *retributionInfo, spends []spend) (
684686
// the lingering funds within the channel into the daemon's wallet.
685687
//
686688
// NOTE: This MUST be run as a goroutine.
687-
func (b *BreachArbiter) exactRetribution(confChan *chainntnfs.ConfirmationEvent,
688-
breachInfo *retributionInfo) {
689+
//
690+
//nolint:funlen
691+
func (b *BreachArbitrator) exactRetribution(
692+
confChan *chainntnfs.ConfirmationEvent, breachInfo *retributionInfo) {
689693

690694
defer b.wg.Done()
691695

@@ -916,7 +920,7 @@ Loop:
916920

917921
// cleanupBreach marks the given channel point as fully resolved and removes the
918922
// retribution for that the channel from the retribution store.
919-
func (b *BreachArbiter) cleanupBreach(chanPoint *wire.OutPoint) error {
923+
func (b *BreachArbitrator) cleanupBreach(chanPoint *wire.OutPoint) error {
920924
// With the channel closed, mark it in the database as such.
921925
err := b.cfg.DB.MarkChanFullyClosed(chanPoint)
922926
if err != nil {
@@ -943,15 +947,17 @@ func (b *BreachArbiter) cleanupBreach(chanPoint *wire.OutPoint) error {
943947
}
944948

945949
// handleBreachHandoff handles a new breach event, by writing it to disk, then
946-
// notifies the BreachArbiter contract observer goroutine that a channel's
950+
// notifies the BreachArbitrator contract observer goroutine that a channel's
947951
// contract has been breached by the prior counterparty. Once notified the
948-
// BreachArbiter will attempt to sweep ALL funds within the channel using the
952+
// BreachArbitrator will attempt to sweep ALL funds within the channel using the
949953
// information provided within the BreachRetribution generated due to the
950954
// breach of channel contract. The funds will be swept only after the breaching
951955
// transaction receives a necessary number of confirmations.
952956
//
953957
// NOTE: This MUST be run as a goroutine.
954-
func (b *BreachArbiter) handleBreachHandoff(breachEvent *ContractBreachEvent) {
958+
func (b *BreachArbitrator) handleBreachHandoff(
959+
breachEvent *ContractBreachEvent) {
960+
955961
defer b.wg.Done()
956962

957963
chanPoint := breachEvent.ChanPoint
@@ -1367,7 +1373,7 @@ type justiceTxVariants struct {
13671373
// the funds within the channel which we are now entitled to due to a breach of
13681374
// the channel's contract by the counterparty. This function returns a *fully*
13691375
// signed transaction with the witness for each input fully in place.
1370-
func (b *BreachArbiter) createJusticeTx(
1376+
func (b *BreachArbitrator) createJusticeTx(
13711377
breachedOutputs []breachedOutput) (*justiceTxVariants, error) {
13721378

13731379
var (
@@ -1442,7 +1448,7 @@ func (b *BreachArbiter) createJusticeTx(
14421448
}
14431449

14441450
// createSweepTx creates a tx that sweeps the passed inputs back to our wallet.
1445-
func (b *BreachArbiter) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
1451+
func (b *BreachArbitrator) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
14461452
error) {
14471453

14481454
if len(inputs) == 0 {
@@ -1498,7 +1504,7 @@ func (b *BreachArbiter) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
14981504

14991505
// sweepSpendableOutputsTxn creates a signed transaction from a sequence of
15001506
// spendable outputs by sweeping the funds into a single p2wkh output.
1501-
func (b *BreachArbiter) sweepSpendableOutputsTxn(txWeight int64,
1507+
func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight int64,
15021508
inputs ...input.Input) (*wire.MsgTx, error) {
15031509

15041510
// First, we obtain a new public key script from the wallet which we'll

contractcourt/breacharbiter_test.go renamed to contractcourt/breach_arbitrator_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ restartCheck:
951951
}
952952
}
953953

954-
func initBreachedState(t *testing.T) (*BreachArbiter,
954+
func initBreachedState(t *testing.T) (*BreachArbitrator,
955955
*lnwallet.LightningChannel, *lnwallet.LightningChannel,
956956
*lnwallet.LocalForceCloseSummary, chan *ContractBreachEvent) {
957957

@@ -1338,7 +1338,7 @@ func getSpendTransactions(signer input.Signer, chanPoint *wire.OutPoint,
13381338
},
13391339
}
13401340

1341-
// In order for the breacharbiter to detect that it is being spent
1341+
// In order for the BreachArbitrator to detect that it is being spent
13421342
// using the revocation key, it will inspect the witness. Therefore
13431343
// sign and add the witness to the HTLC sweep.
13441344
retInfo := newRetributionInfo(chanPoint, retribution)
@@ -1684,7 +1684,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
16841684
}
16851685

16861686
// We also keep a map of those remaining outputs we expect the
1687-
// breacharbiter to try and sweep.
1687+
// BreachArbitrator to try and sweep.
16881688
inputsToSweep := map[wire.OutPoint]struct{}{
16891689
htlcOutpoint: {},
16901690
localOutpoint: {},
@@ -1892,7 +1892,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
18921892
}
18931893

18941894
// Now mine another block without the justice tx confirming. This
1895-
// should lead to the breacharbiter publishing the split justice tx
1895+
// should lead to the BreachArbitrator publishing the split justice tx
18961896
// variants.
18971897
notifier.EpochChan <- &chainntnfs.BlockEpoch{
18981898
Height: blockHeight + 4,
@@ -1988,7 +1988,7 @@ func findInputIndex(t *testing.T, op wire.OutPoint, tx *wire.MsgTx) int {
19881988

19891989
// assertArbiterBreach checks that the breach arbiter has persisted the breach
19901990
// information for a particular channel.
1991-
func assertArbiterBreach(t *testing.T, brar *BreachArbiter,
1991+
func assertArbiterBreach(t *testing.T, brar *BreachArbitrator,
19921992
chanPoint *wire.OutPoint) {
19931993

19941994
t.Helper()
@@ -2008,7 +2008,7 @@ func assertArbiterBreach(t *testing.T, brar *BreachArbiter,
20082008

20092009
// assertNoArbiterBreach checks that the breach arbiter has not persisted the
20102010
// breach information for a particular channel.
2011-
func assertNoArbiterBreach(t *testing.T, brar *BreachArbiter,
2011+
func assertNoArbiterBreach(t *testing.T, brar *BreachArbitrator,
20122012
chanPoint *wire.OutPoint) {
20132013

20142014
t.Helper()
@@ -2027,7 +2027,7 @@ func assertNoArbiterBreach(t *testing.T, brar *BreachArbiter,
20272027

20282028
// assertBrarCleanup blocks until the given channel point has been removed the
20292029
// retribution store and the channel is fully closed in the database.
2030-
func assertBrarCleanup(t *testing.T, brar *BreachArbiter,
2030+
func assertBrarCleanup(t *testing.T, brar *BreachArbitrator,
20312031
chanPoint *wire.OutPoint, db *channeldb.ChannelStateDB) {
20322032

20332033
t.Helper()
@@ -2108,7 +2108,7 @@ func assertNotPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
21082108
// createTestArbiter instantiates a breach arbiter with a failing retribution
21092109
// store, so that controlled failures can be tested.
21102110
func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
2111-
db *channeldb.DB) (*BreachArbiter, error) {
2111+
db *channeldb.DB) (*BreachArbitrator, error) {
21122112

21132113
// Create a failing retribution store, that wraps a normal one.
21142114
store := newFailingRetributionStore(func() RetributionStorer {
@@ -2120,7 +2120,7 @@ func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
21202120

21212121
// Assemble our test arbiter.
21222122
notifier := mock.MakeMockSpendNotifier()
2123-
ba := NewBreachArbiter(&BreachConfig{
2123+
ba := NewBreachArbitrator(&BreachConfig{
21242124
CloseLink: func(_ *wire.OutPoint, _ ChannelCloseType) {},
21252125
DB: db.ChannelStateDB(),
21262126
Estimator: chainfee.NewStaticEstimator(12500, 0),

contractcourt/breach_resolver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
)
99

1010
// breachResolver is a resolver that will handle breached closes. In the
11-
// future, this will likely take over the duties the current breacharbiter has.
11+
// future, this will likely take over the duties the current BreachArbitrator
12+
// has.
1213
type breachResolver struct {
1314
// resolved reflects if the contract has been fully resolved or not.
1415
resolved bool
1516

1617
// subscribed denotes whether or not the breach resolver has subscribed
17-
// to the breacharbiter for breach resolution.
18+
// to the BreachArbitrator for breach resolution.
1819
subscribed bool
1920

2021
// replyChan is closed when the breach arbiter has completed serving
@@ -42,8 +43,8 @@ func (b *breachResolver) ResolverKey() []byte {
4243
return key[:]
4344
}
4445

45-
// Resolve queries the breacharbiter to see if the justice transaction has been
46-
// broadcast.
46+
// Resolve queries the BreachArbitrator to see if the justice transaction has
47+
// been broadcast.
4748
func (b *breachResolver) Resolve() (ContractResolver, error) {
4849
if !b.subscribed {
4950
complete, err := b.SubscribeBreachComplete(

contractcourt/chain_arbitrator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ type ChainArbitratorConfig struct {
100100
MarkLinkInactive func(wire.OutPoint) error
101101

102102
// ContractBreach is a function closure that the ChainArbitrator will
103-
// use to notify the breachArbiter about a contract breach. It should
104-
// only return a non-nil error when the breachArbiter has preserved
103+
// use to notify the BreachArbitrator about a contract breach. It should
104+
// only return a non-nil error when the BreachArbitrator has preserved
105105
// the necessary breach info for this channel point. Once the breach
106-
// resolution is persisted in the channel arbitrator, it will be safe
106+
// resolution is persisted in the ChannelArbitrator, it will be safe
107107
// to mark the channel closed.
108108
ContractBreach func(wire.OutPoint, *lnwallet.BreachRetribution) error
109109

0 commit comments

Comments
 (0)