Last week's update mentioned WIP work on persisting bid analysis data, and now that the patch is done, this week's update contains some notes on how it works and some useful things coming with it. So, last week I worked on the logic to persist bid analysis data in a flexible way and implemented an initial query layer on top of the DB store to get bid analysis data. I committed the cleaned-up patch here.
The reason for this work was two-fold. First, so far bid analysis have been stored in-memory as a mapping of analysis type -> count of those analysis events, so persistence was needed. Second, because of having to store analysis in-memory, you couldn't really query for results in a flexible way, e.g. for slot ranges or filter by category.
As a quick recap, a bid "analysis" is an event / object that the relay monitor generates when it receives a bid from the relay (builder) via a getHeader()
request. The relay monitor can do various analyses ranging from verifying bid w.r.t consensus to verifying validator preferences and whether the bid / corresponding payload conforms to these. For now, the relay monitor has just the consensus-lever analysis / verification, but adding new analyzers will be very easy. Regardless, with persistance to DB, the analysis data is being stored into a table with a following schema (i.e. format)
The "context" data helps identify the bid (in a followup PR this can be refactored to not require this much duplication). The category
field indentifies what the result of the analysis was and right now is defined as the following enum
The reason
is an optional string that the analyzer can use to provide context.
Given this, the scenarios the relay monitor handles currently are
category
is set to ValidBidCategory
, reason
is empty, and the analysis is persistedcategory
is set to InvalidBidConsensusCategory
and reason
provides an "error string"category
is set to InvalidBidIgnoredPreferencesCategory
and reason
can be used for more contextThis covers the "save" portion of bid analysis. For "get", there are now a couple of generic "getters" for analysis data from the DB can be utilized to retrieve whichever faults (or bid verification "successes") that you'd like
GetCountAnalysisWithinSlots
โ fetch analysis stats using slots as "time"GetCountAnalysisWithinDuration
โ fetch analysis stats using insertion time (used interchangeably with "analysis time" since we assume a save to DB shortly after analysis)Both functions accept a AnalysisQueryFilter
which helps filter out results. This allows queries like "count faults of class "ignored validator preference" that have occured in last 10 min".
There's a few new API endpoints for getting bid analysis stats. These are mostly for POC and are barebones so far, but show how the bid analysis numbers can be returned to a client / interested relay.
There's a number of things that can be done now, stats / analysis count wise. As an example, here's what I wrote from previous week's update:
- Support for queries of bid analysis, e.g. "count faults from slot n to n + 10" or just "how many bids have been analyzed / inserted in the last hour"
"how many bids have been analyzed / inserted in the last hour" can be queried on route
With the new endpoints "count faults from slot n to n + 10" becomes an API request to relay monitor on route
more query params can add more filtering options.
There are a few smaller-scoped features that will be added on top of this
I got started on, but didn't finish the "streaming" part of the bid analysis fault notification that I'm aiming to be done with this week. The idea is to have a nice way to be notified of faults (or successful verifications of valid bids) without having to send queries. API endpoints for stats are still useful for generic data keeping purposes, but for this to be useful to a relay we need a nice way to notify when something doesn't check out with a bid