# Stader monitoring
### Overview
The stader monitoring project consist of the following parts:
- Brain: in charge of collecting signatures and sending them to the infra
- Infra: in charge of verifying and storing the signatures, data visualization.
### Brain
The brain implementation will consist of:
- Infra API client: to communicate with the infra API for sending requests
- Web3signer new singing endpoint (see [PR](https://github.com/Consensys/web3signer/pull/982)). The request/response format are:
- Body REQUEST format will be
```json
{
"message": {
"platform": "dappnode",
"timestamp": "185921877",
"pubkey": "0xb48c495c19082d892f38227bced89f7199f4e9b642bf94c7f2f1ccf29c0e6a6f54d653002513aa7cd3b56c88368797ec"
}
```
- Body RESPONSE format:
```json
{
"payload": "ewogICAgIm1lc3NhZ2UiOiB7CiAgICAgICAgInBsYXRmb3JtIjogImRhcHBub2RlIiwKICAgICAgICAidGltZXN0YW1wIjogIjE4NTkyMTg3NyIsCiAgICAgICAgInB1YmtleSI6ICIweGI0OGM0OTVjMTkwODJkODkyZjM4MjI3YmNlZDg5ZjcxOTlmNGU5YjY0MmJmOTRjN2YyZjFjY2YyOWMwZTZhNmY1NGQ2NTMwMDI1MTNhYTdjZDNiNTZjODgzNjg3OTdlYyIKICAgIH0KfQ==",
"signature": "0xa8b00e7746a523346c5165dfa80ffafe52317c6fe6cdcfabd41886f9c8209b829266c5000597142b58dddbcc9c23cfd81315180acf18bb000db50d08293bc539e06a7c751d3d9dec89fb441b3ba6aefdeeff9cfed72fb41171173f22e2993e74"
}
```
- Cron for sending signatures to dappnode infra:
- The cron will append to the existing reponse from the web3signer the keys `label` and `network` so it will result into:
```json
{
"payload": "ewogICAgIm1lc3NhZ2UiOiB7CiAgICAgICAgInBsYXRmb3JtIjogImRhcHBub2RlIiwKICAgICAgICAidGltZXN0YW1wIjogIjE4NTkyMTg3NyIsCiAgICAgICAgInB1YmtleSI6ICIweGI0OGM0OTVjMTkwODJkODkyZjM4MjI3YmNlZDg5ZjcxOTlmNGU5YjY0MmJmOTRjN2YyZjFjY2YyOWMwZTZhNmY1NGQ2NTMwMDI1MTNhYTdjZDNiNTZjODgzNjg3OTdlYyIKICAgIH0KfQ==",
"signature": "0xa8b00e7746a523346c5165dfa80ffafe52317c6fe6cdcfabd41886f9c8209b829266c5000597142b58dddbcc9c23cfd81315180acf18bb000db50d08293bc539e06a7c751d3d9dec89fb441b3ba6aefdeeff9cfed72fb41171173f22e2993e74",
"network": "prater",
"label": "stader"
},
```
See upstream work https://github.com/dappnode/StakingBrain/pull/304/files#diff-b6700726da8096923be646537b8b185a1dd1a40f8966d7d5f0f6f9fc6cfa4154
### Infra
The infra will consist of the following pieces:
- API: a process that will listen to the endpoint `/signature` with the HTTP method POST. The format of the request must follow the brain format otherwise request will not be allowed:
```json
{
"payload": "ewogICAgIm1lc3NhZ2UiOiB7CiAgICAgICAgInBsYXRmb3JtIjogImRhcHBub2RlIiwKICAgICAgICAidGltZXN0YW1wIjogIjE4NTkyMTg3NyIsCiAgICAgICAgInB1YmtleSI6ICIweGI0OGM0OTVjMTkwODJkODkyZjM4MjI3YmNlZDg5ZjcxOTlmNGU5YjY0MmJmOTRjN2YyZjFjY2YyOWMwZTZhNmY1NGQ2NTMwMDI1MTNhYTdjZDNiNTZjODgzNjg3OTdlYyIKICAgIH0KfQ==",
"signature": "0xa8b00e7746a523346c5165dfa80ffafe52317c6fe6cdcfabd41886f9c8209b829266c5000597142b58dddbcc9c23cfd81315180acf18bb000db50d08293bc539e06a7c751d3d9dec89fb441b3ba6aefdeeff9cfed72fb41171173f22e2993e74",
"network": "prater",
"label": "stader"
},
```
1. valid request format
2. decode
3. write
If the format is valid the API will write to the mongoDB with the status "pending" and the . The request must be decoded before, the signautre and the payload are encoded following this format:
```json
{
"payload": BASE64_ENCODED_PAYLOAD,
"signature": HEX_ENCODED_SIGNATURE
}
```
Being the signature signed with algorithm keccak256.
The payload decoded has the format
```json
"platform": "dappnode",
"timestamp": "185921877",
"pubkey": "0xb48c495c19082d892f38227bced89f7199f4e9b642bf94c7f2f1ccf29c0e6a6f54d653002513aa7cd3b56c88368797ec"
```
**ADDITION: Would be nice to make sure this is a unique signature (meaining unique pubkey, timestamp, and network) before adding it to mongodb**
- Mongo DB: it will be a mongoDB where the verifyier and the API processese can read and write. The mongo db will have the following format:
```json
"pubkey": "",
"network": "mainnet",
"label": "solo",
"signatures": {
"signature": "",
"timestamp": "",
"platform": "dappnode",
"status": "pending"
}[],
```
This database format will assume as unique keys in the database the combination of pubke + network + (label?)
- Verifyier: the verifyer will be another nodejs process that will be polling the mongo DB for new entries, every new entry it will run a verification of:
- 1. Verify its actually a validator in the given network, otherwise drop the public key entry from the database
- 2. The signature. If the signature is valid it will write it with the status "valid" and if invalid it will be written with status "invalid"
- Future: implement veryfier as CLI
- TODO: research how to do polling https://chat.openai.com/c/472ab981-7a8d-428d-ae47-2ab2e82b25e5
- Grafana: a service for data visualization of the mongodb database, see [mongodb implementation as datasource in grafana](https://grafana.com/docs/plugins/grafana-mongodb-datasource/latest/).
- TODO: define the dashboards to create