Skip to content

Commit

Permalink
modify based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
Faulty Tolly committed Nov 22, 2024
1 parent 9ceb70a commit 036243a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 48 deletions.
56 changes: 55 additions & 1 deletion block/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package block

import (
"context"
"github.com/dymensionxyz/dymint/types"
"fmt"
"github.com/cockroachdb/errors"
"strconv"
"sync"
"time"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/types"
)

const CheckBalancesInterval = 3 * time.Minute
Expand Down Expand Up @@ -44,3 +49,52 @@ func (m *Manager) MonitorBalances(ctx context.Context) error {
}
}
}

type Balances struct {
DA *da.Balance
SL *types.Balance
}

func (m *Manager) checkBalances() (*Balances, error) {
balances := &Balances{}
var wg sync.WaitGroup
wg.Add(2)

var errDA, errSL error

go func() {
defer wg.Done()
balance, err := m.DAClient.GetSignerBalance()
if err != nil {
errDA = fmt.Errorf("get DA signer balance: %w", err)
return
}
balances.DA = balance
}()

go func() {
defer wg.Done()
balance, err := m.SLClient.GetSignerBalance()
if err != nil {
errSL = fmt.Errorf("get SL signer balance: %w", err)
return
}
balances.SL = balance
}()

wg.Wait()

var errs error
if errDA != nil {
errs = errors.Join(errs, errDA)
}
if errSL != nil {
errs = errors.Join(errs, errSL)
}

if errs != nil {
return balances, fmt.Errorf("errors checking balances: %w", errs)
}

return balances, nil
}
47 changes: 0 additions & 47 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,53 +417,6 @@ func (m *Manager) freezeNode(err error) {
m.Cancel()
}

type Balances struct {
DA *da.Balance
SL *types.Balance
}

func (m *Manager) checkBalances() (*Balances, error) {
balances := &Balances{}
var wg sync.WaitGroup
wg.Add(2)

errChan := make(chan error, 2)

go func() {
defer wg.Done()
balance, err := m.DAClient.GetSignerBalance()
if err != nil {
errChan <- fmt.Errorf("get DA signer balance: %w", err)
return
}
balances.DA = balance
}()

go func() {
defer wg.Done()
balance, err := m.SLClient.GetSignerBalance()
if err != nil {
errChan <- fmt.Errorf("get SL signer balance: %w", err)
return
}
balances.SL = balance
}()

wg.Wait()
close(errChan)

var errs []error
for err := range errChan {
errs = append(errs, err)
}

if len(errs) > 0 {
return balances, fmt.Errorf("errors checking balances: %v", errs)
}

return balances, nil
}

// SetLastBlockTimeInSettlementFromHeight is used to initialize LastBlockTimeInSettlement from rollapp height in settlement
func (m *Manager) SetLastBlockTimeInSettlementFromHeight(lastSettlementHeight uint64) {
block, err := m.Store.LoadBlock(lastSettlementHeight)
Expand Down

0 comments on commit 036243a

Please sign in to comment.