pinax-network / substreams

Substreams built by Pinax
Apache License 2.0
5 stars 2 forks source link

[Substream Proposal] Blocktivity #1

Closed fschoell closed 1 year ago

fschoell commented 2 years ago

Goal

Blocktivity is a tool that calculates the actions / transactions on chain and buckets them into hourly intervals. The current implementation can be found here. It would make sense to re-implement this tool as a Substream.

Models

message Blocktivity {
  uint64 block_num = 1;                     # block number 
  google.protobuf.Timestamp timestamp = 2;  # block creation timestamp (UTC)
  uint64 trxCount = 3;                      # number of transactions in this block
  uint64 actCount = 4;                      # number of actions in this block
  uint64 cpuUsageUs = 5;                    # cpu_usage_us of this block
  uint64 netUsageWords = 6;                 # net_usage_words of this block
}

Maps

map_blocktivity - Transforms a full block into a Blocktivity object

Stores

Each store will get the Blocktivity objects, calculate the key (the timestamp of the hour of this block) and then accumulates the data in multiple StoreAddInt64 stores.

store_trx_count - Adds up the number of transactions per key (hour) store_act_count - Adds up the number of actions per key (hour) store_cpu_usage_us - Adds up the cpu_usage_us values per key (hour) store_net_usage_words - Adds up the net_usage_words per key (hour)

Consumers

This would probably be consumed by a custom consumer (Golang/NodeJS) that reads in the buckets and pushes the data as transactions to chain whenever a bucket is full (the current hour has passed).

matthewdarwin commented 1 year ago

When building this proposal consider that other blockchains don't have all the same data elements. (eg cpu/net is Antelope specific). On Ethererum chains you might want to count gas fees.

fschoell commented 1 year ago

added a first draft implementation in here: https://github.com/EOS-Nation/substreams-monorepo/tree/develop/substreams/blocktivity

DenisCarriere commented 1 year ago

Moved to https://github.com/pinax-network/subtivity-substreams/issues/5