# MEV Polygon - Monitoring and Logging
###### tags: `Marlin`
Convince to use a managed service for logging
* https://stackoverflow.com/a/10526402/12160191
* explains why mongodb is not the ideal solution for logging
* shorturl.at/qOS24
* why managed service is better. only handles ES though
* upgrades easier
* sizing and scaling is easier
* https://logz.io/blog/the-cost-of-doing-elk-stack-on-your-own/
* configuration issues for component interaction
* maintenance issues like error reporting
* scaling up/down the cluster
* performance tuning - JVM heap and OS swap
* data retention and archiving
* handling upgrades
* https://coralogix.com/blog/how-much-does-free-elk-stack-cost-you/
ELK VS PLG
* https://www.infracloud.io/blogs/logging-in-kubernetes-efk-vs-plg-stack/
## Non-goals
* Whether any of the txns in the bundle were frontrun/sandwiched/backrun in the block
* Whether the bundle was included in a different block than desired
* Network bundle/block propogation timing related information
* Rate limiting related metrics
* Server uptime
## Tentative Architecture
Clients (bundles) / Polygon Node(blocks) -> Gateway(Logs) -> Search DB(queries) -> Dashboard(visualization)
Gateway subscribes to new heads to receive blocks included in chain. ~~We maintain the highest bid bundle indexed by block number to infer censored transactions. We infer the bundle to be censored when the max priced transaction is lower in price than the simulated price of the bundle. This is not an accurate measure by any means, however.~~ Not implementing at the moment since gas fees is not the only measure to determine if the txn is profitable. Need to look at the fees to the block proposer, doing which is expensive.
Also, note that the validator to whom the bundle has been sent may not be the producer of the block since the validator may simply be unavailable at that time. In that case, backup proposers produce the block and it is impossible for them to include the bundle.
## Tentative schema
Log
* Each bundle along with the block its included
* Each block with its list of bundles included
### Send Bundle Index schema
*Attributes*
* version
* request hash
* signing Key
* source IP
* block number
* min timestamp
* max timestamp
* reverting txns
* primary proposer
* list of txns
* block hash
* inclusion
### Flashbots Blocks Index Schema
*Attributes*
* version
* timestamp
* block number
* block hash
* block proposer
* primary proposer
* miner reward from bundles
* list of bundles included
* list of bundles censored
* list of bundles reverted
## Useful Visualizations
* Percentage of total blocks produced per day that include flashbots bundles (line)
* count_over_time({job="gateway-blocks"} | json first_bundle="included_bundle_txs[0]" | first_bundle="" [1h])
* Number of bundles landed on-chain per unit time (line)
* count_over_time({job="gateway-bundles"} | json | inclusion_status="included" [1h])
* Total number of blocks that included bundles (number)
* count_over_time({job="gateway-blocks"} [1h])
* ~~Total miner reward (number)~~
* ~~Top 5 proposers who censored transactions (pie)~~
* ~~Top 5 proposers who were unavailable (pie)~~
* ~~Top 5 proposers who reverted txns (pie)~~
## Testing params
* number of txns in a bundle
* bundle inclusion status cases