diff --git a/app/data/pool.go b/app/data/pool.go index a947a32..c6e4673 100644 --- a/app/data/pool.go +++ b/app/data/pool.go @@ -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 { diff --git a/app/data/response.go b/app/data/response.go index d153d35..1937d80 100644 --- a/app/data/response.go +++ b/app/data/response.go @@ -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 diff --git a/app/server/server.go b/app/server/server.go index 6d76657..d851554 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -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, })