@@ -613,15 +613,44 @@ func (c *ChainArbitrator) Start() error {
613
613
}
614
614
}
615
615
616
+ // Create a single read tx that we can use for all of our arbitrators
617
+ // db lookups as we start them. This reduces our load to a single tx
618
+ // rather than 2 * number of chan arbitrators.
619
+ tx , err := c .chanSource .BeginReadTx ()
620
+ if err != nil {
621
+ if stopErr := c .Stop (); stopErr != nil {
622
+ log .Errorf ("chain arb stop error: %v" , err )
623
+ }
624
+
625
+ return fmt .Errorf ("could no create chain arb start tx: %v" , err )
626
+ }
627
+
616
628
// Launch all the goroutines for each arbitrator so they can carry out
617
629
// their duties.
618
630
for _ , arbitrator := range c .activeChannels {
619
- if err := arbitrator .Start (nil ); err != nil {
620
- c .Stop ()
631
+ if err := arbitrator .Start (tx ); err != nil {
632
+ if stopErr := c .Stop (); stopErr != nil {
633
+ log .Errorf ("chain arb stop error: %v" , err )
634
+ }
635
+
636
+ if rollbackErr := tx .Rollback (); rollbackErr != nil {
637
+ log .Errorf ("chain arb tx rollback failed: %v" ,
638
+ err )
639
+ }
640
+
621
641
return err
622
642
}
623
643
}
624
644
645
+ if err := tx .Rollback (); err != nil {
646
+ if stopErr := c .Stop (); stopErr != nil {
647
+ log .Errorf ("chain arb stop error: %v" , err )
648
+ }
649
+
650
+ return fmt .Errorf ("could not rollback chain arb start tx: %v" ,
651
+ err )
652
+ }
653
+
625
654
// Subscribe to a single stream of block epoch notifications that we
626
655
// will dispatch to all active arbitrators.
627
656
blockEpoch , err := c .cfg .Notifier .RegisterBlockEpochNtfn (nil )
0 commit comments