Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
better stat with when latest block was seen
Browse files Browse the repository at this point in the history
  • Loading branch information
itzmeanjan committed Apr 17, 2021
1 parent 6776341 commit 720f675
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/data/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func (m *MemPool) DoneTxCount() uint64 {
return m.Pending.Processed()
}

// LastSeenBlock - Last seen block by mempool & when it was seen, to be invoked
// by stat generator http request handler method
func (m *MemPool) LastSeenBlock() LastSeenBlock {
return m.Pending.GetLastSeenBlock()
}

// PendingForGTE - Returning list of tx(s), pending for more than
// x time unit
func (m *MemPool) PendingForGTE(x time.Duration) []*MemPoolTx {
Expand Down
14 changes: 9 additions & 5 deletions app/data/response.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package data

import "time"

// Stat - Response to client queries for current mempool state
// to be sent in this form
type Stat struct {
PendingPoolSize uint64 `json:"pendingPoolSize"`
QueuedPoolSize uint64 `json:"queuedPoolSize"`
Uptime string `json:"uptime"`
Processed uint64 `json:"processed"`
NetworkID uint64 `json:"networkID"`
PendingPoolSize uint64 `json:"pendingPoolSize"`
QueuedPoolSize uint64 `json:"queuedPoolSize"`
Uptime string `json:"uptime"`
Processed uint64 `json:"processed"`
LatestBlock uint64 `json:"latestBlock"`
SeenAgo time.Duration `json:"latestSeenAgo"`
NetworkID uint64 `json:"networkID"`
}

// Msg - Response message sent to client
Expand Down
4 changes: 4 additions & 0 deletions app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ func Start(ctx context.Context, res *data.Resource) {

v1.GET("/stat", func(c echo.Context) error {

latestBlock := res.Pool.LastSeenBlock()

return c.JSON(http.StatusOK, &data.Stat{
PendingPoolSize: res.Pool.PendingPoolLength(),
QueuedPoolSize: res.Pool.QueuedPoolLength(),
Uptime: time.Now().UTC().Sub(res.StartedAt).String(),
Processed: res.Pool.DoneTxCount(),
LatestBlock: latestBlock.Number,
SeenAgo: time.Now().UTC().Sub(latestBlock.At),
NetworkID: res.NetworkID,
})

Expand Down

0 comments on commit 720f675

Please sign in to comment.