Adding allowed connection

This commit is contained in:
Godmode Galactus 2023-10-16 11:56:16 +02:00
parent fcef6ba854
commit 0514689dc3
No known key found for this signature in database
GPG Key ID: A04142C71ABB0DEA
3 changed files with 55 additions and 29 deletions

36
Cargo.lock generated
View File

@ -3555,7 +3555,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-account-decoder" name = "solana-account-decoder"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.21.4", "base64 0.21.4",
@ -3578,7 +3578,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-address-lookup-table-program" name = "solana-address-lookup-table-program"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"bincode", "bincode",
"bytemuck", "bytemuck",
@ -3598,7 +3598,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-config-program" name = "solana-config-program"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"bincode", "bincode",
"chrono", "chrono",
@ -3611,7 +3611,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-frozen-abi" name = "solana-frozen-abi"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"ahash 0.8.3", "ahash 0.8.3",
"blake3", "blake3",
@ -3673,7 +3673,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-frozen-abi-macro" name = "solana-frozen-abi-macro"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"proc-macro2 1.0.69", "proc-macro2 1.0.69",
"quote 1.0.33", "quote 1.0.33",
@ -3696,7 +3696,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-geyser-plugin-interface" name = "solana-geyser-plugin-interface"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"log", "log",
"solana-sdk 1.16.15", "solana-sdk 1.16.15",
@ -3707,7 +3707,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-logger" name = "solana-logger"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"lazy_static", "lazy_static",
@ -3728,7 +3728,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-measure" name = "solana-measure"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"log", "log",
"solana-sdk 1.16.15", "solana-sdk 1.16.15",
@ -3737,7 +3737,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-metrics" name = "solana-metrics"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"gethostname", "gethostname",
@ -3750,7 +3750,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-perf" name = "solana-perf"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"ahash 0.8.3", "ahash 0.8.3",
"bincode", "bincode",
@ -3776,7 +3776,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-program" name = "solana-program"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"ark-bn254", "ark-bn254",
"ark-ec", "ark-ec",
@ -3884,7 +3884,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-program-runtime" name = "solana-program-runtime"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"base64 0.21.4", "base64 0.21.4",
"bincode", "bincode",
@ -3911,7 +3911,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-rayon-threadlimit" name = "solana-rayon-threadlimit"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"num_cpus", "num_cpus",
@ -3920,7 +3920,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-sdk" name = "solana-sdk"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"base64 0.21.4", "base64 0.21.4",
@ -4026,7 +4026,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-sdk-macro" name = "solana-sdk-macro"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"bs58", "bs58",
"proc-macro2 1.0.69", "proc-macro2 1.0.69",
@ -4051,7 +4051,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-streamer" name = "solana-streamer"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"bytes", "bytes",
@ -4083,7 +4083,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-transaction-status" name = "solana-transaction-status"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.21.4", "base64 0.21.4",
@ -4108,7 +4108,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-vote-program" name = "solana-vote-program"
version = "1.16.15" version = "1.16.15"
source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_v1.16.15#53907baf5868d4537dfdfca4804f07141e7a7406" source = "git+https://github.com/blockworks-foundation/solana.git?branch=geyser_send_transaction_result_plugin#4641300ad4ecb89340f1c7954be04a74dd2575f2"
dependencies = [ dependencies = [
"bincode", "bincode",
"log", "log",

View File

@ -7,9 +7,9 @@ edition = "2021"
[dependencies] [dependencies]
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time", "fs"] } tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time", "fs"] }
solana-sdk = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_v1.16.15" } solana-sdk = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_plugin" }
solana-geyser-plugin-interface = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_v1.16.15" } solana-geyser-plugin-interface = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_plugin" }
solana-streamer = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_v1.16.15" } solana-streamer = { git = "https://github.com/blockworks-foundation/solana.git", branch = "geyser_send_transaction_result_plugin" }
itertools = "0.10.5" itertools = "0.10.5"
serde = { version = "1.0.160", features = ["derive"] } serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96" serde_json = "1.0.96"

View File

