Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new block format support for eosmechanics #35

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ localblocks
rpc-cache
localdata
*.spkg
!/**/imports/*.spkg

### VisualStudioCode template
.vscode/*
Expand Down
9 changes: 6 additions & 3 deletions eosmechanics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[package]
name = "eosmechanics"
version = "0.3.6"
authors = ["Denis <[email protected]>", "Fred <[email protected]>", "Charles <[email protected]>"]
version = "0.4.0"
authors = [
"Denis <[email protected]>",
"Fred <[email protected]>",
"Charles <[email protected]>",
]
description = "Block Producer Benchmarks"
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -17,7 +21,6 @@ crate-type = ["cdylib"]
prost = { workspace = true }
prost-types = { workspace = true }
substreams = { workspace = true }
# substreams-antelope = { workspace = true }
substreams-antelope = "0.5"
substreams-sink-kv = { workspace = true }
substreams-sink-prometheus = { workspace = true }
10 changes: 7 additions & 3 deletions eosmechanics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ info:

.PHONY: run
run:
substreams run -e telos.substreams.pinax.network:443 prom_out -s 273976005 -o jsonl
substreams run ./substreams.yaml -e telos.substreams.pinax.network:443 prom_out -s 273976005 -o jsonl

.PHONY: gui
gui:
substreams gui -e kylin.substreams.pinax.network:443 prom_out -s 273976005 -t +1000
substreams gui ./substreams.yaml -e eos.substreams.pinax.network:443 prom_out -s 396958039

.PHONY: cache
cache:
substreams gui ./substreams.yaml -e eos.substreams.pinax.network:443 prom_out -s 396958039 -t 0 --production-mode

.PHONY: sink
sink:
substreams-sink-prometheus run -e eos.substreams.pinax.network:443 https://github.com/pinax-network/substreams/releases/download/eosmechanics-v0.3.5/eosmechanics-v0.3.5.spkg -s 292103130
substreams-sink-prometheus run -e eos.substreams.pinax.network:443 https://github.com/pinax-network/substreams/releases/download/eosmechanics-v0.3.5/eosmechanics-v0.3.5.spkg -s 292103130 prom_out

Binary file not shown.
20 changes: 15 additions & 5 deletions eosmechanics/src/maps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use substreams::errors::Error;
use substreams::{errors::Error, skip_empty_output};
use substreams_antelope::pb::{Block, ProducerAuthoritySchedule};

use crate::eosmechanics::{ProducerUsage, ScheduleChange};
Expand Down Expand Up @@ -29,6 +29,8 @@ use crate::eosmechanics::{ProducerUsage, ScheduleChange};
/// producer.
#[substreams::handlers::map]
pub fn map_producer_usage(block: Block) -> Result<ProducerUsage, Error> {
skip_empty_output();

// Producer is found in the block header
let producer = block.header.as_ref().unwrap().producer.clone();

Expand All @@ -54,11 +56,19 @@ pub fn map_producer_usage(block: Block) -> Result<ProducerUsage, Error> {

#[substreams::handlers::map]
pub fn map_schedule_change(block: Block) -> Result<ScheduleChange, Error> {
let active_schedule: Vec<String> = schedule_to_accounts(block.active_schedule_v2.as_ref().unwrap());
let pending_schedule: Vec<String> = schedule_to_accounts(block.pending_schedule.as_ref().unwrap().schedule_v2.as_ref().unwrap());
skip_empty_output();

let active_schedule: Vec<String> = match block.proposer_policy.as_ref() {
Some(proposer_policy) => schedule_to_accounts(proposer_policy.proposer_schedule.as_ref().unwrap()), // New
None => schedule_to_accounts(block.active_schedule_v2.as_ref().unwrap()), // Old
};
let pending_schedule: Vec<String> = match block.pending_schedule.as_ref() {
Some(pending_schedule) => schedule_to_accounts(pending_schedule.schedule_v2.as_ref().unwrap()), // Old
None => vec![], // New
};

// If there is no pending schedule, then there is no schedule change
if pending_schedule.is_empty() {
// If there is no pending schedule and it's old block format, then there is no schedule change
if pending_schedule.is_empty() && block.proposer_policy.as_ref().is_none() {
return Ok(Default::default());
}

Expand Down
10 changes: 4 additions & 6 deletions eosmechanics/src/sinks.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::collections::HashMap;

use substreams::errors::Error;
use substreams::log;
use substreams_sink_prometheus::{PrometheusOperations, Counter, Gauge, Histogram, Summary};
use substreams::{errors::Error, skip_empty_output};
use substreams_sink_prometheus::{Counter, Gauge, Histogram, PrometheusOperations, Summary};

use crate::eosmechanics::{ProducerUsage, ScheduleChange};

#[substreams::handlers::map]
pub fn prom_out(
producer_usage: ProducerUsage,
schedule_change: ScheduleChange
) -> Result<PrometheusOperations, Error> {
pub fn prom_out(producer_usage: ProducerUsage, schedule_change: ScheduleChange) -> Result<PrometheusOperations, Error> {
skip_empty_output();

let mut prom_out = PrometheusOperations::default();
let producer = producer_usage.producer.clone();
Expand Down
7 changes: 3 additions & 4 deletions eosmechanics/substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
specVersion: v0.1.0
package:
name: eosmechanics
version: v0.3.6
version: v0.4.0
url: https://github.com/pinax-network/substreams
doc: Block Producer Benchmarks

# imports:
# prometheus: https://github.com/pinax-network/substreams-sink-prometheus.rs/releases/download/v0.2.0/substreams-sink-prometheus-v0.2.0.spkg
imports:
prometheus: ./imports/substreams-sink-prometheus-v0.2.0.spkg

binaries:
default:
Expand Down
Loading
Loading