Skip to content

Commit 3ea2145

Browse files
committed
contractcourt: use single read transaction to startup channel arbs
1 parent 945b143 commit 3ea2145

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

contractcourt/chain_arbitrator.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,44 @@ func (c *ChainArbitrator) Start() error {
613613
}
614614
}
615615

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+
616628
// Launch all the goroutines for each arbitrator so they can carry out
617629
// their duties.
618630
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+
621641
return err
622642
}
623643
}
624644

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+
625654
// Subscribe to a single stream of block epoch notifications that we
626655
// will dispatch to all active arbitrators.
627656
blockEpoch, err := c.cfg.Notifier.RegisterBlockEpochNtfn(nil)

0 commit comments

Comments
 (0)