@@ -54,8 +54,10 @@ type ArbitratorLog interface {
54
54
// TODO(roasbeef): document on interface the errors expected to be
55
55
// returned
56
56
57
- // CurrentState returns the current state of the ChannelArbitrator.
58
- CurrentState () (ArbitratorState , error )
57
+ // CurrentState returns the current state of the ChannelArbitrator. It
58
+ // takes an optional database transaction, which will be used if it is
59
+ // non-nil, otherwise the lookup will be done in its own transaction.
60
+ CurrentState (tx kvdb.RTx ) (ArbitratorState , error )
59
61
60
62
// CommitState persists, the current state of the chain attendant.
61
63
CommitState (ArbitratorState ) error
@@ -96,8 +98,10 @@ type ArbitratorLog interface {
96
98
InsertConfirmedCommitSet (c * CommitSet ) error
97
99
98
100
// FetchConfirmedCommitSet fetches the known confirmed active HTLC set
99
- // from the database.
100
- FetchConfirmedCommitSet () (* CommitSet , error )
101
+ // from the database. It takes an optional database transaction, which
102
+ // will be used if it is non-nil, otherwise the lookup will be done in
103
+ // its own transaction.
104
+ FetchConfirmedCommitSet (tx kvdb.RTx ) (* CommitSet , error )
101
105
102
106
// FetchChainActions attempts to fetch the set of previously stored
103
107
// chain actions. We'll use this upon restart to properly advance our
@@ -412,32 +416,47 @@ func (b *boltArbitratorLog) writeResolver(contractBucket kvdb.RwBucket,
412
416
return contractBucket .Put (resKey , buf .Bytes ())
413
417
}
414
418
415
- // CurrentState returns the current state of the ChannelArbitrator.
419
+ // CurrentState returns the current state of the ChannelArbitrator. It takes an
420
+ // optional database transaction, which will be used if it is non-nil, otherwise
421
+ // the lookup will be done in its own transaction.
416
422
//
417
423
// NOTE: Part of the ContractResolver interface.
418
- func (b * boltArbitratorLog ) CurrentState () (ArbitratorState , error ) {
419
- var s ArbitratorState
420
- err := kvdb .View (b .db , func (tx kvdb.RTx ) error {
421
- scopeBucket := tx .ReadBucket (b .scopeKey [:])
422
- if scopeBucket == nil {
423
- return errScopeBucketNoExist
424
- }
424
+ func (b * boltArbitratorLog ) CurrentState (tx kvdb.RTx ) (ArbitratorState , error ) {
425
+ var (
426
+ s ArbitratorState
427
+ err error
428
+ )
425
429
426
- stateBytes := scopeBucket .Get (stateKey )
427
- if stateBytes == nil {
428
- return nil
429
- }
430
+ if tx != nil {
431
+ s , err = b .currentState (tx )
432
+ } else {
433
+ err = kvdb .View (b .db , func (tx kvdb.RTx ) error {
434
+ s , err = b .currentState (tx )
435
+ return err
436
+ })
437
+ }
430
438
431
- s = ArbitratorState (stateBytes [0 ])
432
- return nil
433
- })
434
439
if err != nil && err != errScopeBucketNoExist {
435
440
return s , err
436
441
}
437
442
438
443
return s , nil
439
444
}
440
445
446
+ func (b * boltArbitratorLog ) currentState (tx kvdb.RTx ) (ArbitratorState , error ) {
447
+ scopeBucket := tx .ReadBucket (b .scopeKey [:])
448
+ if scopeBucket == nil {
449
+ return 0 , errScopeBucketNoExist
450
+ }
451
+
452
+ stateBytes := scopeBucket .Get (stateKey )
453
+ if stateBytes == nil {
454
+ return 0 , nil
455
+ }
456
+
457
+ return ArbitratorState (stateBytes [0 ]), nil
458
+ }
459
+
441
460
// CommitState persists, the current state of the chain attendant.
442
461
//
443
462
// NOTE: Part of the ContractResolver interface.
@@ -843,29 +862,20 @@ func (b *boltArbitratorLog) InsertConfirmedCommitSet(c *CommitSet) error {
843
862
}
844
863
845
864
// FetchConfirmedCommitSet fetches the known confirmed active HTLC set from the
846
- // database.
865
+ // database. It takes an optional database transaction, which will be used if it
866
+ // is non-nil, otherwise the lookup will be done in its own transaction.
847
867
//
848
868
// NOTE: Part of the ContractResolver interface.
849
- func (b * boltArbitratorLog ) FetchConfirmedCommitSet () (* CommitSet , error ) {
869
+ func (b * boltArbitratorLog ) FetchConfirmedCommitSet (tx kvdb.RTx ) (* CommitSet , error ) {
870
+ if tx != nil {
871
+ return b .fetchConfirmedCommitSet (tx )
872
+ }
873
+
850
874
var c * CommitSet
851
875
err := kvdb .View (b .db , func (tx kvdb.RTx ) error {
852
- scopeBucket := tx .ReadBucket (b .scopeKey [:])
853
- if scopeBucket == nil {
854
- return errScopeBucketNoExist
855
- }
856
-
857
- commitSetBytes := scopeBucket .Get (commitSetKey )
858
- if commitSetBytes == nil {
859
- return errNoCommitSet
860
- }
861
-
862
- commitSet , err := decodeCommitSet (bytes .NewReader (commitSetBytes ))
863
- if err != nil {
864
- return err
865
- }
866
-
867
- c = commitSet
868
- return nil
876
+ var err error
877
+ c , err = b .fetchConfirmedCommitSet (tx )
878
+ return err
869
879
})
870
880
if err != nil {
871
881
return nil , err
@@ -874,6 +884,22 @@ func (b *boltArbitratorLog) FetchConfirmedCommitSet() (*CommitSet, error) {
874
884
return c , nil
875
885
}
876
886
887
+ func (b * boltArbitratorLog ) fetchConfirmedCommitSet (tx kvdb.RTx ) (* CommitSet ,
888
+ error ) {
889
+
890
+ scopeBucket := tx .ReadBucket (b .scopeKey [:])
891
+ if scopeBucket == nil {
892
+ return nil , errScopeBucketNoExist
893
+ }
894
+
895
+ commitSetBytes := scopeBucket .Get (commitSetKey )
896
+ if commitSetBytes == nil {
897
+ return nil , errNoCommitSet
898
+ }
899
+
900
+ return decodeCommitSet (bytes .NewReader (commitSetBytes ))
901
+ }
902
+
877
903
// WipeHistory is to be called ONLY once *all* contracts have been fully
878
904
// resolved, and the channel closure if finalized. This method will delete all
879
905
// on-disk state within the persistent log.
0 commit comments