-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (rollapp): register balances l2 (#1247)
Co-authored-by: Faulty Tolly <@faulttolerance.net> Co-authored-by: Sergi Rene <[email protected]> Co-authored-by: keruch <[email protected]> Co-authored-by: Daniel T <[email protected]> Co-authored-by: keruch <[email protected]>
- Loading branch information
1 parent
98a3348
commit cf2976a
Showing
22 changed files
with
467 additions
and
10 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
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
60 changes: 60 additions & 0 deletions
60
mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.