Creating 3 libraries, for plugin, client and common code between them

This commit is contained in:
Godmode Galactus 2024-05-10 11:46:04 +02:00
commit 0341559027
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
19 changed files with 4030 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

3801
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

48
Cargo.toml Normal file
View File

@ -0,0 +1,48 @@
[workspace]
resolver = "2"
members = [
"plugin",
"client",
"common"
]
[workspace.package]
version = "0.1.0"
authors = ["gmgalactus <gmgalactus@mango.markets>"]
repository = "https://github.com/blockworks-foundation/quic-geyser-plugin"
license = "AGPL"
edition = "2021"
[workspace.dependencies]
tokio = "1.37.0"
solana-sdk = "~1.18.11"
agave-geyser-plugin-interface = "~1.18.11"
solana-streamer = "~1.18.11"
itertools = "0.10.5"
serde = "1.0.201"
clap = "4.2.4"
serde_json = "1.0.96"
bincode = "1.3.3"
bs58 = "0.4.0"
base64 = "0.21.0"
thiserror = "1.0.40"
futures = "0.3.28"
bytes = "1.4.0"
anyhow = "1.0.70"
log = "0.4.17"
const_env = "0.1.2"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
chrono = "0.4.24"
native-tls = "0.2.11"
quinn = "0.11.0"
rustls = "=0.20.8"
rcgen = "0.10.0"
pkcs8 = "0.8.0"
pem = "1.1.1"
lz4 = "1.24.0"
quic-geyser-common = {path = "common", version="0.1.0"}
quic-geyser-client = {path = "client", version="0.1.0"}
quic-geyser-plugin = {path = "plugin", version="0.1.0"}

8
client/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "quic-geyser-client"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

0
client/src/lib.rs Normal file
View File

12
common/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "quic-geyser-common"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
solana-sdk = { workspace = "true" }
serde = { workspace = "true" }
bincode = { workspace = "true" }
lz4 = { workspace = "true" }

14
common/src/compression.rs Normal file
View File

@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CompressionType {
None,
Lz4Fast(u32),
Lz4(u32),
}
impl Default for CompressionType {
fn default() -> Self{
Self::Lz4Fast(8)
}
}

10
common/src/filters.rs Normal file
View File

@ -0,0 +1,10 @@
use std::collections::HashSet;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
#[derive(Serialize, Deserialize, Clone)]
pub struct AccountFilter {
owner: Option<Pubkey>,
accounts: Option<HashSet<Pubkey>>,
}

4
common/src/lib.rs Normal file
View File

@ -0,0 +1,4 @@
pub mod filters;
pub mod types;
pub mod compression;
pub mod message;

6
common/src/message.rs Normal file
View File

@ -0,0 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub enum Message {
}

View File

@ -0,0 +1,11 @@
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use super::slot_identifier::SlotIdentifier;
#[derive(Serialize, Deserialize, Clone)]
pub struct Account {
slot_identifier: SlotIdentifier,
pubkey: Pubkey,
data: Vec<u8>,
}

2
common/src/types/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod account;
pub mod slot_identifier;

View File

@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};
use solana_sdk::hash::Hash;
#[derive(Serialize, Deserialize, Clone, Copy)]
pub struct SlotIdentifier {
slot: u64,
blockhash : Hash,
}

24
plugin/Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
[package]
name = "geyser-quic-plugin"
version = "0.1.0"
edition = "2021"
authors = ["Godmode Galactus"]
[lib]
crate-type = ["cdylib", "rlib"]
[[bin]]
name = "config-check"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { workspace = "true" }
clap = { workspace = "true", features = ["derive", "env"] }
serde = { workspace = "true" }
solana-sdk = { workspace = "true" }
agave-geyser-plugin-interface = { workspace = "true" }
serde_json = { workspace = "true" }
anyhow = { workspace = "true" }
quic-geyser-common = { path = "../common" }

View File

@ -0,0 +1,16 @@
use {clap::Parser, geyser_quic_plugin::config::Config};
#[derive(Debug, Parser)]
#[clap(author, version, about)]
struct Args {
#[clap(short, long, default_value_t = String::from("config.json"))]
/// Path to config
config: String,
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let _config = Config::load_from_file(args.config)?;
println!("Config is OK!");
Ok(())
}

62
plugin/src/config.rs Normal file
View File

@ -0,0 +1,62 @@
use std::{fs::read_to_string, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, path::Path};
use agave_geyser_plugin_interface::geyser_plugin_interface::GeyserPluginError;
use quic_geyser_common::compression::CompressionType;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub libpath: String,
pub quic_plugin: ConfigQuicPlugin,
}
impl Config {
fn load_from_str(config: &str) -> std::result::Result<Self, GeyserPluginError> {
serde_json::from_str(config).map_err(|error| GeyserPluginError::ConfigFileReadError {
msg: error.to_string(),
})
}
pub fn load_from_file<P: AsRef<Path>>(file: P) -> std::result::Result<Self, GeyserPluginError> {
let config = read_to_string(file).map_err(GeyserPluginError::ConfigFileOpenError)?;
Self::load_from_str(&config)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConfigQuicPlugin {
/// Address of Grpc service.
#[serde(default = "ConfigQuicPlugin::default_address")]
pub address: SocketAddr,
#[serde(default)]
pub quic_parameters : QuicParameters,
#[serde(default)]
pub compression_parameters: CompressionParameters,
}
impl ConfigQuicPlugin {
fn default_address()-> SocketAddr {
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 10800))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuicParameters {
pub max_number_of_streams_per_client: u64,
}
impl Default for QuicParameters {
fn default() -> Self {
Self {
max_number_of_streams_per_client: 4096
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CompressionParameters {
compression_type: CompressionType,
}

2
plugin/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod quic;
pub mod config;

1
plugin/src/quic/mod.rs Normal file
View File

@ -0,0 +1 @@
mod quic_server;

View File