@ -1,12 +1,12 @@
use std::{net::{IpAddr, Ipv4Addr, UdpSocket}, sync::Arc}; use std::{net::{IpAddr, Ipv4Addr, UdpSocket}, sync::Arc, str::FromStr};
use pem::Pem; use pem::Pem;
use quinn::{ServerConfig, IdleTimeout, Endpoint, TokioRuntime, EndpointConfig}; use quinn::{ServerConfig, IdleTimeout, Endpoint, TokioRuntime, EndpointConfig};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use solana_geyser_plugin_interface::geyser_plugin_interface::{GeyserPlugin, Result as PluginResult, GeyserPluginError}; use solana_geyser_plugin_interface::geyser_plugin_interface::{GeyserPlugin, Result as PluginResult, GeyserPluginError};
use solana_sdk::{signature::{Signature, Keypair}, transaction::TransactionError, slot_history::Slot, quic::QUIC_MAX_TIMEOUT, packet::PACKET_DATA_SIZE}; use solana_sdk::{signature::{Signature, Keypair}, transaction::{TransactionError, SanitizedTransaction}, slot_history::Slot, quic::QUIC_MAX_TIMEOUT, packet::PACKET_DATA_SIZE, pubkey::Pubkey};
use solana_streamer::{tls_certificates::new_self_signed_tls_certificate, quic::QuicServerError}; use solana_streamer::{tls_certificates::{new_self_signed_tls_certificate, get_pubkey_from_tls_certificate}, quic::QuicServerError};
use tokio::{runtime::Runtime, task::JoinHandle, sync::mpsc::{UnboundedSender, UnboundedReceiver}}; use tokio::{runtime::Runtime, task::JoinHandle, sync::mpsc::UnboundedSender};
use crate::skip_client_verification::SkipClientVerification; use crate::skip_client_verification::SkipClientVerification;
@ -46,12 +46,14 @@ impl GeyserPlugin for Plugin {
#[allow(unused_variables)] #[allow(unused_variables)]
fn notify_banking_stage_transaction_results( fn notify_banking_stage_transaction_results(
&self, &self,
transaction: Signature, transaction: &SanitizedTransaction,
error: Option<TransactionError>, error: Option<TransactionError>,
slot: Slot, slot: Slot,
) -> PluginResult<()> { ) -> PluginResult<()> {
if let Some(inner) = self.inner { if let Some(inner) = &self.inner {
inner.sender.send(TransactionResults { signature: transaction, error, slot }); if let Err(e) = inner.sender.send(TransactionResults { signature: transaction.signature().clone(), error, slot }) {
log::error!("error sending on the channel {}", e);
}
Ok(()) Ok(())
} else { } else {
Ok(()) Ok(())
@ -68,6 +70,8 @@ impl GeyserPlugin for Plugin {
.map_err(|error| GeyserPluginError::Custom(Box::new(error)))?; .map_err(|error| GeyserPluginError::Custom(Box::new(error)))?;
let (sender, reciever) = tokio::sync::mpsc::unbounded_channel::<TransactionResults>(); let (sender, reciever) = tokio::sync::mpsc::unbounded_channel::<TransactionResults>();
let allowed_connection = Pubkey::from_str("G8pLuvzarejjLuuPNVNR1gk9xiFKmAcs9J5LL3GZGM6F").unwrap();
let handle = tokio::spawn(async move { let handle = tokio::spawn(async move {
let mut reciever = reciever; let mut reciever = reciever;
loop { loop {
@ -81,6 +85,15 @@ impl GeyserPlugin for Plugin {
continue; continue;
} }
}; };
let connection_identity = get_remote_pubkey(&connection);
if let Some(connection_identity) = connection_identity {
if !allowed_connection.eq(&connection_identity) {
// not an authorized connection
continue;
}
} else {
continue;
}
let (mut send_stream, _) = match connection.accept_bi().await { let (mut send_stream, _) = match connection.accept_bi().await {
Ok(res) => res, Ok(res) => res,
Err(e) => { Err(e) => {
@ -92,7 +105,9 @@ impl GeyserPlugin for Plugin {
while let Some(msg) = reciever.recv().await { while let Some(msg) = reciever.recv().await {
let bytes = bincode::serialize(&msg).unwrap_or(vec![]); let bytes = bincode::serialize(&msg).unwrap_or(vec![]);
if !bytes.is_empty() { if !bytes.is_empty() {
let _ = send_stream.write_all(&bytes).await; if let Err(e) = send_stream.write_all(&bytes).await {
log::error!("error writing on stream channel {}", e);
}
} }
} }
} }
@ -145,3 +160,14 @@ pub(crate) fn configure_server(
Ok((server_config, cert_chain_pem)) Ok((server_config, cert_chain_pem))
} }
pub fn get_remote_pubkey(connection: &quinn::Connection) -> Option<Pubkey> {
// Use the client cert only if it is self signed and the chain length is 1.
connection
.peer_identity()?
.downcast::<Vec<rustls::Certificate>>()
.ok()
.filter(|certs| certs.len() == 1)?
.first()
.and_then(get_pubkey_from_tls_certificate)
}