Last active
April 24, 2019 21:29
-
-
Save movitto/56d308b897d64f85bc3d6eb7d60cb0c1 to your computer and use it in GitHub Desktop.
XRPL NodeStore - Type Extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Work in progress: Ruby Script that parses rippled rocksdb node store and | |
# dumps out data types. | |
# | |
# Written by Dev Null Productions <devnullproductions@gmail.com> | |
# | |
# Many thanks for help received on XRPChat: | |
# https://www.xrpchat.com/topic/31118-question-pertaining-to-hashing-database-lookups/ | |
# | |
# Requires upstream build of rocksdb-ruby to incorporate recent changes. | |
# Also the 'bistro' and 'tty-cursor' rubygems (gem install these). | |
# | |
# Run it with: | |
# ruby xrpl-rocksdb.rb /var/lib/rippled/db/rocksdb/[SPECIFIC_DB] | |
# | |
# Example output: | |
# https://asciinema.org/a/242685 | |
require "rocksdb" | |
require "bistro" | |
require "tty-cursor" | |
STOP = 10000 | |
NODE_TYPES = { | |
1 => :ledger, | |
2 => :tx, | |
3 => :account_node, | |
4 => :tx_node | |
} | |
HASH_PREFIXES = { | |
"54584E00" => :tx_id, | |
"534E4400" => :tx_node, | |
"4D4C4E00" => :leaf_node, | |
"4D494E00" => :inner_node, | |
"4C575200" => :ledger_master, | |
"53545800" => :tx_sign, | |
"56414C00" => :validation, | |
"50525000" => :proposal | |
} | |
tallys = {} | |
format = Bistro.new([ | |
'H16', nil, # unused | |
'c', 'node_type', | |
'H8', 'hash_prefix' | |
]) | |
path = ARGV.first | |
raise "Must specify valid path" unless path && File.exist?(path) | |
rocksdb = RocksDB::DB.new path, | |
{:readonly => true, | |
:max_open_files => 200} | |
i = 0 | |
cursor = TTY::Cursor | |
iterator = rocksdb.new_iterator | |
iterator.seek_to_first | |
puts `clear` | |
while(iterator.valid) | |
obj = format.decode(iterator.value) | |
node_type = NODE_TYPES[obj["node_type"]] | |
hash_prefix = HASH_PREFIXES[obj["hash_prefix"].upcase] | |
type = node_type.to_s + "/" + hash_prefix.to_s | |
tallys[type] ||= 0 | |
tallys[type] += 1 | |
print cursor.move_to(0, 0) | |
tallys.each { |k,v| | |
puts "#{k}: #{v}" | |
} | |
iterator.next | |
i += 1 | |
break if i > STOP | |
end | |
iterator.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment