Skip to content

Instantly share code, notes, and snippets.

View 0xNineteen's full-sized avatar
🦭
chillin

x19 0xNineteen

🦭
chillin
View GitHub Profile
@0xNineteen
0xNineteen / run.py
Created March 11, 2024 20:27
rust client abi changes script
import requests
import re
import json
def get_frozen_abi(tag):
url_base = f"https://raw.githubusercontent.com/solana-labs/solana/{tag}/"
path = "gossip/src/cluster_info.rs"
# print(url_base + path)
r = requests.get(url_base + path)
URL=$(curl https://ziglang.org/download/index.json | jq '.master."aarch64-macos".tarball')
URL=${URL//\"/}
curl $URL -O
# unwrap .tar to directory
FN=$(basename "$URL")
tar xf $FN
rm $FN
# required: ~/.profile PATH already points to this 'zig' path
@0xNineteen
0xNineteen / sockets.zig
Last active January 12, 2024 19:58
syscall or die
const std = @import("std");
const net = std.net;
const os = std.os;
const info = std.log.info;
const expect = std.testing.expect;
const system = os.system;
const linux = os.linux;
const c = std.c;
const MAX_CONNECTIONS = 32;
@0xNineteen
0xNineteen / parse_vote_txs.rs
Last active May 18, 2023 19:29
parse solana vote txs from a block
use std::{str::FromStr, collections::HashMap};
use serde::{Serialize, Deserialize};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{vote::{instruction::VoteInstruction, self}, signature::Signature, transaction::{VersionedTransaction, SanitizedTransaction}, pubkey::Pubkey};
use solana_transaction_status::{EncodedTransaction, UiTransactionEncoding, UiConfirmedBlock, EncodedConfirmedBlock, TransactionBinaryEncoding};
use solana_account_decoder::{self, UiAccountData, parse_stake::{parse_stake, StakeAccountType}, parse_vote::parse_vote};
#[macro_export]
macro_rules! send_rpc_call {
use std::{net::{SocketAddr, TcpStream, IpAddr, Ipv4Addr}, time::{Duration, Instant}, sync::{atomic::{AtomicBool, Ordering}, Arc, RwLock}, thread::sleep, collections::{HashSet, HashMap}, path::Path, io::Read, str::FromStr};
use crossbeam_channel::unbounded;
use solana_core::{validator::Validator, tpu::DEFAULT_TPU_COALESCE};
use solana_gossip::{gossip_service::{GossipService}, cluster_info::{ClusterInfo, Protocol, Node}, socketaddr_any, socketaddr, duplicate_shred::{DuplicateShred, into_shreds}};
use solana_gossip::{legacy_contact_info::LegacyContactInfo as ContactInfo};
use solana_perf::{recycler::Recycler, packet::{PacketBatch, Packet, PacketBatchRecycler}};
use solana_streamer::{socket::SocketAddrSpace, streamer::{self, StreamerReceiveStats}};
use tracing_subscriber;
use solana_sdk::{signer::{Signer}, timing::timestamp, signature::read_keypair_file};
use paste::paste;
macro_rules! dispatch_trait_fn {
($value_name:ident : $value:ty => $key_name:ident : $key:ty) => {
paste!(
fn [<get_ $value_name>](&self, $key_name:$key) -> Result<$value>;
fn [<put_ $value_name>](&self, $value_name:$value) -> Result<$key>;
);
}
}
use std::error::Error;
use std::time::Duration;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::time::sleep;
use tokio::runtime::Builder;
use tracing_subscriber;
use tracing::{info, Instrument};
pub async fn generator(sender: Sender<u64>) {
@0xNineteen
0xNineteen / eth2-pubsub.rs
Last active March 8, 2023 18:04
discv5 + libp2p gossipsub -- built with lighthouse eth2 client
use std::collections::HashSet;
use std::error::Error;
use std::hash::Hash;
use std::sync::Arc;
use discv5::Enr;
use futures::lock::Mutex;
use libp2p::gossipsub::subscription_filter::AllowAllSubscriptionFilter;
use lighthouse_network::{EnrExt, GossipTopic, Eth2Enr, strip_peer_id};
use lighthouse_network::config::{Config, gossipsub_config};
@0xNineteen
0xNineteen / libp2p_gossipsub.rs
Created February 23, 2023 15:25
simple gossipsub using libp2p in rust
use futures::{prelude::*, select};
use libp2p::gossipsub::{Gossipsub, GossipsubConfig, Sha256Topic, GossipsubEvent};
use libp2p::{
gossipsub, identity, mdns, swarm::NetworkBehaviour, swarm::SwarmEvent, PeerId, Swarm,
};
use async_std::io::{stdin, BufReader};
use std::error::Error;
#[async_std::main]
async fn main() -> Result<(), Box<dyn Error>> {
@0xNineteen
0xNineteen / block_stream.rs
Last active February 3, 2023 18:49
stream eth2 blocks (and txs) directly from the consensus client [using checkpoint sync it takes a few minutes to receive the newest blocks]
// steps:
// 1) setup and run lighthouse to run with checkpoint sync
// 2) run akula execution client
// 3) wait till lighthouse is 'synced' (takes a few minutes)
// 4) run this script to query the newest block + its txs
use std::{result::Result, error::Error};
use hyper::{Client, body::HttpBody, Request};
use hyper::http::header::ACCEPT;
use rlp::{Rlp, Decodable};