Skip to content

Commit

Permalink
Update eos mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 2, 2023
1 parent 9a81fb6 commit cec63e7
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 74 deletions.
22 changes: 15 additions & 7 deletions eosmechanics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
### Quickstart

```
$ substreams run -e eos.firehose.eosnation.io:9001 map_block_stats -t +10
$ substreams run -e eos.firehose.eosnation.io:9001 map_producer_usage -s 292180468 -t +1
```

### Mermaid graph

```mermaid
graph TD;
map_block_stats[map: map_block_stats]
sf.antelope.type.v2.Block[source: sf.antelope.type.v2.Block] --> map_block_stats
map_producer_usage[map: map_producer_usage]
sf.antelope.type.v2.Block[source: sf.antelope.type.v2.Block] --> map_producer_usage
map_prom_out[map: map_prom_out]
map_producer_usage --> map_prom_out
```

<img width="832" alt="image" src="https://user-images.githubusercontent.com/550895/216176638-cea94a43-f95e-4eb6-ae00-527a2cb02ab7.png">
Expand All @@ -27,10 +29,16 @@ Package name: eosmechanics
Version: v0.1.0
Doc: Block Producer Benchmarks
Modules:
----
Name: map_block_stats
----
Name: map_producer_usage
Initial block: 0
Kind: map
Output Type: proto:eosmechanics.v1.BlockStats
Hash: e71870fcf747d120a130501211e1ad8770cc44b8
Output Type: proto:eosmechanics.v1.ProducerUsage
Hash: 7c6074773130dc85c3022d6b56fca8f21f06d8cf

