Skip to content
Snippets Groups Projects
Commit 9ab76c8b authored by Augustin Jaujay's avatar Augustin Jaujay
Browse files

Parallélisation du remplissage des blocs

parent e49ffda6
Branches
Tags
No related merge requests found
Pipeline #4313 failed
......@@ -102,9 +102,10 @@ defmodule DB do
:dets.close(db)
if dbName == 'block' do
fill_with_block()
spawn(fn -> fill_with_block() end)
end
{:ok, {dbName, dbNumber}}
end
......@@ -233,17 +234,25 @@ defmodule DB do
defp fill_with_block() do
# Getting current block from the remote node of the blockchain
currentBlock = case :httpc.request(:get, {@base_url ++ '/blockchain/current', []}, [], []) do
currentRemoteBlock = (case :httpc.request(:get, {@base_url ++ '/blockchain/current', []}, [], []) do
{:ok, {{_, 200, 'OK'}, _headers, body}} -> Poison.decode!(body)
_ -> Logger.info('Filling DB : Failing when getting current block')
end)["number"]
# currentRemoteBlock = 50_000
dbSize = get_size('block')
currentLocalBlock = if dbSize > currentRemoteBlock do
currentRemoteBlock
else
dbSize
end
get_size('block')..50 # currentBlock["number"] # TODO : Fetch all the blocks
currentLocalBlock..currentRemoteBlock # TODO : Fetch all the blocks
|> Enum.chunk_every(5000)
|> Enum.map(fn chk ->
# Putting the new blocks in the local database
case :httpc.request(:get, {@base_url ++ '/blockchain/blocks/' ++ to_charlist(List.last(chk) - List.first(chk)) ++ '/' ++ to_charlist(List.first(chk)), []}, [], []) do
case :httpc.request(:get, {@base_url ++ '/blockchain/blocks/' ++ to_charlist(length(chk)) ++ '/' ++ to_charlist(List.first(chk)), []}, [], []) do
{:ok, {{_, 200, 'OK'}, _headers, '[]'}} ->
Logger.info('Filling DB : No blocks to get from remote g1-test node')
......@@ -259,6 +268,8 @@ defmodule DB do
_ ->
Logger.info('---Failed when filling DataBase---')
end
:timer.sleep(1000)
end)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment