Utilitaire pour indexer des informations de la blockchain et dessiner des Plots. Focalisé sur la toile de confiance. http://datajune.coinduf.eu/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.3 KiB

module LightGraphExporter
export lightgraph_export
using ..BlockchainBrowser, ..Config
using LightGraphs, JSON, ProgressMeter, Serialization
# NOTE: rebuilding whole history but only writing last files
"resample events every SAMPLING_PERIOD seconds and write to lightgraph files"
function lightgraph_export()
storage = BlockchainBrowser.load_storage()
npseudo = size(storage.pseudos, 1) # number of pseudos
last_lg = length(readdir(LG_PATH)) # number of last lg export
start = storage.firstblock_timestamp
step = SAMPLING_PERIOD
stop = storage.lastblock_timestamp
# steps = start:step:stop
# nstep = length(steps)
nstep = length(storage.sampled_blocks)
g = SimpleDiGraph(npseudo) # empty graph with one node per pseudo
active_nodes = falses(npseudo,nstep) # boolean of node activity
activation = falses(npseudo) # track node activity for one step only
activation_block = zeros(Int, npseudo) # track last block number of activation
i = 1 # step number
crtinptr = 1 # pointer on cert_in
crtexptr = 1 # pointer on cert_out
joinptr = 1 # pointer on joiners
leavptr = 1 # pointer on leavers
@showprogress "Converting files..." for (i, cur_block) in enumerate(storage.sampled_blocks)
# take into account joiners and leavers (due to distance rule, revocation, membership...)
while leavptr < length(storage.leavers) && storage.leavers[leavptr][1] <= cur_block.number
n, id = storage.leavers[leavptr]
activation[id] = false # tell that id leaved
activation_block[id] = n # track block number of activation
leavptr += 1
end
while storage.joiners[joinptr][1] <= cur_block.number
n, id = storage.joiners[joinptr]
if n >= activation_block[id]
activation[id] = true # tell that id joined
end
joinptr += 1
end
active_nodes[:,i] .= activation
# take certifications into account
while storage.cert_in[crtinptr][1] <= cur_block.medianTime
t, (source, target) = storage.cert_in[crtinptr]
add_edge!(g, source, target) # add new certifications
crtinptr += 1
end
while storage.cert_out[crtexptr][1] <= cur_block.medianTime
t, (source, target) = storage.cert_out[crtexptr]
rem_edge!(g, source, target) # remove expired certification
crtexptr += 1
end
if i > last_lg # only write files which do not already exist
was_member = cur_block.pseudoCount
ne_before = ne(g)
rem_vertices!(g, collect(was_member+1:npseudo), keep_order=true) # mini hack to change g size in lg file
ne_after = ne(g)
if ne_before != ne_after; error("unexpected edge removal $ne_before$ne_after "); end # small check for debugging
savegraph(joinpath(LG_PATH, lpad(i,4,'0')*".lg"), g) # save graph
add_vertices!(g, npseudo-was_member)
end
end
serialize(joinpath(CACHE_PATH, "info.jls"),
Dict("start"=>start,"step"=>step,"stop"=>stop,"npseudo"=>npseudo)) # save some info
serialize(joinpath(CACHE_PATH, "active.jls"), active_nodes)
write(joinpath(GLOBAL_PATH, "pseudos.txt"), join(storage.pseudos, "\n"))
return nothing
end
end