Name: map_prom_out
Initial block: 0
Kind: map
Output Type: proto:pinax.substreams.sinks.prom.v1.PrometheusMetrics
Hash: a27326168962800fae976825c6173a6539cd8702
```
6 changes: 1 addition & 5 deletions eosmechanics/proto/v1/eosmechanics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ syntax = "proto3";

package eosmechanics.v1;

message BlockResults {
repeated ProducerStats producer_stats = 1;
}

message ProducerStats {
message ProducerUsage {
string producer = 1; // the name of the block producer
int64 cpu_usage = 2; // cpu usage of the eosmechanics transaction
}
8 changes: 8 additions & 0 deletions eosmechanics/proto/v1/sink.prom.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

package pinax.sinks.prom.v1;

message PrometheusMetrics {
// TO-DO
// Reference https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#Gauge
}
5 changes: 5 additions & 0 deletions eosmechanics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
pub mod eosmechanics;
pub use self::eosmechanics::*;

#[path = "pb/pinax.sinks.prom.v1.rs"]
#[allow(dead_code)]
pub mod sinks;
pub use self::sinks::*;

mod maps;
51 changes: 31 additions & 20 deletions eosmechanics/src/maps.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
use substreams::errors::Error;
use substreams::{log, prelude::*};
use substreams::log;
use substreams_antelope::Block;

use crate::eosmechanics::{BlockResults, ProducerStats};
use crate::eosmechanics::ProducerUsage;
use crate::sinks::PrometheusMetrics;

#[substreams::handlers::map]
pub fn map_block_stats(block: Block) -> Result<BlockResults, Error> {
pub fn map_producer_usage(block: Block) -> Result<ProducerUsage, Error> {

// ToDo parse the transaction traces of the block
// if it contains an action on account "eosmechanics" with the name "cpu" then take the
// cpu time of the transaction and the name of the producer and return it.
// Producer is found in the block header
let producer = block.clone().header.unwrap().producer;

for trx in block.clone().all_transaction_traces() {
// CPU usage is found in the transaction receipt
let cpu_usage = trx.clone().receipt.unwrap().cpu_usage_micro_seconds as i64;

// the producer can be found on the block header using:
// block.header.unwrap().producer
// Only return a value if the transaction trace contains `eosmechanics:cpu` action
for trace in trx.clone().action_traces {
let action_trace = trace.action.as_ref().unwrap().clone();
if action_trace.account != "eosmechanics" { continue; }
if action_trace.name != "cpu" { continue; }
return Ok(ProducerUsage{
producer,
cpu_usage,
})
}
}

// the cpu usage can be found in the transaction receipt

Ok(BlockResults{
producer_stats: vec![]
})
// If no transaction trace contains `eosmechanics:cpu` action, return default value
Ok(Default::default())
}

// #[substreams::handlers::map]
// pub fn prom_out(block_results: BlockResults) -> Result<PrometheusChange, Error> {
//
// ToDo push generic prometheus changes here
// this requires that we define a prometheus changes protobuf first. I (Fred) will help you on that task
//
// }
#[substreams::handlers::map]
pub fn prom_out(producer_usage: ProducerUsage) -> Result<PrometheusMetrics, Error> {
log::debug!("producer_usage={:?}", producer_usage);

// TO-DO push generic prometheus changes here
// this requires that we define a prometheus changes protobuf first. I (Fred) will help you on that task
return Ok(PrometheusMetrics::default());
}
63 changes: 23 additions & 40 deletions eosmechanics/src/pb/eosmechanics.v1.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// @generated
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BlockResults {
#[prost(message, repeated, tag="1")]
pub producer_stats: ::prost::alloc::vec::Vec<ProducerStats>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ProducerStats {
pub struct ProducerUsage {
/// the name of the block producer
#[prost(string, tag="1")]
pub producer: ::prost::alloc::string::String,
Expand All @@ -15,40 +10,28 @@ pub struct ProducerStats {
}
/// Encoded file descriptor set for the `eosmechanics.v1` package
pub const FILE_DESCRIPTOR_SET: &[u8] = &[
0x0a, 0xa0, 0x04, 0x0a, 0x12, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e, 0x69, 0x63,
0x0a, 0xec, 0x02, 0x0a, 0x12, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e, 0x69, 0x63,
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68,
0x61, 0x6e, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x55, 0x0a, 0x0c, 0x42, 0x6c, 0x6f, 0x63,
0x6b, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x45, 0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x64,
0x75, 0x63, 0x65, 0x72, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x1e, 0x2e, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e, 0x69, 0x63, 0x73, 0x2e,
0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x73,
0x52, 0x0d, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x73, 0x22,
0x48, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x73,
0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x12, 0x1b, 0x0a, 0x09,
0x63, 0x70, 0x75, 0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
0x08, 0x63, 0x70, 0x75, 0x55, 0x73, 0x61, 0x67, 0x65, 0x4a, 0xcf, 0x02, 0x0a, 0x06, 0x12, 0x04,
0x00, 0x00, 0x0b, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x08,
0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00, 0x18, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04,
0x04, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, 0x14,
0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x05, 0x04, 0x2e, 0x0a, 0x0c, 0x0a,
0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x05, 0x04, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04,
0x00, 0x02, 0x00, 0x06, 0x12, 0x03, 0x05, 0x0d, 0x1a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02,
0x00, 0x01, 0x12, 0x03, 0x05, 0x1b, 0x29, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03,
0x12, 0x03, 0x05, 0x2c, 0x2d, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, 0x12, 0x04, 0x08, 0x00, 0x0b,
0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, 0x08, 0x15, 0x0a, 0x2d, 0x0a,
0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x09, 0x04, 0x18, 0x22, 0x20, 0x20, 0x74, 0x68, 0x65,
0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x6c, 0x6f,
0x63, 0x6b, 0x20, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x0a, 0x0a, 0x0c, 0x0a, 0x05,
0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x09, 0x04, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01,
0x02, 0x00, 0x01, 0x12, 0x03, 0x09, 0x0b, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00,
0x03, 0x12, 0x03, 0x09, 0x16, 0x17, 0x0a, 0x39, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x12, 0x03,
0x0a, 0x04, 0x18, 0x22, 0x2c, 0x20, 0x63, 0x70, 0x75, 0x20, 0x75, 0x73, 0x61, 0x67, 0x65, 0x20,
0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e,
0x69, 0x63, 0x73, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20,
0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x05, 0x12, 0x03, 0x0a, 0x04, 0x09, 0x0a,
0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, 0x0a, 0x13, 0x0a, 0x0c, 0x0a,
0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0a, 0x16, 0x17, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x61, 0x6e, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x48, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x64,
0x75, 0x63, 0x65, 0x72, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f,
0x64, 0x75, 0x63, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f,
0x64, 0x75, 0x63, 0x65, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x70, 0x75, 0x5f, 0x75, 0x73, 0x61,
0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x63, 0x70, 0x75, 0x55, 0x73, 0x61,
0x67, 0x65, 0x4a, 0xf2, 0x01, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00, 0x07, 0x01, 0x0a, 0x08, 0x0a,
0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00,
0x18, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x04, 0x00, 0x07, 0x01, 0x0a, 0x0a, 0x0a,
0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, 0x15, 0x0a, 0x2d, 0x0a, 0x04, 0x04, 0x00, 0x02,
0x00, 0x12, 0x03, 0x05, 0x04, 0x18, 0x22, 0x20, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6e, 0x61, 0x6d,
0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x70,
0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00,
0x05, 0x12, 0x03, 0x05, 0x04, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12,
0x03, 0x05, 0x0b, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x05,
0x16, 0x17, 0x0a, 0x39, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x06, 0x04, 0x18, 0x22,
0x2c, 0x20, 0x63, 0x70, 0x75, 0x20, 0x75, 0x73, 0x61, 0x67, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x65, 0x6f, 0x73, 0x6d, 0x65, 0x63, 0x68, 0x61, 0x6e, 0x69, 0x63, 0x73, 0x20,
0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x0a, 0x0a, 0x0c, 0x0a,
0x05, 0x04, 0x00, 0x02, 0x01, 0x05, 0x12, 0x03, 0x06, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04,
0x00, 0x02, 0x01, 0x01, 0x12, 0x03, 0x06, 0x0a, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02,
0x01, 0x03, 0x12, 0x03, 0x06, 0x16, 0x17, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
];
// @@protoc_insertion_point(module)
24 changes: 24 additions & 0 deletions eosmechanics/src/pb/pinax.sinks.prom.v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @generated
/// TO-DO
/// Reference <https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#Gauge>
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PrometheusMetrics {
}
/// Encoded file descriptor set for the `pinax.sinks.prom.v1` package
pub const FILE_DESCRIPTOR_SET: &[u8] = &[
0x0a, 0xd6, 0x01, 0x0a, 0x0f, 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x70, 0x69, 0x6e, 0x61, 0x78, 0x2e, 0x73, 0x69, 0x6e, 0x6b,
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x2e, 0x76, 0x31, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x72, 0x6f,
0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x4a, 0x90,
0x01, 0x0a, 0x06, 0x12, 0x04, 0x02, 0x00, 0x09, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03,
0x02, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x04, 0x00, 0x1c, 0x0a, 0x66, 0x0a,
0x02, 0x04, 0x00, 0x12, 0x04, 0x06, 0x00, 0x09, 0x01, 0x22, 0x5a, 0x20, 0x54, 0x4f, 0x2d, 0x44,
0x4f, 0x0a, 0x20, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x20, 0x68, 0x74, 0x74,
0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x70, 0x6b, 0x67, 0x2e, 0x67, 0x6f, 0x2e, 0x64, 0x65, 0x76, 0x2f,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65,
0x74, 0x68, 0x65, 0x75, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x67, 0x6f, 0x6c,
0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x23, 0x47,
0x61, 0x75, 0x67, 0x65, 0x0a, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x06, 0x08,
0x19, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
];
// @@protoc_insertion_point(module)
14 changes: 12 additions & 2 deletions eosmechanics/substreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ binaries:
protobuf:
files:
- eosmechanics.proto
- sink.prom.proto
importPaths:
- proto/v1

modules:
- name: map_block_stats
- name: map_producer_usage
kind: map
inputs:
- source: sf.antelope.type.v2.Block
output:
type: proto:eosmechanics.v1.BlockStats
type: proto:eosmechanics.v1.ProducerUsage

- name: map_prom_out
kind: map
inputs:
- map: map_producer_usage
output:
type: proto:pinax.substreams.sink.prom.v1.PrometheusMetrics


0 comments on commit cec63e7

Please sign in to comment.