-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
587 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"sync" | ||
"time" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/dymensionxyz/dymint/da" | ||
"github.com/dymensionxyz/dymint/types" | ||
) | ||
|
||
const CheckBalancesInterval = 3 * time.Minute | ||
|
||
// MonitorBalances checks the balances of the node and updates the gauges for prometheus | ||
func (m *Manager) MonitorBalances(ctx context.Context) error { | ||
ticker := time.NewTicker(CheckBalancesInterval) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case <-ticker.C: | ||
m.logger.Info("Checking balances.") | ||
balances, err := m.checkBalances() | ||
|
||
if balances.DA != nil { | ||
if amountFloat, errDA := strconv.ParseFloat(balances.DA.Amount.String(), 64); errDA == nil { | ||
types.DaLayerBalanceGauge.Set(amountFloat) | ||
} else { | ||
m.logger.Error("Parsing DA balance amount", "error", errDA) | ||
} | ||
} | ||
|
||
if balances.SL != nil { | ||
if amountFloat, errSL := strconv.ParseFloat(balances.SL.Amount.String(), 64); errSL == nil { | ||
types.HubLayerBalanceGauge.Set(amountFloat) | ||
} else { | ||
m.logger.Error("Parsing SL balance amount", "error", errSL) | ||
} | ||
} | ||
|
||
if err != nil { | ||
m.logger.Error("Checking balances", "error", err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
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() | ||
|
||
errs := errors.Join(errDA, errSL) | ||
if errs != nil { | ||
return balances, fmt.Errorf("errors checking balances: %w", errs) | ||
} | ||
|
||
return balances, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.