From 37ec28f13a7060f9a8dda57e87a59a9e6ad1c282 Mon Sep 17 00:00:00 2001 From: 0xb10c Date: Thu, 21 Mar 2024 11:38:23 +0100 Subject: [PATCH] add: hook up validation::block_connected tracepoint --- extractor/build.rs | 2 +- extractor/src/bpf/tracing.bpf.c | 29 +++++ extractor/src/main.rs | 34 +++++- protobuf/proto-types/validation.proto | 20 ++++ protobuf/proto-types/wrapper.proto | 2 + protobuf/python-types/addrman_pb2.py | 20 ++-- protobuf/python-types/mempool_pb2.py | 33 ++++++ protobuf/python-types/net_conn_pb2.py | 36 +++--- protobuf/python-types/net_msg_pb2.py | 144 ++++++++++++------------ protobuf/python-types/primitive_pb2.py | 40 +++---- protobuf/python-types/validation_pb2.py | 27 +++++ protobuf/python-types/wrapper_pb2.py | 16 +-- shared/src/ctypes.rs | 35 ++++++ shared/src/lib.rs | 1 + shared/src/validation.rs | 42 +++++++ tools/logger/src/main.rs | 5 + 16 files changed, 355 insertions(+), 131 deletions(-) create mode 100644 protobuf/proto-types/validation.proto create mode 100644 protobuf/python-types/mempool_pb2.py create mode 100644 protobuf/python-types/validation_pb2.py create mode 100644 shared/src/validation.rs diff --git a/extractor/build.rs b/extractor/build.rs index 6ead0e1..1f42cd6 100644 --- a/extractor/build.rs +++ b/extractor/build.rs @@ -17,7 +17,7 @@ fn main() { { Ok(_) => (), Err(e) => { - println!("{}", e); + println!("Error: {}", e); panic!("could not compile {}", SOURCE); } } diff --git a/extractor/src/bpf/tracing.bpf.c b/extractor/src/bpf/tracing.bpf.c index 5ae4fcb..fd0e2bd 100644 --- a/extractor/src/bpf/tracing.bpf.c +++ b/extractor/src/bpf/tracing.bpf.c @@ -422,4 +422,33 @@ int BPF_USDT(handle_mempool_rejected, void *txid, void *reason) { return bpf_ringbuf_output(&mempool_rejected, &rejected, sizeof(rejected), 0); }; +// VALIDATION + +#define VALIDATION_BLOCK_CONNECTED_PAGES 64 + +RINGBUFFER(validation_block_connected, VALIDATION_BLOCK_CONNECTED_PAGES) + +#define HASH_LENGHT 32 + +struct BlockConnected { + u8 hash[HASH_LENGHT]; + s32 height; + u64 transactions; + s32 inputs; + u64 sigops; + u64 connection_time; +}; + +SEC("usdt") +int BPF_USDT(handle_validation_block_connected, void *hash, s32 height, u64 transactions, s32 inputs, u64 sigops, u64 connection_time) { + struct BlockConnected connected = {}; + bpf_probe_read(&connected.hash, sizeof(connected.hash), hash); + connected.height = height; + connected.transactions = transactions; + connected.inputs = inputs; + connected.sigops = sigops; + connected.connection_time = connection_time; + return bpf_ringbuf_output(&validation_block_connected, &connected, sizeof(connected), 0); +}; + char LICENSE[] SEC("license") = "Dual BSD/GPL"; diff --git a/extractor/src/main.rs b/extractor/src/main.rs index 5457c1b..065bf6e 100644 --- a/extractor/src/main.rs +++ b/extractor/src/main.rs @@ -16,11 +16,11 @@ use prost::Message; use shared::ctypes::{ AddrmanInsertNew, AddrmanInsertTried, ClosedConnection, InboundConnection, MempoolAdded, MempoolRejected, MempoolRemoved, MempoolReplaced, MisbehavingConnection, OutboundConnection, - P2PMessage, P2PMessageSize, + P2PMessage, P2PMessageSize, ValidationBlockConnected, }; use shared::wrapper::wrapper::Wrap; use shared::wrapper::Wrapper; -use shared::{addrman, mempool, net_conn, net_msg}; +use shared::{addrman, mempool, net_conn, net_msg, validation}; use crate::tracing::OpenTracingSkel; @@ -107,6 +107,12 @@ const _TRACEPOINTS_ADDRMAN: [Tracepoint; 2] = [ }, ]; +const TRACEPOINTS_VALIDATION: [Tracepoint; 1] = [Tracepoint { + context: "validation", + name: "block_connected", + function: "handle_validation_block_connected", +}]; + fn bump_memlock_rlimit() { let rlimit = libc::rlimit { rlim_cur: 128 << 20, @@ -142,6 +148,7 @@ fn main() -> Result<(), libbpf_rs::Error> { let active_tracepoints = TRACEPOINTS_NET_MESSAGE .iter() .chain(TRACEPOINTS_NET_CONN.iter()) + .chain(TRACEPOINTS_VALIDATION.iter()) .chain(TRACEPOINTS_MEMPOOL.iter()); let mut links = Vec::new(); for tracepoint in active_tracepoints { @@ -176,7 +183,8 @@ fn main() -> Result<(), libbpf_rs::Error> { .add(obj.map("mempool_added").unwrap(), |data| { handle_mempool_added(data, socket.clone()) })? .add(obj.map("mempool_removed").unwrap(), |data| { handle_mempool_removed(data, socket.clone()) })? .add(obj.map("mempool_rejected").unwrap(), |data| { handle_mempool_rejected(data, socket.clone()) })? - .add(obj.map("mempool_replaced").unwrap(), |data| { handle_mempool_replaced(data, socket.clone()) })?; + .add(obj.map("mempool_replaced").unwrap(), |data| { handle_mempool_replaced(data, socket.clone()) })? + .add(obj.map("validation_block_connected").unwrap(), |data| { handle_validation_block_connected(data, socket.clone()) })?; let ring_buffers = ringbuff_builder.build()?; loop { @@ -415,3 +423,23 @@ fn handle_mempool_rejected(data: &[u8], s: Socket) -> i32 { s.send(&proto.encode_to_vec()).unwrap(); 0 } + +fn handle_validation_block_connected(data: &[u8], s: Socket) -> i32 { + let connected = ValidationBlockConnected::from_bytes(data); + let now = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + let timestamp = now.as_secs(); + let timestamp_subsec_millis = now.subsec_micros(); + let proto = Wrapper { + timestamp: timestamp, + timestamp_subsec_micros: timestamp_subsec_millis, + wrap: Some(Wrap::Validation(validation::ValidationEvent { + event: Some(validation::validation_event::Event::BlockConnected( + connected.into(), + )), + })), + }; + s.send(&proto.encode_to_vec()).unwrap(); + 0 +} diff --git a/protobuf/proto-types/validation.proto b/protobuf/proto-types/validation.proto new file mode 100644 index 0000000..4597fdc --- /dev/null +++ b/protobuf/proto-types/validation.proto @@ -0,0 +1,20 @@ +syntax = "proto2"; + +package validation; + +message ValidationEvent { + oneof event { + BlockConnected block_connected = 1; + } +} + +// A block connected to the chain. +message BlockConnected { + required bytes hash = 1; // Hash of the connected block. + required int32 height = 2; // Height of the connected block. + required int64 transactions = 3; // Number of transactions in the connected block. + required int32 inputs = 4; // Number of inputs in the connected block. + required int64 sigops = 5; // Number of sigops in the connected block. + required int64 connection_time = 6; // Time it took to connect the block in microseconds (µs). +} + diff --git a/protobuf/proto-types/wrapper.proto b/protobuf/proto-types/wrapper.proto index 0e5a1a1..4a9b55d 100644 --- a/protobuf/proto-types/wrapper.proto +++ b/protobuf/proto-types/wrapper.proto @@ -6,6 +6,7 @@ import "net_msg.proto"; import "net_conn.proto"; import "addrman.proto"; import "mempool.proto"; +import "validation.proto"; message Wrapper { required uint64 timestamp = 10; // Timestamp (seconds since UNIX epoch) when the message was received. @@ -15,6 +16,7 @@ message Wrapper { net_conn.ConnectionEvent conn = 2; addrman.AddrmanEvent addrman = 3; mempool.MempoolEvent mempool = 4; + validation.ValidationEvent validation = 5; } } diff --git a/protobuf/python-types/addrman_pb2.py b/protobuf/python-types/addrman_pb2.py index 7aac009..627cd3a 100644 --- a/protobuf/python-types/addrman_pb2.py +++ b/protobuf/python-types/addrman_pb2.py @@ -2,10 +2,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: addrman.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -15,15 +15,15 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\raddrman.proto\x12\x07\x61\x64\x64rman\"a\n\x0c\x41\x64\x64rmanEvent\x12!\n\x03new\x18\x01 \x01(\x0b\x32\x12.addrman.InsertNewH\x00\x12%\n\x05tried\x18\x02 \x01(\x0b\x32\x14.addrman.InsertTriedH\x00\x42\x07\n\x05\x65vent\"\x83\x01\n\tInsertNew\x12\x10\n\x08inserted\x18\x01 \x02(\x08\x12\x0e\n\x06\x62ucket\x18\x02 \x02(\x05\x12\x12\n\nbucket_pos\x18\x03 \x02(\x05\x12\x0c\n\x04\x61\x64\x64r\x18\x04 \x02(\t\x12\x0f\n\x07\x61\x64\x64r_AS\x18\x05 \x02(\r\x12\x0e\n\x06source\x18\x06 \x02(\t\x12\x11\n\tsource_AS\x18\x07 \x02(\r\"s\n\x0bInsertTried\x12\x0e\n\x06\x62ucket\x18\x01 \x02(\x05\x12\x12\n\nbucket_pos\x18\x02 \x02(\x05\x12\x0c\n\x04\x61\x64\x64r\x18\x03 \x02(\t\x12\x0f\n\x07\x61\x64\x64r_AS\x18\x04 \x02(\r\x12\x0e\n\x06source\x18\x05 \x02(\t\x12\x11\n\tsource_AS\x18\x06 \x02(\r') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'addrman_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'addrman_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _ADDRMANEVENT._serialized_start=26 - _ADDRMANEVENT._serialized_end=123 - _INSERTNEW._serialized_start=126 - _INSERTNEW._serialized_end=257 - _INSERTTRIED._serialized_start=259 - _INSERTTRIED._serialized_end=374 + _globals['_ADDRMANEVENT']._serialized_start=26 + _globals['_ADDRMANEVENT']._serialized_end=123 + _globals['_INSERTNEW']._serialized_start=126 + _globals['_INSERTNEW']._serialized_end=257 + _globals['_INSERTTRIED']._serialized_start=259 + _globals['_INSERTTRIED']._serialized_end=374 # @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/mempool_pb2.py b/protobuf/python-types/mempool_pb2.py new file mode 100644 index 0000000..0f272cb --- /dev/null +++ b/protobuf/python-types/mempool_pb2.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: mempool.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rmempool.proto\x12\x07mempool\"\xab\x01\n\x0cMempoolEvent\x12\x1f\n\x05\x61\x64\x64\x65\x64\x18\x01 \x01(\x0b\x32\x0e.mempool.AddedH\x00\x12%\n\x08replaced\x18\x02 \x01(\x0b\x32\x11.mempool.ReplacedH\x00\x12#\n\x07removed\x18\x03 \x01(\x0b\x32\x10.mempool.RemovedH\x00\x12%\n\x08rejected\x18\x04 \x01(\x0b\x32\x11.mempool.RejectedH\x00\x42\x07\n\x05\x65vent\"1\n\x05\x41\x64\x64\x65\x64\x12\x0c\n\x04txid\x18\x01 \x02(\x0c\x12\r\n\x05vsize\x18\x02 \x02(\x05\x12\x0b\n\x03\x66\x65\x65\x18\x03 \x02(\x03\"W\n\x07Removed\x12\x0c\n\x04txid\x18\x01 \x02(\x0c\x12\x0e\n\x06reason\x18\x02 \x02(\t\x12\r\n\x05vsize\x18\x03 \x02(\x05\x12\x0b\n\x03\x66\x65\x65\x18\x04 \x02(\x03\x12\x12\n\nentry_time\x18\x05 \x02(\x04\"(\n\x08Rejected\x12\x0c\n\x04txid\x18\x01 \x02(\x0c\x12\x0e\n\x06reason\x18\x02 \x02(\t\"\xba\x01\n\x08Replaced\x12\x15\n\rreplaced_txid\x18\x01 \x02(\x0c\x12\x16\n\x0ereplaced_vsize\x18\x02 \x02(\x05\x12\x14\n\x0creplaced_fee\x18\x03 \x02(\x03\x12\x1b\n\x13replaced_entry_time\x18\x04 \x02(\x04\x12\x18\n\x10replacement_txid\x18\x05 \x02(\x0c\x12\x19\n\x11replacement_vsize\x18\x06 \x02(\x05\x12\x17\n\x0freplacement_fee\x18\x07 \x02(\x03') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mempool_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_MEMPOOLEVENT']._serialized_start=27 + _globals['_MEMPOOLEVENT']._serialized_end=198 + _globals['_ADDED']._serialized_start=200 + _globals['_ADDED']._serialized_end=249 + _globals['_REMOVED']._serialized_start=251 + _globals['_REMOVED']._serialized_end=338 + _globals['_REJECTED']._serialized_start=340 + _globals['_REJECTED']._serialized_end=380 + _globals['_REPLACED']._serialized_start=383 + _globals['_REPLACED']._serialized_end=569 +# @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/net_conn_pb2.py b/protobuf/python-types/net_conn_pb2.py index 3c6d1dc..bb519f7 100644 --- a/protobuf/python-types/net_conn_pb2.py +++ b/protobuf/python-types/net_conn_pb2.py @@ -2,10 +2,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: net_conn.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -16,23 +16,23 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0enet_conn.proto\x12\x08net_conn\x1a\x0fprimitive.proto\"\xa1\x02\n\x0f\x43onnectionEvent\x12,\n\x06\x63losed\x18\x01 \x01(\x0b\x32\x1a.net_conn.ClosedConnectionH\x00\x12=\n\x0finbound_evicted\x18\x02 \x01(\x0b\x32\".net_conn.EvictedInboundConnectionH\x00\x12.\n\x07inbound\x18\x03 \x01(\x0b\x32\x1b.net_conn.InboundConnectionH\x00\x12\x30\n\x08outbound\x18\x04 \x01(\x0b\x32\x1c.net_conn.OutboundConnectionH\x00\x12\x36\n\x0bmisbehaving\x18\x05 \x01(\x0b\x32\x1f.net_conn.MisbehavingConnectionH\x00\x42\x07\n\x05\x65vent\"d\n\nConnection\x12\x0f\n\x07peer_id\x18\x01 \x02(\x04\x12\x0c\n\x04\x61\x64\x64r\x18\x02 \x02(\t\x12&\n\tconn_type\x18\x03 \x02(\x0e\x32\x13.primitive.ConnType\x12\x0f\n\x07network\x18\x04 \x02(\r\"P\n\x10\x43losedConnection\x12\"\n\x04\x63onn\x18\x01 \x02(\x0b\x32\x14.net_conn.Connection\x12\x18\n\x10time_established\x18\x02 \x02(\x04\"X\n\x18\x45victedInboundConnection\x12\"\n\x04\x63onn\x18\x01 \x02(\x0b\x32\x14.net_conn.Connection\x12\x18\n\x10time_established\x18\x02 \x02(\x04\"U\n\x11InboundConnection\x12\"\n\x04\x63onn\x18\x01 \x02(\x0b\x32\x14.net_conn.Connection\x12\x1c\n\x14\x65xisting_connections\x18\x02 \x02(\x04\"V\n\x12OutboundConnection\x12\"\n\x04\x63onn\x18\x01 \x02(\x0b\x32\x14.net_conn.Connection\x12\x1c\n\x14\x65xisting_connections\x18\x02 \x02(\x04\"\x7f\n\x15MisbehavingConnection\x12\n\n\x02id\x18\x01 \x02(\x04\x12\x14\n\x0cscore_before\x18\x02 \x02(\x05\x12\x16\n\x0escore_increase\x18\x03 \x02(\x05\x12\x10\n\x08xmessage\x18\x04 \x02(\t\x12\x1a\n\x12threshold_exceeded\x18\x05 \x02(\x08') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'net_conn_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'net_conn_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _CONNECTIONEVENT._serialized_start=46 - _CONNECTIONEVENT._serialized_end=335 - _CONNECTION._serialized_start=337 - _CONNECTION._serialized_end=437 - _CLOSEDCONNECTION._serialized_start=439 - _CLOSEDCONNECTION._serialized_end=519 - _EVICTEDINBOUNDCONNECTION._serialized_start=521 - _EVICTEDINBOUNDCONNECTION._serialized_end=609 - _INBOUNDCONNECTION._serialized_start=611 - _INBOUNDCONNECTION._serialized_end=696 - _OUTBOUNDCONNECTION._serialized_start=698 - _OUTBOUNDCONNECTION._serialized_end=784 - _MISBEHAVINGCONNECTION._serialized_start=786 - _MISBEHAVINGCONNECTION._serialized_end=913 + _globals['_CONNECTIONEVENT']._serialized_start=46 + _globals['_CONNECTIONEVENT']._serialized_end=335 + _globals['_CONNECTION']._serialized_start=337 + _globals['_CONNECTION']._serialized_end=437 + _globals['_CLOSEDCONNECTION']._serialized_start=439 + _globals['_CLOSEDCONNECTION']._serialized_end=519 + _globals['_EVICTEDINBOUNDCONNECTION']._serialized_start=521 + _globals['_EVICTEDINBOUNDCONNECTION']._serialized_end=609 + _globals['_INBOUNDCONNECTION']._serialized_start=611 + _globals['_INBOUNDCONNECTION']._serialized_end=696 + _globals['_OUTBOUNDCONNECTION']._serialized_start=698 + _globals['_OUTBOUNDCONNECTION']._serialized_end=784 + _globals['_MISBEHAVINGCONNECTION']._serialized_start=786 + _globals['_MISBEHAVINGCONNECTION']._serialized_end=913 # @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/net_msg_pb2.py b/protobuf/python-types/net_msg_pb2.py index 5cfee12..f4d8d30 100644 --- a/protobuf/python-types/net_msg_pb2.py +++ b/protobuf/python-types/net_msg_pb2.py @@ -2,10 +2,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: net_msg.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -16,77 +16,77 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rnet_msg.proto\x12\x07net_msg\x1a\x0fprimitive.proto\"\x81\x01\n\x08Metadata\x12\x0f\n\x07peer_id\x18\x01 \x02(\x04\x12\x0c\n\x04\x61\x64\x64r\x18\x02 \x02(\t\x12&\n\tconn_type\x18\x03 \x02(\x0e\x32\x13.primitive.ConnType\x12\x0f\n\x07\x63ommand\x18\x04 \x02(\t\x12\x0f\n\x07inbound\x18\x05 \x02(\x08\x12\x0c\n\x04size\x18\x06 \x02(\x04\"\xf3\n\n\x07Message\x12\x1f\n\x04meta\x18\x01 \x02(\x0b\x32\x11.net_msg.Metadata\x12\x1d\n\x04ping\x18\x02 \x01(\x0b\x32\r.net_msg.PingH\x00\x12\x1d\n\x04pong\x18\x03 \x01(\x0b\x32\r.net_msg.PongH\x00\x12\x1b\n\x03inv\x18\x04 \x01(\x0b\x32\x0c.net_msg.InvH\x00\x12#\n\x07getdata\x18\x05 \x01(\x0b\x32\x10.net_msg.GetDataH\x00\x12\x19\n\x02tx\x18\x06 \x01(\x0b\x32\x0b.net_msg.TxH\x00\x12#\n\x07headers\x18\x07 \x01(\x0b\x32\x10.net_msg.HeadersH\x00\x12\x1d\n\x04\x61\x64\x64r\x18\x08 \x01(\x0b\x32\r.net_msg.AddrH\x00\x12!\n\x06\x61\x64\x64rv2\x18\t \x01(\x0b\x32\x0f.net_msg.AddrV2H\x00\x12\'\n\tfeefilter\x18\n \x01(\x0b\x32\x12.net_msg.FeeFilterH\x00\x12)\n\ngetheaders\x18\x0b \x01(\x0b\x32\x13.net_msg.GetHeadersH\x00\x12\'\n\tgetblocks\x18\x0c \x01(\x0b\x32\x12.net_msg.GetBlocksH\x00\x12#\n\x07version\x18\r \x01(\x0b\x32\x10.net_msg.VersionH\x00\x12%\n\x08notfound\x18\x0e \x01(\x0b\x32\x11.net_msg.NotFoundH\x00\x12!\n\x06reject\x18\' \x01(\x0b\x32\x0f.net_msg.RejectH\x00\x12-\n\x0c\x63ompactblock\x18\x10 \x01(\x0b\x32\x15.net_msg.CompactBlockH\x00\x12+\n\x0bsendcompact\x18\x11 \x01(\x0b\x32\x14.net_msg.SendCompactH\x00\x12\x1f\n\x05\x62lock\x18\x12 \x01(\x0b\x32\x0e.net_msg.BlockH\x00\x12+\n\x0bgetblocktxn\x18\x13 \x01(\x0b\x32\x14.net_msg.GetBlockTxnH\x00\x12%\n\x08\x62locktxn\x18\x14 \x01(\x0b\x32\x11.net_msg.BlockTxnH\x00\x12\x1f\n\x05\x61lert\x18\x15 \x01(\x0b\x32\x0e.net_msg.AlertH\x00\x12\'\n\tfilteradd\x18\x16 \x01(\x0b\x32\x12.net_msg.FilterAddH\x00\x12)\n\nfilterload\x18\x17 \x01(\x0b\x32\x13.net_msg.FilterLoadH\x00\x12-\n\x0cgetcfcheckpt\x18\x18 \x01(\x0b\x32\x15.net_msg.GetCFCheckptH\x00\x12\'\n\tcfheaders\x18\x19 \x01(\x0b\x32\x12.net_msg.CFHeadersH\x00\x12#\n\x07\x63\x66ilter\x18\x1a \x01(\x0b\x32\x10.net_msg.CFilterH\x00\x12\'\n\tcfcheckpt\x18\x1b \x01(\x0b\x32\x12.net_msg.CFCheckptH\x00\x12-\n\x0cgetcfheaders\x18\x1c \x01(\x0b\x32\x15.net_msg.GetCFHeadersH\x00\x12)\n\ngetcfilter\x18\x1d \x01(\x0b\x32\x13.net_msg.GetCFilterH\x00\x12+\n\x0bmerkleblock\x18\x1e \x01(\x0b\x32\x14.net_msg.MerkleBlockH\x00\x12#\n\x07unknown\x18\x1f \x01(\x0b\x32\x10.net_msg.UnknownH\x00\x12\x10\n\x06verack\x18 \x01(\x08H\x00\x12\x15\n\x0bsendheaders\x18! \x01(\x08H\x00\x12\x11\n\x07getaddr\x18\" \x01(\x08H\x00\x12\x11\n\x07mempool\x18# \x01(\x08H\x00\x12\x14\n\nwtxidrelay\x18$ \x01(\x08H\x00\x12\x14\n\nsendaddrv2\x18% \x01(\x08H\x00\x12\x15\n\x0b\x66ilterclear\x18& \x01(\x08H\x00\x12\x15\n\x0b\x65mptyaddrv2\x18( \x01(\x08H\x00\x12\x11\n\x07oldping\x18) \x01(\x08H\x00\x42\x05\n\x03msg\"\x15\n\x04Ping\x12\r\n\x05value\x18\x01 \x02(\x06\"\x15\n\x04Pong\x12\r\n\x05value\x18\x01 \x02(\x06\".\n\x03Inv\x12\'\n\x05items\x18\x01 \x03(\x0b\x32\x18.primitive.InventoryItem\"3\n\x08NotFound\x12\'\n\x05items\x18\x01 \x03(\x0b\x32\x18.primitive.InventoryItem\"\x8f\x01\n\x0c\x43ompactBlock\x12&\n\x06header\x18\x01 \x02(\x0b\x32\x16.primitive.BlockHeader\x12\r\n\x05nonce\x18\x02 \x02(\x04\x12\x11\n\tshort_ids\x18\x03 \x03(\x0c\x12\x35\n\x0ctransactions\x18\x04 \x03(\x0b\x32\x1f.primitive.PrefilledTransaction\"(\n\x02Tx\x12\"\n\x02tx\x18\x01 \x02(\x0b\x32\x16.primitive.Transaction\"2\n\x07GetData\x12\'\n\x05items\x18\x01 \x03(\x0b\x32\x18.primitive.InventoryItem\"2\n\x07Headers\x12\'\n\x07headers\x18\x01 \x03(\x0b\x32\x16.primitive.BlockHeader\"5\n\x0bGetBlockTxn\x12\x12\n\nblock_hash\x18\x01 \x02(\x0c\x12\x12\n\ntx_indexes\x18\x02 \x03(\x04\"L\n\x08\x42lockTxn\x12\x12\n\nblock_hash\x18\x01 \x02(\x0c\x12,\n\x0ctransactions\x18\x02 \x03(\x0b\x32\x16.primitive.Transaction\"\x16\n\x05\x41lert\x12\r\n\x05\x61lert\x18\x01 \x02(\x0c\"-\n\x04\x41\x64\x64r\x12%\n\taddresses\x18\x01 \x03(\x0b\x32\x12.primitive.Address\"/\n\x06\x41\x64\x64rV2\x12%\n\taddresses\x18\x01 \x03(\x0b\x32\x12.primitive.Address\"\xf3\x01\n\x06Reject\x12\x18\n\x10rejected_command\x18\x01 \x02(\t\x12,\n\x06reason\x18\x02 \x02(\x0e\x32\x1c.net_msg.Reject.RejectReason\x12\x16\n\x0ereason_details\x18\x03 \x02(\t\x12\x0c\n\x04hash\x18\x04 \x02(\x0c\"{\n\x0cRejectReason\x12\r\n\tMALFORMED\x10\x00\x12\x0b\n\x07INVALID\x10\x01\x12\x0c\n\x08OBSOLETE\x10\x02\x12\r\n\tDUPLICATE\x10\x03\x12\x0f\n\x0bNONSTANDARD\x10\x04\x12\x08\n\x04\x44UST\x10\x05\x12\x07\n\x03\x46\x45\x45\x10\x06\x12\x0e\n\nCHECKPOINT\x10\x07\"4\n\x0bSendCompact\x12\x14\n\x0csend_compact\x18\x01 \x02(\x08\x12\x0f\n\x07version\x18\x02 \x02(\x04\"\x18\n\tFeeFilter\x12\x0b\n\x03\x66\x65\x65\x18\x01 \x02(\x12\"H\n\nGetHeaders\x12\x0f\n\x07version\x18\x01 \x02(\r\x12\x16\n\x0elocator_hashes\x18\x02 \x03(\x0c\x12\x11\n\tstop_hash\x18\x03 \x02(\x0c\"G\n\tGetBlocks\x12\x0f\n\x07version\x18\x01 \x02(\r\x12\x16\n\x0elocator_hashes\x18\x02 \x03(\x0c\x12\x11\n\tstop_hash\x18\x03 \x02(\x0c\"\xd1\x01\n\x07Version\x12\x0f\n\x07version\x18\x01 \x02(\r\x12\x10\n\x08services\x18\x02 \x02(\x04\x12\x11\n\ttimestamp\x18\x03 \x02(\x12\x12$\n\x08receiver\x18\x04 \x02(\x0b\x32\x12.primitive.Address\x12\"\n\x06sender\x18\x05 \x02(\x0b\x32\x12.primitive.Address\x12\r\n\x05nonce\x18\x06 \x02(\x04\x12\x12\n\nuser_agent\x18\x07 \x02(\t\x12\x14\n\x0cstart_height\x18\x08 \x02(\x11\x12\r\n\x05relay\x18\t \x02(\x08\"]\n\x05\x42lock\x12&\n\x06header\x18\x01 \x02(\x0b\x32\x16.primitive.BlockHeader\x12,\n\x0ctransactions\x18\x02 \x03(\x0b\x32\x16.primitive.Transaction\"\x1b\n\tFilterAdd\x12\x0e\n\x06\x66ilter\x18\x01 \x02(\x0c\"\x9f\x01\n\nFilterLoad\x12\x0e\n\x06\x66ilter\x18\x01 \x02(\x0c\x12\x12\n\nhash_funcs\x18\x02 \x02(\r\x12\r\n\x05tweak\x18\x03 \x02(\r\x12-\n\x05\x66lags\x18\x04 \x02(\x0e\x32\x1e.net_msg.FilterLoad.BloomFlags\"/\n\nBloomFlags\x12\x08\n\x04None\x10\x00\x12\x07\n\x03\x41ll\x10\x01\x12\x0e\n\nPubkeyOnly\x10\x02\"6\n\x0cGetCFCheckpt\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x11\n\tstop_hash\x18\x02 \x02(\x0c\"K\n\tCFCheckpt\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x11\n\tstop_hash\x18\x02 \x02(\x0c\x12\x16\n\x0e\x66ilter_headers\x18\x03 \x03(\x0c\"L\n\x0cGetCFHeaders\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x14\n\x0cstart_height\x18\x02 \x02(\r\x12\x11\n\tstop_hash\x18\x03 \x02(\x0c\"j\n\tCFHeaders\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x11\n\tstop_hash\x18\x02 \x02(\x0c\x12\x1e\n\x16previous_filter_header\x18\x03 \x02(\x0c\x12\x15\n\rfilter_hashes\x18\x04 \x03(\x0c\"J\n\nGetCFilter\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x14\n\x0cstart_height\x18\x02 \x02(\r\x12\x11\n\tstop_hash\x18\x03 \x02(\x0c\"B\n\x07\x43\x46ilter\x12\x13\n\x0b\x66ilter_type\x18\x01 \x02(\r\x12\x12\n\nblock_hash\x18\x02 \x02(\x0c\x12\x0e\n\x06\x66ilter\x18\x03 \x02(\x0c\"m\n\x0bMerkleBlock\x12&\n\x06header\x18\x01 \x02(\x0b\x32\x16.primitive.BlockHeader\x12\x18\n\x10num_transactions\x18\x02 \x02(\r\x12\x0c\n\x04\x62its\x18\x03 \x03(\x08\x12\x0e\n\x06hashes\x18\x04 \x03(\x0c\"+\n\x07Unknown\x12\x0f\n\x07\x63ommand\x18\x01 \x02(\t\x12\x0f\n\x07payload\x18\x02 \x02(\x0c') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'net_msg_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'net_msg_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _METADATA._serialized_start=44 - _METADATA._serialized_end=173 - _MESSAGE._serialized_start=176 - _MESSAGE._serialized_end=1571 - _PING._serialized_start=1573 - _PING._serialized_end=1594 - _PONG._serialized_start=1596 - _PONG._serialized_end=1617 - _INV._serialized_start=1619 - _INV._serialized_end=1665 - _NOTFOUND._serialized_start=1667 - _NOTFOUND._serialized_end=1718 - _COMPACTBLOCK._serialized_start=1721 - _COMPACTBLOCK._serialized_end=1864 - _TX._serialized_start=1866 - _TX._serialized_end=1906 - _GETDATA._serialized_start=1908 - _GETDATA._serialized_end=1958 - _HEADERS._serialized_start=1960 - _HEADERS._serialized_end=2010 - _GETBLOCKTXN._serialized_start=2012 - _GETBLOCKTXN._serialized_end=2065 - _BLOCKTXN._serialized_start=2067 - _BLOCKTXN._serialized_end=2143 - _ALERT._serialized_start=2145 - _ALERT._serialized_end=2167 - _ADDR._serialized_start=2169 - _ADDR._serialized_end=2214 - _ADDRV2._serialized_start=2216 - _ADDRV2._serialized_end=2263 - _REJECT._serialized_start=2266 - _REJECT._serialized_end=2509 - _REJECT_REJECTREASON._serialized_start=2386 - _REJECT_REJECTREASON._serialized_end=2509 - _SENDCOMPACT._serialized_start=2511 - _SENDCOMPACT._serialized_end=2563 - _FEEFILTER._serialized_start=2565 - _FEEFILTER._serialized_end=2589 - _GETHEADERS._serialized_start=2591 - _GETHEADERS._serialized_end=2663 - _GETBLOCKS._serialized_start=2665 - _GETBLOCKS._serialized_end=2736 - _VERSION._serialized_start=2739 - _VERSION._serialized_end=2948 - _BLOCK._serialized_start=2950 - _BLOCK._serialized_end=3043 - _FILTERADD._serialized_start=3045 - _FILTERADD._serialized_end=3072 - _FILTERLOAD._serialized_start=3075 - _FILTERLOAD._serialized_end=3234 - _FILTERLOAD_BLOOMFLAGS._serialized_start=3187 - _FILTERLOAD_BLOOMFLAGS._serialized_end=3234 - _GETCFCHECKPT._serialized_start=3236 - _GETCFCHECKPT._serialized_end=3290 - _CFCHECKPT._serialized_start=3292 - _CFCHECKPT._serialized_end=3367 - _GETCFHEADERS._serialized_start=3369 - _GETCFHEADERS._serialized_end=3445 - _CFHEADERS._serialized_start=3447 - _CFHEADERS._serialized_end=3553 - _GETCFILTER._serialized_start=3555 - _GETCFILTER._serialized_end=3629 - _CFILTER._serialized_start=3631 - _CFILTER._serialized_end=3697 - _MERKLEBLOCK._serialized_start=3699 - _MERKLEBLOCK._serialized_end=3808 - _UNKNOWN._serialized_start=3810 - _UNKNOWN._serialized_end=3853 + _globals['_METADATA']._serialized_start=44 + _globals['_METADATA']._serialized_end=173 + _globals['_MESSAGE']._serialized_start=176 + _globals['_MESSAGE']._serialized_end=1571 + _globals['_PING']._serialized_start=1573 + _globals['_PING']._serialized_end=1594 + _globals['_PONG']._serialized_start=1596 + _globals['_PONG']._serialized_end=1617 + _globals['_INV']._serialized_start=1619 + _globals['_INV']._serialized_end=1665 + _globals['_NOTFOUND']._serialized_start=1667 + _globals['_NOTFOUND']._serialized_end=1718 + _globals['_COMPACTBLOCK']._serialized_start=1721 + _globals['_COMPACTBLOCK']._serialized_end=1864 + _globals['_TX']._serialized_start=1866 + _globals['_TX']._serialized_end=1906 + _globals['_GETDATA']._serialized_start=1908 + _globals['_GETDATA']._serialized_end=1958 + _globals['_HEADERS']._serialized_start=1960 + _globals['_HEADERS']._serialized_end=2010 + _globals['_GETBLOCKTXN']._serialized_start=2012 + _globals['_GETBLOCKTXN']._serialized_end=2065 + _globals['_BLOCKTXN']._serialized_start=2067 + _globals['_BLOCKTXN']._serialized_end=2143 + _globals['_ALERT']._serialized_start=2145 + _globals['_ALERT']._serialized_end=2167 + _globals['_ADDR']._serialized_start=2169 + _globals['_ADDR']._serialized_end=2214 + _globals['_ADDRV2']._serialized_start=2216 + _globals['_ADDRV2']._serialized_end=2263 + _globals['_REJECT']._serialized_start=2266 + _globals['_REJECT']._serialized_end=2509 + _globals['_REJECT_REJECTREASON']._serialized_start=2386 + _globals['_REJECT_REJECTREASON']._serialized_end=2509 + _globals['_SENDCOMPACT']._serialized_start=2511 + _globals['_SENDCOMPACT']._serialized_end=2563 + _globals['_FEEFILTER']._serialized_start=2565 + _globals['_FEEFILTER']._serialized_end=2589 + _globals['_GETHEADERS']._serialized_start=2591 + _globals['_GETHEADERS']._serialized_end=2663 + _globals['_GETBLOCKS']._serialized_start=2665 + _globals['_GETBLOCKS']._serialized_end=2736 + _globals['_VERSION']._serialized_start=2739 + _globals['_VERSION']._serialized_end=2948 + _globals['_BLOCK']._serialized_start=2950 + _globals['_BLOCK']._serialized_end=3043 + _globals['_FILTERADD']._serialized_start=3045 + _globals['_FILTERADD']._serialized_end=3072 + _globals['_FILTERLOAD']._serialized_start=3075 + _globals['_FILTERLOAD']._serialized_end=3234 + _globals['_FILTERLOAD_BLOOMFLAGS']._serialized_start=3187 + _globals['_FILTERLOAD_BLOOMFLAGS']._serialized_end=3234 + _globals['_GETCFCHECKPT']._serialized_start=3236 + _globals['_GETCFCHECKPT']._serialized_end=3290 + _globals['_CFCHECKPT']._serialized_start=3292 + _globals['_CFCHECKPT']._serialized_end=3367 + _globals['_GETCFHEADERS']._serialized_start=3369 + _globals['_GETCFHEADERS']._serialized_end=3445 + _globals['_CFHEADERS']._serialized_start=3447 + _globals['_CFHEADERS']._serialized_end=3553 + _globals['_GETCFILTER']._serialized_start=3555 + _globals['_GETCFILTER']._serialized_end=3629 + _globals['_CFILTER']._serialized_start=3631 + _globals['_CFILTER']._serialized_end=3697 + _globals['_MERKLEBLOCK']._serialized_start=3699 + _globals['_MERKLEBLOCK']._serialized_end=3808 + _globals['_UNKNOWN']._serialized_start=3810 + _globals['_UNKNOWN']._serialized_end=3853 # @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/primitive_pb2.py b/protobuf/python-types/primitive_pb2.py index 7698159..a17e473 100644 --- a/protobuf/python-types/primitive_pb2.py +++ b/protobuf/python-types/primitive_pb2.py @@ -2,10 +2,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: primitive.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -15,25 +15,25 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fprimitive.proto\x12\tprimitive\"7\n\x0bTransaction\x12\x0c\n\x04txid\x18\x01 \x02(\x0c\x12\r\n\x05wtxid\x18\x02 \x02(\x0c\x12\x0b\n\x03raw\x18\x03 \x01(\x0c\"\x84\x01\n\x0b\x42lockHeader\x12\x0f\n\x07version\x18\x01 \x02(\x11\x12\x16\n\x0eprev_blockhash\x18\x02 \x02(\x0c\x12\x13\n\x0bmerkle_root\x18\x03 \x02(\x0c\x12\x0c\n\x04time\x18\x04 \x02(\r\x12\x0c\n\x04\x62its\x18\x05 \x02(\r\x12\r\n\x05nonce\x18\x06 \x02(\r\x12\x0c\n\x04hash\x18\x07 \x02(\x0c\"\xd7\x01\n\x07\x41\x64\x64ress\x12\x11\n\ttimestamp\x18\x01 \x02(\r\x12\x0e\n\x04ipv4\x18\x02 \x01(\tH\x00\x12\x0e\n\x04ipv6\x18\x03 \x01(\tH\x00\x12\x0f\n\x05torv2\x18\x04 \x01(\tH\x00\x12\x0f\n\x05torv3\x18\x05 \x01(\tH\x00\x12\r\n\x03i2p\x18\x06 \x01(\tH\x00\x12\x0f\n\x05\x63jdns\x18\x07 \x01(\tH\x00\x12,\n\x07unknown\x18\x08 \x01(\x0b\x32\x19.primitive.UnknownAddressH\x00\x12\x10\n\x08services\x18\t \x02(\x04\x12\x0c\n\x04port\x18\n \x02(\rB\t\n\x07\x61\x64\x64ress\"-\n\x0eUnknownAddress\x12\n\n\x02id\x18\x01 \x02(\r\x12\x0f\n\x07\x61\x64\x64ress\x18\x02 \x02(\x0c\"\xdb\x01\n\rInventoryItem\x12\x15\n\x0btransaction\x18\x01 \x01(\x0cH\x00\x12\x0f\n\x05\x62lock\x18\x02 \x01(\x0cH\x00\x12\r\n\x03wtx\x18\x03 \x01(\x0cH\x00\x12\x1d\n\x13witness_transaction\x18\x04 \x01(\x0cH\x00\x12\x17\n\rwitness_block\x18\x05 \x01(\x0cH\x00\x12\x17\n\rcompact_block\x18\x06 \x01(\x0cH\x00\x12)\n\x07unknown\x18\x07 \x01(\x0b\x32\x16.primitive.UnknownItemH\x00\x12\x0f\n\x05\x65rror\x18\x0f \x01(\x08H\x00\x42\x06\n\x04item\"-\n\x0bUnknownItem\x12\x10\n\x08inv_type\x18\x01 \x02(\r\x12\x0c\n\x04hash\x18\x02 \x02(\x0c\"N\n\x14PrefilledTransaction\x12\x12\n\ndiff_index\x18\x01 \x02(\r\x12\"\n\x02tx\x18\x02 \x02(\x0b\x32\x16.primitive.Transaction*[\n\x08\x43onnType\x12\x0b\n\x07Unknown\x10\x00\x12\x0b\n\x07Inbound\x10\x01\x12\x15\n\x11OutboundFullRelay\x10\x02\x12\x12\n\x0e\x42lockRelayOnly\x10\x03\x12\n\n\x06\x46\x65\x65ler\x10\x04') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'primitive_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'primitive_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _CONNTYPE._serialized_start=836 - _CONNTYPE._serialized_end=927 - _TRANSACTION._serialized_start=30 - _TRANSACTION._serialized_end=85 - _BLOCKHEADER._serialized_start=88 - _BLOCKHEADER._serialized_end=220 - _ADDRESS._serialized_start=223 - _ADDRESS._serialized_end=438 - _UNKNOWNADDRESS._serialized_start=440 - _UNKNOWNADDRESS._serialized_end=485 - _INVENTORYITEM._serialized_start=488 - _INVENTORYITEM._serialized_end=707 - _UNKNOWNITEM._serialized_start=709 - _UNKNOWNITEM._serialized_end=754 - _PREFILLEDTRANSACTION._serialized_start=756 - _PREFILLEDTRANSACTION._serialized_end=834 + _globals['_CONNTYPE']._serialized_start=836 + _globals['_CONNTYPE']._serialized_end=927 + _globals['_TRANSACTION']._serialized_start=30 + _globals['_TRANSACTION']._serialized_end=85 + _globals['_BLOCKHEADER']._serialized_start=88 + _globals['_BLOCKHEADER']._serialized_end=220 + _globals['_ADDRESS']._serialized_start=223 + _globals['_ADDRESS']._serialized_end=438 + _globals['_UNKNOWNADDRESS']._serialized_start=440 + _globals['_UNKNOWNADDRESS']._serialized_end=485 + _globals['_INVENTORYITEM']._serialized_start=488 + _globals['_INVENTORYITEM']._serialized_end=707 + _globals['_UNKNOWNITEM']._serialized_start=709 + _globals['_UNKNOWNITEM']._serialized_end=754 + _globals['_PREFILLEDTRANSACTION']._serialized_start=756 + _globals['_PREFILLEDTRANSACTION']._serialized_end=834 # @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/validation_pb2.py b/protobuf/python-types/validation_pb2.py new file mode 100644 index 0000000..e0e8afc --- /dev/null +++ b/protobuf/python-types/validation_pb2.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: validation.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10validation.proto\x12\nvalidation\"Q\n\x0fValidationEvent\x12\x35\n\x0f\x62lock_connected\x18\x01 \x01(\x0b\x32\x1a.validation.BlockConnectedH\x00\x42\x07\n\x05\x65vent\"o\n\x0e\x42lockConnected\x12\x0e\n\x06height\x18\x01 \x02(\x05\x12\x14\n\x0ctransactions\x18\x02 \x02(\x03\x12\x0e\n\x06inputs\x18\x03 \x02(\x05\x12\x0e\n\x06sigops\x18\x04 \x02(\x03\x12\x17\n\x0f\x63onnection_time\x18\x05 \x02(\x03') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'validation_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_VALIDATIONEVENT']._serialized_start=32 + _globals['_VALIDATIONEVENT']._serialized_end=113 + _globals['_BLOCKCONNECTED']._serialized_start=115 + _globals['_BLOCKCONNECTED']._serialized_end=226 +# @@protoc_insertion_point(module_scope) diff --git a/protobuf/python-types/wrapper_pb2.py b/protobuf/python-types/wrapper_pb2.py index 02b5bc5..c3c91a4 100644 --- a/protobuf/python-types/wrapper_pb2.py +++ b/protobuf/python-types/wrapper_pb2.py @@ -2,10 +2,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: wrapper.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -14,15 +14,17 @@ import net_msg_pb2 as net__msg__pb2 import net_conn_pb2 as net__conn__pb2 import addrman_pb2 as addrman__pb2 +import mempool_pb2 as mempool__pb2 +import validation_pb2 as validation__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rwrapper.proto\x12\x07wrapper\x1a\rnet_msg.proto\x1a\x0enet_conn.proto\x1a\raddrman.proto\"\xbb\x01\n\x07Wrapper\x12\x11\n\ttimestamp\x18\n \x02(\x04\x12\x1f\n\x17timestamp_subsec_micros\x18\x0b \x02(\r\x12\x1f\n\x03msg\x18\x01 \x01(\x0b\x32\x10.net_msg.MessageH\x00\x12)\n\x04\x63onn\x18\x02 \x01(\x0b\x32\x19.net_conn.ConnectionEventH\x00\x12(\n\x07\x61\x64\x64rman\x18\x03 \x01(\x0b\x32\x15.addrman.AddrmanEventH\x00\x42\x06\n\x04wrap') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rwrapper.proto\x12\x07wrapper\x1a\rnet_msg.proto\x1a\x0enet_conn.proto\x1a\raddrman.proto\x1a\rmempool.proto\x1a\x10validation.proto\"\x98\x02\n\x07Wrapper\x12\x11\n\ttimestamp\x18\n \x02(\x04\x12\x1f\n\x17timestamp_subsec_micros\x18\x0b \x02(\r\x12\x1f\n\x03msg\x18\x01 \x01(\x0b\x32\x10.net_msg.MessageH\x00\x12)\n\x04\x63onn\x18\x02 \x01(\x0b\x32\x19.net_conn.ConnectionEventH\x00\x12(\n\x07\x61\x64\x64rman\x18\x03 \x01(\x0b\x32\x15.addrman.AddrmanEventH\x00\x12(\n\x07mempool\x18\x04 \x01(\x0b\x32\x15.mempool.MempoolEventH\x00\x12\x31\n\nvalidation\x18\x05 \x01(\x0b\x32\x1b.validation.ValidationEventH\x00\x42\x06\n\x04wrap') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wrapper_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wrapper_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _WRAPPER._serialized_start=73 - _WRAPPER._serialized_end=260 + _globals['_WRAPPER']._serialized_start=106 + _globals['_WRAPPER']._serialized_end=386 # @@protoc_insertion_point(module_scope) diff --git a/shared/src/ctypes.rs b/shared/src/ctypes.rs index 7f70c9f..4d9704f 100644 --- a/shared/src/ctypes.rs +++ b/shared/src/ctypes.rs @@ -23,6 +23,8 @@ const TXID_LENGTH: usize = 32; const REMOVAL_REASON_LENGTH: usize = 9; const REJECTION_REASON_LENGTH: usize = 118; +const HASH_LENGTH: usize = 32; + #[repr(usize)] pub enum P2PMessageSize { Small = MAX_SMALL_MSG_LENGTH, @@ -396,6 +398,39 @@ impl MempoolRejected { } } +#[repr(C)] +pub struct ValidationBlockConnected { + /// Hash of the connected block + pub hash: [u8; HASH_LENGTH], + /// Height of the connected block + pub height: i32, + /// Number of transactions in the connected block + pub transactions: u64, + /// Number of inputs in the connected block + pub inputs: i32, + /// Number of sigops in the connected block + pub sigops: u64, + /// Time it took to connect the block in microseconds (µs) + pub connection_time: u64, +} + +impl fmt::Display for ValidationBlockConnected { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "ValidationBlockConnected(hash={}, height={}, transactions={}, inputs={}, sigops={}, time={}µs)", + bitcoin::BlockHash::from_slice(&self.hash).unwrap(), + self.height, self.transactions, self.inputs, self.sigops, self.connection_time, + ) + } +} + +impl ValidationBlockConnected { + pub fn from_bytes(x: &[u8]) -> Self { + unsafe { ptr::read_unaligned(x.as_ptr() as *const Self) } + } +} + fn decode_network_message( meta: &P2PMessageMetadata, payload: &[u8], diff --git a/shared/src/lib.rs b/shared/src/lib.rs index b95d35a..508f68a 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -8,6 +8,7 @@ pub mod mempool; pub mod net_conn; pub mod net_msg; pub mod primitive; +pub mod validation; pub mod wrapper; /// Utillity functions shared among peer-observer tools diff --git a/shared/src/validation.rs b/shared/src/validation.rs new file mode 100644 index 0000000..a729c43 --- /dev/null +++ b/shared/src/validation.rs @@ -0,0 +1,42 @@ +use crate::bitcoin::hashes::Hash; +use crate::ctypes; +use std::fmt; + +// structs are generated via the validation.proto file +include!(concat!(env!("OUT_DIR"), "/validation.rs")); + +impl From for BlockConnected { + fn from(connected: ctypes::ValidationBlockConnected) -> Self { + BlockConnected { + hash: connected.hash.to_vec(), + height: connected.height, + transactions: connected.transactions as i64, + inputs: connected.inputs, + sigops: connected.sigops as i64, + connection_time: connected.connection_time as i64, + } + } +} + +impl fmt::Display for BlockConnected { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "BlockConnected(hash={}, height={}, transactions={}, inputs={}, sigops={}, time={}µs)", + bitcoin::BlockHash::from_slice(&self.hash).unwrap(), + self.height, + self.transactions, + self.inputs, + self.sigops, + self.connection_time, + ) + } +} + +impl fmt::Display for validation_event::Event { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + validation_event::Event::BlockConnected(connected) => write!(f, "{}", connected), + } + } +} diff --git a/tools/logger/src/main.rs b/tools/logger/src/main.rs index 06b5786..5c10de7 100644 --- a/tools/logger/src/main.rs +++ b/tools/logger/src/main.rs @@ -48,6 +48,11 @@ fn main() { "$Mempool {}", m.event.unwrap() }; } + Wrap::Validation(v) => { + println! { + "+Validation {}", v.event.unwrap() + }; + } } } }