Convert Blockstore Rewards cf to protobuf (#12860)
* Add Blockstore protobuf cf type * Add Rewards message to proto and make generated pub * Convert Rewards cf to ProtobufColumn * Add bench * Adjust tags * Move solana proto definitions and conversion methods to new crate
This commit is contained in:
24
storage-proto/Cargo.toml
Normal file
24
storage-proto/Cargo.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "solana-storage-proto"
|
||||
version = "1.5.0"
|
||||
description = "Solana Storage Protobuf Definitions"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.2.1"
|
||||
prost = "0.6.1"
|
||||
serde = "1.0.112"
|
||||
serde_derive = "1.0.103"
|
||||
solana-sdk = { path = "../sdk", version = "1.5.0" }
|
||||
solana-transaction-status = { path = "../transaction-status", version = "1.5.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_storage_proto"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
1
storage-proto/build-proto/.gitignore
vendored
Normal file
1
storage-proto/build-proto/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/
|
337
storage-proto/build-proto/Cargo.lock
generated
Normal file
337
storage-proto/build-proto/Cargo.lock
generated
Normal file
@@ -0,0 +1,337 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multimap"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-build"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"heck",
|
||||
"itertools",
|
||||
"log",
|
||||
"multimap",
|
||||
"petgraph",
|
||||
"prost",
|
||||
"prost-types",
|
||||
"tempfile",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-derive"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-types"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proto"
|
||||
version = "1.5.0"
|
||||
dependencies = [
|
||||
"tonic-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e03e57e4fcbfe7749842d53e24ccb9aa12b7252dbe5e91d2acad31834c8b8fdd"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"rand",
|
||||
"redox_syscall",
|
||||
"remove_dir_all",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tonic-build"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d8d21cb568e802d77055ab7fcd43f0992206de5028de95c8d3a41118d32e8e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"prost-build",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
15
storage-proto/build-proto/Cargo.toml
Normal file
15
storage-proto/build-proto/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
description = "Blockchain, Rebuilt for Scale"
|
||||
edition = "2018"
|
||||
homepage = "https://solana.com/"
|
||||
license = "Apache-2.0"
|
||||
name = "proto"
|
||||
publish = false
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
version = "1.5.0"
|
||||
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
tonic-build = "0.2.0"
|
16
storage-proto/build-proto/src/main.rs
Normal file
16
storage-proto/build-proto/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
let out_dir = manifest_dir.join("../proto");
|
||||
let proto_files = manifest_dir.join("../src");
|
||||
|
||||
println!("Protobuf directory: {}", proto_files.display());
|
||||
println!("output directory: {}", out_dir.display());
|
||||
|
||||
tonic_build::configure()
|
||||
.build_client(true)
|
||||
.build_server(false)
|
||||
.format(true)
|
||||
.out_dir(&out_dir)
|
||||
.compile(&[proto_files.join("confirmed_block.proto")], &[proto_files])
|
||||
}
|
115
storage-proto/proto/solana.storage.confirmed_block.rs
Normal file
115
storage-proto/proto/solana.storage.confirmed_block.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ConfirmedBlock {
|
||||
#[prost(string, tag = "1")]
|
||||
pub previous_blockhash: std::string::String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub blockhash: std::string::String,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub parent_slot: u64,
|
||||
#[prost(message, repeated, tag = "4")]
|
||||
pub transactions: ::std::vec::Vec<ConfirmedTransaction>,
|
||||
#[prost(message, repeated, tag = "5")]
|
||||
pub rewards: ::std::vec::Vec<Reward>,
|
||||
#[prost(message, optional, tag = "6")]
|
||||
pub block_time: ::std::option::Option<UnixTimestamp>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ConfirmedTransaction {
|
||||
#[prost(message, optional, tag = "1")]
|
||||
pub transaction: ::std::option::Option<Transaction>,
|
||||
#[prost(message, optional, tag = "2")]
|
||||
pub meta: ::std::option::Option<TransactionStatusMeta>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Transaction {
|
||||
#[prost(bytes, repeated, tag = "1")]
|
||||
pub signatures: ::std::vec::Vec<std::vec::Vec<u8>>,
|
||||
#[prost(message, optional, tag = "2")]
|
||||
pub message: ::std::option::Option<Message>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Message {
|
||||
#[prost(message, optional, tag = "1")]
|
||||
pub header: ::std::option::Option<MessageHeader>,
|
||||
#[prost(bytes, repeated, tag = "2")]
|
||||
pub account_keys: ::std::vec::Vec<std::vec::Vec<u8>>,
|
||||
#[prost(bytes, tag = "3")]
|
||||
pub recent_blockhash: std::vec::Vec<u8>,
|
||||
#[prost(message, repeated, tag = "4")]
|
||||
pub instructions: ::std::vec::Vec<CompiledInstruction>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct MessageHeader {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub num_required_signatures: u32,
|
||||
#[prost(uint32, tag = "2")]
|
||||
pub num_readonly_signed_accounts: u32,
|
||||
#[prost(uint32, tag = "3")]
|
||||
pub num_readonly_unsigned_accounts: u32,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct TransactionStatusMeta {
|
||||
#[prost(message, optional, tag = "1")]
|
||||
pub err: ::std::option::Option<TransactionError>,
|
||||
#[prost(uint64, tag = "2")]
|
||||
pub fee: u64,
|
||||
#[prost(uint64, repeated, tag = "3")]
|
||||
pub pre_balances: ::std::vec::Vec<u64>,
|
||||
#[prost(uint64, repeated, tag = "4")]
|
||||
pub post_balances: ::std::vec::Vec<u64>,
|
||||
#[prost(message, repeated, tag = "5")]
|
||||
pub inner_instructions: ::std::vec::Vec<InnerInstructions>,
|
||||
#[prost(string, repeated, tag = "6")]
|
||||
pub log_messages: ::std::vec::Vec<std::string::String>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct TransactionError {
|
||||
#[prost(bytes, tag = "1")]
|
||||
pub err: std::vec::Vec<u8>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct InnerInstructions {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub index: u32,
|
||||
#[prost(message, repeated, tag = "2")]
|
||||
pub instructions: ::std::vec::Vec<CompiledInstruction>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct CompiledInstruction {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub program_id_index: u32,
|
||||
#[prost(bytes, tag = "2")]
|
||||
pub accounts: std::vec::Vec<u8>,
|
||||
#[prost(bytes, tag = "3")]
|
||||
pub data: std::vec::Vec<u8>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Reward {
|
||||
#[prost(string, tag = "1")]
|
||||
pub pubkey: std::string::String,
|
||||
#[prost(int64, tag = "2")]
|
||||
pub lamports: i64,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub post_balance: u64,
|
||||
#[prost(enumeration = "RewardType", tag = "4")]
|
||||
pub reward_type: i32,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Rewards {
|
||||
#[prost(message, repeated, tag = "1")]
|
||||
pub rewards: ::std::vec::Vec<Reward>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UnixTimestamp {
|
||||
#[prost(int64, tag = "1")]
|
||||
pub timestamp: i64,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
||||
#[repr(i32)]
|
||||
pub enum RewardType {
|
||||
Unspecified = 0,
|
||||
Fee = 1,
|
||||
Rent = 2,
|
||||
Staking = 3,
|
||||
Voting = 4,
|
||||
}
|
82
storage-proto/src/confirmed_block.proto
Normal file
82
storage-proto/src/confirmed_block.proto
Normal file
@@ -0,0 +1,82 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package solana.storage.ConfirmedBlock;
|
||||
|
||||
message ConfirmedBlock {
|
||||
string previous_blockhash = 1;
|
||||
string blockhash = 2;
|
||||
uint64 parent_slot = 3;
|
||||
repeated ConfirmedTransaction transactions = 4;
|
||||
repeated Reward rewards = 5;
|
||||
UnixTimestamp block_time = 6;
|
||||
}
|
||||
|
||||
message ConfirmedTransaction {
|
||||
Transaction transaction = 1;
|
||||
TransactionStatusMeta meta = 2;
|
||||
}
|
||||
|
||||
message Transaction {
|
||||
repeated bytes signatures = 1;
|
||||
Message message = 2;
|
||||
}
|
||||
|
||||
message Message {
|
||||
MessageHeader header = 1;
|
||||
repeated bytes account_keys = 2;
|
||||
bytes recent_blockhash = 3;
|
||||
repeated CompiledInstruction instructions = 4;
|
||||
}
|
||||
|
||||
message MessageHeader {
|
||||
uint32 num_required_signatures = 1;
|
||||
uint32 num_readonly_signed_accounts = 2;
|
||||
uint32 num_readonly_unsigned_accounts = 3;
|
||||
}
|
||||
|
||||
message TransactionStatusMeta {
|
||||
TransactionError err = 1;
|
||||
uint64 fee = 2;
|
||||
repeated uint64 pre_balances = 3;
|
||||
repeated uint64 post_balances = 4;
|
||||
repeated InnerInstructions inner_instructions = 5;
|
||||
repeated string log_messages = 6;
|
||||
}
|
||||
|
||||
message TransactionError {
|
||||
bytes err = 1;
|
||||
}
|
||||
|
||||
message InnerInstructions {
|
||||
uint32 index = 1;
|
||||
repeated CompiledInstruction instructions = 2;
|
||||
}
|
||||
|
||||
message CompiledInstruction {
|
||||
uint32 program_id_index = 1;
|
||||
bytes accounts = 2;
|
||||
bytes data = 3;
|
||||
}
|
||||
|
||||
enum RewardType {
|
||||
Unspecified = 0;
|
||||
Fee = 1;
|
||||
Rent = 2;
|
||||
Staking = 3;
|
||||
Voting = 4;
|
||||
}
|
||||
|
||||
message Reward {
|
||||
string pubkey = 1;
|
||||
int64 lamports = 2;
|
||||
uint64 post_balance = 3;
|
||||
RewardType reward_type = 4;
|
||||
}
|
||||
|
||||
message Rewards {
|
||||
repeated Reward rewards = 1;
|
||||
}
|
||||
|
||||
message UnixTimestamp {
|
||||
int64 timestamp = 1;
|
||||
}
|
357
storage-proto/src/convert.rs
Normal file
357
storage-proto/src/convert.rs
Normal file
@@ -0,0 +1,357 @@
|
||||
use crate::StoredExtendedRewards;
|
||||
use solana_sdk::{
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
message::{Message, MessageHeader},
|
||||
pubkey::Pubkey,
|
||||
signature::Signature,
|
||||
transaction::Transaction,
|
||||
};
|
||||
use solana_transaction_status::{
|
||||
ConfirmedBlock, InnerInstructions, Reward, RewardType, TransactionStatusMeta,
|
||||
TransactionWithStatusMeta,
|
||||
};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
pub mod generated {
|
||||
include!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
concat!("/proto/solana.storage.confirmed_block.rs")
|
||||
));
|
||||
}
|
||||
|
||||
impl From<Vec<Reward>> for generated::Rewards {
|
||||
fn from(rewards: Vec<Reward>) -> Self {
|
||||
Self {
|
||||
rewards: rewards.into_iter().map(|r| r.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::Rewards> for Vec<Reward> {
|
||||
fn from(rewards: generated::Rewards) -> Self {
|
||||
rewards.rewards.into_iter().map(|r| r.into()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoredExtendedRewards> for generated::Rewards {
|
||||
fn from(rewards: StoredExtendedRewards) -> Self {
|
||||
Self {
|
||||
rewards: rewards
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
let r: Reward = r.into();
|
||||
r.into()
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::Rewards> for StoredExtendedRewards {
|
||||
fn from(rewards: generated::Rewards) -> Self {
|
||||
rewards
|
||||
.rewards
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
let r: Reward = r.into();
|
||||
r.into()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reward> for generated::Reward {
|
||||
fn from(reward: Reward) -> Self {
|
||||
Self {
|
||||
pubkey: reward.pubkey,
|
||||
lamports: reward.lamports,
|
||||
post_balance: reward.post_balance,
|
||||
reward_type: match reward.reward_type {
|
||||
None => generated::RewardType::Unspecified,
|
||||
Some(RewardType::Fee) => generated::RewardType::Fee,
|
||||
Some(RewardType::Rent) => generated::RewardType::Rent,
|
||||
Some(RewardType::Staking) => generated::RewardType::Staking,
|
||||
Some(RewardType::Voting) => generated::RewardType::Voting,
|
||||
} as i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::Reward> for Reward {
|
||||
fn from(reward: generated::Reward) -> Self {
|
||||
Self {
|
||||
pubkey: reward.pubkey,
|
||||
lamports: reward.lamports,
|
||||
post_balance: reward.post_balance,
|
||||
reward_type: match reward.reward_type {
|
||||
0 => None,
|
||||
1 => Some(RewardType::Fee),
|
||||
2 => Some(RewardType::Rent),
|
||||
3 => Some(RewardType::Voting),
|
||||
4 => Some(RewardType::Staking),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ConfirmedBlock> for generated::ConfirmedBlock {
|
||||
fn from(confirmed_block: ConfirmedBlock) -> Self {
|
||||
let ConfirmedBlock {
|
||||
previous_blockhash,
|
||||
blockhash,
|
||||
parent_slot,
|
||||
transactions,
|
||||
rewards,
|
||||
block_time,
|
||||
} = confirmed_block;
|
||||
|
||||
Self {
|
||||
previous_blockhash,
|
||||
blockhash,
|
||||
parent_slot,
|
||||
transactions: transactions.into_iter().map(|tx| tx.into()).collect(),
|
||||
rewards: rewards.into_iter().map(|r| r.into()).collect(),
|
||||
block_time: block_time.map(|timestamp| generated::UnixTimestamp { timestamp }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<generated::ConfirmedBlock> for ConfirmedBlock {
|
||||
type Error = bincode::Error;
|
||||
fn try_from(
|
||||
confirmed_block: generated::ConfirmedBlock,
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
let generated::ConfirmedBlock {
|
||||
previous_blockhash,
|
||||
blockhash,
|
||||
parent_slot,
|
||||
transactions,
|
||||
rewards,
|
||||
block_time,
|
||||
} = confirmed_block;
|
||||
|
||||
Ok(Self {
|
||||
previous_blockhash,
|
||||
blockhash,
|
||||
parent_slot,
|
||||
transactions: transactions
|
||||
.into_iter()
|
||||
.map(|tx| tx.try_into())
|
||||
.collect::<std::result::Result<Vec<TransactionWithStatusMeta>, Self::Error>>()?,
|
||||
rewards: rewards.into_iter().map(|r| r.into()).collect(),
|
||||
block_time: block_time.map(|generated::UnixTimestamp { timestamp }| timestamp),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionWithStatusMeta> for generated::ConfirmedTransaction {
|
||||
fn from(value: TransactionWithStatusMeta) -> Self {
|
||||
let meta = if let Some(meta) = value.meta {
|
||||
Some(meta.into())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Self {
|
||||
transaction: Some(value.transaction.into()),
|
||||
meta,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<generated::ConfirmedTransaction> for TransactionWithStatusMeta {
|
||||
type Error = bincode::Error;
|
||||
fn try_from(value: generated::ConfirmedTransaction) -> std::result::Result<Self, Self::Error> {
|
||||
let meta = if let Some(meta) = value.meta {
|
||||
Some(meta.try_into()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(Self {
|
||||
transaction: value.transaction.expect("transaction is required").into(),
|
||||
meta,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Transaction> for generated::Transaction {
|
||||
fn from(value: Transaction) -> Self {
|
||||
Self {
|
||||
signatures: value
|
||||
.signatures
|
||||
.into_iter()
|
||||
.map(|signature| <Signature as AsRef<[u8]>>::as_ref(&signature).into())
|
||||
.collect(),
|
||||
message: Some(value.message.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::Transaction> for Transaction {
|
||||
fn from(value: generated::Transaction) -> Self {
|
||||
Self {
|
||||
signatures: value
|
||||
.signatures
|
||||
.into_iter()
|
||||
.map(|x| Signature::new(&x))
|
||||
.collect(),
|
||||
message: value.message.expect("message is required").into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Message> for generated::Message {
|
||||
fn from(value: Message) -> Self {
|
||||
Self {
|
||||
header: Some(value.header.into()),
|
||||
account_keys: value
|
||||
.account_keys
|
||||
.into_iter()
|
||||
.map(|key| <Pubkey as AsRef<[u8]>>::as_ref(&key).into())
|
||||
.collect(),
|
||||
recent_blockhash: value.recent_blockhash.to_bytes().into(),
|
||||
instructions: value.instructions.into_iter().map(|ix| ix.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::Message> for Message {
|
||||
fn from(value: generated::Message) -> Self {
|
||||
Self {
|
||||
header: value.header.expect("header is required").into(),
|
||||
account_keys: value
|
||||
.account_keys
|
||||
.into_iter()
|
||||
.map(|key| Pubkey::new(&key))
|
||||
.collect(),
|
||||
recent_blockhash: Hash::new(&value.recent_blockhash),
|
||||
instructions: value.instructions.into_iter().map(|ix| ix.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MessageHeader> for generated::MessageHeader {
|
||||
fn from(value: MessageHeader) -> Self {
|
||||
Self {
|
||||
num_required_signatures: value.num_required_signatures as u32,
|
||||
num_readonly_signed_accounts: value.num_readonly_signed_accounts as u32,
|
||||
num_readonly_unsigned_accounts: value.num_readonly_unsigned_accounts as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::MessageHeader> for MessageHeader {
|
||||
fn from(value: generated::MessageHeader) -> Self {
|
||||
Self {
|
||||
num_required_signatures: value.num_required_signatures as u8,
|
||||
num_readonly_signed_accounts: value.num_readonly_signed_accounts as u8,
|
||||
num_readonly_unsigned_accounts: value.num_readonly_unsigned_accounts as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
|
||||
fn from(value: TransactionStatusMeta) -> Self {
|
||||
let TransactionStatusMeta {
|
||||
status,
|
||||
fee,
|
||||
pre_balances,
|
||||
post_balances,
|
||||
inner_instructions,
|
||||
log_messages,
|
||||
} = value;
|
||||
let err = match status {
|
||||
Ok(()) => None,
|
||||
Err(err) => Some(generated::TransactionError {
|
||||
err: bincode::serialize(&err).expect("transaction error to serialize to bytes"),
|
||||
}),
|
||||
};
|
||||
let inner_instructions = inner_instructions
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|ii| ii.into())
|
||||
.collect();
|
||||
let log_messages = log_messages.unwrap_or_default();
|
||||
Self {
|
||||
err,
|
||||
fee,
|
||||
pre_balances,
|
||||
post_balances,
|
||||
inner_instructions,
|
||||
log_messages,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
|
||||
type Error = bincode::Error;
|
||||
|
||||
fn try_from(value: generated::TransactionStatusMeta) -> std::result::Result<Self, Self::Error> {
|
||||
let generated::TransactionStatusMeta {
|
||||
err,
|
||||
fee,
|
||||
pre_balances,
|
||||
post_balances,
|
||||
inner_instructions,
|
||||
log_messages,
|
||||
} = value;
|
||||
let status = match &err {
|
||||
None => Ok(()),
|
||||
Some(tx_error) => Err(bincode::deserialize(&tx_error.err)?),
|
||||
};
|
||||
let inner_instructions = Some(
|
||||
inner_instructions
|
||||
.into_iter()
|
||||
.map(|inner| inner.into())
|
||||
.collect(),
|
||||
);
|
||||
let log_messages = Some(log_messages);
|
||||
Ok(Self {
|
||||
status,
|
||||
fee,
|
||||
pre_balances,
|
||||
post_balances,
|
||||
inner_instructions,
|
||||
log_messages,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InnerInstructions> for generated::InnerInstructions {
|
||||
fn from(value: InnerInstructions) -> Self {
|
||||
Self {
|
||||
index: value.index as u32,
|
||||
instructions: value.instructions.into_iter().map(|i| i.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::InnerInstructions> for InnerInstructions {
|
||||
fn from(value: generated::InnerInstructions) -> Self {
|
||||
Self {
|
||||
index: value.index as u8,
|
||||
instructions: value.instructions.into_iter().map(|i| i.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompiledInstruction> for generated::CompiledInstruction {
|
||||
fn from(value: CompiledInstruction) -> Self {
|
||||
Self {
|
||||
program_id_index: value.program_id_index as u32,
|
||||
accounts: value.accounts,
|
||||
data: value.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::CompiledInstruction> for CompiledInstruction {
|
||||
fn from(value: generated::CompiledInstruction) -> Self {
|
||||
Self {
|
||||
program_id_index: value.program_id_index as u8,
|
||||
accounts: value.accounts,
|
||||
data: value.data,
|
||||
}
|
||||
}
|
||||
}
|
52
storage-proto/src/lib.rs
Normal file
52
storage-proto/src/lib.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::deserialize_utils::default_on_eof;
|
||||
use solana_transaction_status::{Reward, RewardType};
|
||||
|
||||
pub mod convert;
|
||||
|
||||
pub type StoredExtendedRewards = Vec<StoredExtendedReward>;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StoredExtendedReward {
|
||||
pubkey: String,
|
||||
lamports: i64,
|
||||
#[serde(deserialize_with = "default_on_eof")]
|
||||
post_balance: u64,
|
||||
#[serde(deserialize_with = "default_on_eof")]
|
||||
reward_type: Option<RewardType>,
|
||||
}
|
||||
|
||||
impl From<StoredExtendedReward> for Reward {
|
||||
fn from(value: StoredExtendedReward) -> Self {
|
||||
let StoredExtendedReward {
|
||||
pubkey,
|
||||
lamports,
|
||||
post_balance,
|
||||
reward_type,
|
||||
} = value;
|
||||
Self {
|
||||
pubkey,
|
||||
lamports,
|
||||
post_balance,
|
||||
reward_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reward> for StoredExtendedReward {
|
||||
fn from(value: Reward) -> Self {
|
||||
let Reward {
|
||||
pubkey,
|
||||
lamports,
|
||||
post_balance,
|
||||
reward_type,
|
||||
..
|
||||
} = value;
|
||||
Self {
|
||||
pubkey,
|
||||
lamports,
|
||||
post_balance,
|
||||
reward_type,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user