Skip to content

Commit

Permalink
Merge pull request #66 from bloom-solutions/batch_calls
Browse files Browse the repository at this point in the history
Use batch calls for btc to ease up bitcoind
  • Loading branch information
ramontayag committed Nov 14, 2018
2 parents 45250bc + bf34c49 commit 9d007af
Show file tree
Hide file tree
Showing 27 changed files with 1,629 additions and 193 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end

gem "addressable", "~> 2.5"
gem "bip44", "0.2.14"
gem "bitcoiner", "0.1.3"
gem "bitcoiner", github: "bloom-solutions/bitcoiner", branch: "all_features"
gem "btcruby", github: "bloom-solutions/btcruby", branch: "bloom_changes"
gem "dry-initializer", "~> 2.3"
gem "dry-types" # required by reform coercion
Expand Down
16 changes: 11 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/bloom-solutions/bitcoiner.git
revision: 28b33b674f804b07ffa5e424985c65acda0fe3fd
branch: all_features
specs:
bitcoiner (0.1.3)
addressable
typhoeus (~> 1.3.0)

GIT
remote: https://github.com/bloom-solutions/btcruby.git
revision: d0a7f0c9eca61c3e038bf16ca717d55e65155c12
Expand Down Expand Up @@ -65,9 +74,6 @@ GEM
money-tree
rlp (~> 0.7.3)
bip_mnemonic (0.0.2)
bitcoiner (0.1.3)
addressable
typhoeus (~> 1.3.0)
builder (3.2.3)
byebug (10.0.2)
capybara (2.18.0)
Expand Down Expand Up @@ -353,7 +359,7 @@ GEM
turbolinks (5.1.0)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
typhoeus (1.3.0)
typhoeus (1.3.1)
ethon (>= 0.9.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -382,7 +388,7 @@ PLATFORMS
DEPENDENCIES
addressable (~> 2.5)
bip44 (= 0.2.14)
bitcoiner (= 0.1.3)
bitcoiner!
btcruby!
byebug
capybara (~> 2.13)
Expand Down
11 changes: 0 additions & 11 deletions app/jobs/btc/sync_block_job.rb

This file was deleted.

16 changes: 14 additions & 2 deletions app/services/btc/check_txs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ def self.actions
SetBlocks,
GetCurrentBlock,
GetBlocksToSync,
iterate(:unsynced_blocks, [
EnqueueSyncBlockJob,
GetBlocksHashes,
GetRemoteBlocks,
iterate(:remote_blocks, [
DeleteForkedBlock,
SaveBlockInfo,
]),
GetRemoteBlocksTxs,
iterate(:remote_txs, [
GetRemoteTxOutputs,
iterate(:remote_tx_outputs, [
FindAddress,
SaveTxInfo,
NotifyTxReceipt,
])
])
]
end
Expand Down
12 changes: 0 additions & 12 deletions app/services/btc/enqueue_sync_block_job.rb

This file was deleted.

19 changes: 19 additions & 0 deletions app/services/btc/get_blocks_hashes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Btc
class GetBlocksHashes

extend LightService::Action
expects :bitcoiner_client, :unsynced_blocks
promises :block_hashes

executed do |c|
args = c.unsynced_blocks.map do |block_height|
["getblockhash", [block_height]]
end

response = c.bitcoiner_client.request(args)

c.block_hashes = response.map { |hash| hash["result"] }
end

end
end
20 changes: 20 additions & 0 deletions app/services/btc/get_remote_blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Btc
class GetRemoteBlocks

extend LightService::Action
expects :bitcoiner_client, :block_hashes
promises :remote_blocks
VERBOSITY = 2

executed do |c|
args = c.block_hashes.map do |block_hash|
["getblock", [block_hash, VERBOSITY]]
end

response = c.bitcoiner_client.request(args)

c.remote_blocks = response.map { |hash| hash["result"] }
end

end
end
15 changes: 15 additions & 0 deletions app/services/btc/get_remote_blocks_txs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Btc
module GetRemoteBlocksTxs

extend LightService::Action
expects :bitcoiner_client, :remote_blocks
promises :remote_txs

executed do |c|
c.remote_txs = c.remote_blocks.map do |remote_block|
remote_block["tx"] || []
end.flatten
end

end
end
13 changes: 0 additions & 13 deletions app/services/btc/get_remote_txs.rb

This file was deleted.

16 changes: 16 additions & 0 deletions app/services/btc/get_remote_txs_from_tx_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Btc
class GetRemoteTxsFromTxIds

extend LightService::Action
expects :bitcoiner_client, :tx_ids
promises :remote_txs
VERBOSE = true

executed do |c|
args = c.tx_ids.map { |tx_id| ["getrawtransaction", [tx_id, VERBOSE]] }
response = c.bitcoiner_client.request(args)
c.remote_txs = response.map { |r| r["result"] }
end

end
end
31 changes: 0 additions & 31 deletions app/services/btc/sync_block.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/services/btc/sync_unconfirmed_txs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def self.actions
[
InitBitcoinerClient,
GetRawMempoolTxIds,
iterate(:tx_ids, [
GetRemoteTx,
GetRemoteTxsFromTxIds,
iterate(:remote_txs, [
GetRemoteTxOutputs,
iterate(:remote_tx_outputs, [
FindAddress,
Expand Down
39 changes: 31 additions & 8 deletions app/services/sync_missing_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,37 @@ def self.call(coin)
private

def self.actions_for(coin)
coin_namespace = coin.classify.constantize
[
coin_namespace.const_get("SetBlocks"),
DetectBlockGaps,
iterate(:unsynced_blocks, [
coin_namespace.const_get("EnqueueSyncBlockJob"),
])
]
case coin
when "btc"
[
InitBitcoinerClient,
Btc::SetBlocks,
DetectBlockGaps,
Btc::GetBlocksHashes,
Btc::GetRemoteBlocks,
iterate(:remote_blocks, [
Btc::DeleteForkedBlock,
Btc::SaveBlockInfo,
]),
Btc::GetRemoteBlocksTxs,
iterate(:remote_txs, [
Btc::GetRemoteTxOutputs,
iterate(:remote_tx_outputs, [
Btc::FindAddress,
Btc::SaveTxInfo,
NotifyTxReceipt,
])
])
]
when "eth"
[
Eth::SetBlocks,
DetectBlockGaps,
iterate(:unsynced_blocks, [
Eth::EnqueueSyncBlockJob,
])
]
end
end

end

0 comments on commit 9d007af

Please sign in to comment.