Skip to content

Commit

Permalink
monitor keeper app transactions count
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Aug 14, 2024
1 parent 1ee45b9 commit 38e75e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func bundleSignerState(ctx context.Context, mdb *mtg.SQLite3Store, store *signer
state = state + fmt.Sprintf("⏲️ Run time :%s\n", time.Now().Sub(startedAt).String())
state = state + fmt.Sprintf("⏲️ Group: %s %d\n", mixinnet.HashMembers(grp.GetMembers()), grp.GetThreshold())

state = state + "\n𝗠𝙏𝗚\n"
tl, _, err := mdb.ListTransactions(ctx, mtg.TransactionStateInitial, 1000)
if err != nil {
return "", err
Expand Down Expand Up @@ -88,6 +89,7 @@ func bundleSignerState(ctx context.Context, mdb *mtg.SQLite3Store, store *signer
amount := decimal.RequireFromString(sa.String()).Div(tTredecillion).IntPart()
state = state + fmt.Sprintf("💍 MSST Balance: %d TT\n", amount)

state = state + "\n𝗔𝙋𝗣\n"
ss, err := store.SessionsState(ctx)
if err != nil {
return "", err
Expand Down Expand Up @@ -132,6 +134,7 @@ func bundleKeeperState(ctx context.Context, mdb *mtg.SQLite3Store, store *kstore
state = state + fmt.Sprintf("⏲️ Run time :%s\n", time.Now().Sub(startedAt).String())
state = state + fmt.Sprintf("⏲️ Group: %s %d\n", mixinnet.HashMembers(grp.GetMembers()), grp.GetThreshold())

state = state + "\n𝗠𝙏𝗚\n"
req, err := store.ReadLatestRequest(ctx)
if err != nil {
return "", err
Expand Down Expand Up @@ -172,6 +175,7 @@ func bundleKeeperState(ctx context.Context, mdb *mtg.SQLite3Store, store *kstore
}
state = state + fmt.Sprintf("💍 MSKT Outputs: %d\n", len(ol))

state = state + "\n𝗔𝙋𝗣\n"
sbc, err := store.CountSpareKeys(ctx, common.CurveSecp256k1ECDSABitcoin, common.RequestFlagNone, common.RequestRoleSigner)
if err != nil {
return "", err
Expand All @@ -194,6 +198,27 @@ func bundleKeeperState(ctx context.Context, mdb *mtg.SQLite3Store, store *kstore
}
state = state + fmt.Sprintf("🔑 Observer Ethereum keys: %d\n", oec)

tc, err := store.CountTransactionsByState(ctx, common.RequestStateInitial)
if err != nil {
return "", err
}
state = state + fmt.Sprintf("💷 Initial Transactions: %d\n", tc)
tc, err = store.CountTransactionsByState(ctx, common.RequestStatePending)
if err != nil {
return "", err
}
state = state + fmt.Sprintf("💶 Pending Transactions: %d\n", tc)
tc, err = store.CountTransactionsByState(ctx, common.RequestStateDone)
if err != nil {
return "", err
}
state = state + fmt.Sprintf("💵 Done Transactions: %d\n", tc)
tc, err = store.CountTransactionsByState(ctx, common.RequestStateFailed)
if err != nil {
return "", err
}
state = state + fmt.Sprintf("💸 Failed Transactions: %d\n", tc)

state = state + fmt.Sprintf("🦷 Binary version: %s", version)
return state, nil
}
Expand Down
12 changes: 12 additions & 0 deletions keeper/store/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func (s *SQLite3Store) ReadTransaction(ctx context.Context, hash string) (*Trans
return s.readTransaction(ctx, tx, hash)
}

func (s *SQLite3Store) CountTransactionsByState(ctx context.Context, state byte) (int, error) {
query := "SELECT COUNT(*) FROM transactions WHERE state=?"
row := s.db.QueryRowContext(ctx, query, state)

var count int
err := row.Scan(&count)
if err == sql.ErrNoRows {
return 0, nil
}
return count, err
}

func (s *SQLite3Store) CountUnfinishedTransactionsByHolder(ctx context.Context, holder string) (int, error) {
query := "SELECT COUNT(*) FROM transactions WHERE holder=? AND state=?"
row := s.db.QueryRowContext(ctx, query, holder, common.RequestStateInitial)
Expand Down

0 comments on commit 38e75e4

Please sign in to comment.