class Avalon::Eloipool
Pool is a node encapsulating pool software
Public Class Methods
new(monitor, ip, frequency)
click to toggle source
Calls superclass method
# File lib/avalon/eloipool.rb, line 5 def initialize monitor, ip, frequency @ip, @frequency = ip, frequency @update_num = 0 @block_file = Avalon::Config[:block_file] @blocks = load_blocks || {} super() end
Public Instance Methods
add_new_blocks(pool_log, print = true)
click to toggle source
Add new blocks from pool log
# File lib/avalon/eloipool.rb, line 80 def add_new_blocks pool_log, print = true Block.print_headers if print pool_log.split(/\n/).each do |line| hash = line.chomp.match(/\h*$/).to_s unless @blocks[hash] @blocks[hash] = Block.new(hash) puts @blocks[hash] if print @pending_hash = hash end end save_blocks end
inspect()
click to toggle source
# File lib/avalon/eloipool.rb, line 97 def inspect @data.map {|name, value| "#{name}:#{value}"}.join(" ") end
load_blocks(print = true)
click to toggle source
# File lib/avalon/eloipool.rb, line 42 def load_blocks print = true if File.exist?(@block_file) Block.print_headers dump = YAML::load_file(@block_file) Hash[ *dump.map do |data| block = Block.new data puts block [data[:hash], block] end.flatten ] end end
poll(verbose=true)
click to toggle source
# File lib/avalon/eloipool.rb, line 13 def poll verbose=true self[:ping] = ping @ip self[:found] = `ssh #{@ip} "cat solo/logs/pool.log | grep BLKHASH | wc -l"`.to_i update_old_block puts "#{self}" if verbose end
report()
click to toggle source
Check for any exceptional situations, sound alarm if any
# File lib/avalon/eloipool.rb, line 24 def report if self[:ping].nil? alarm "Eloipool at #{@ip} not responding to ping" elsif self[:found] > @blocks.size add_new_blocks `ssh #{@ip} "cat solo/logs/pool.log | grep BLKHASH"` alarm "Eloipool found #{@found} blocks", :block_found elsif @blocks[@blocks.keys.last].pending? update_block @blocks[@blocks.keys.last] do alarm "Eloipool last block updated", :block_updated end end end
save_blocks()
click to toggle source
# File lib/avalon/eloipool.rb, line 37 def save_blocks dump = @blocks.values.map(&:data) File.open(@block_file, "w") {|file| YAML.dump(dump, file)} end
to_s()
click to toggle source
# File lib/avalon/eloipool.rb, line 93 def to_s "Eloipool: " + @data.map {|name, value| "#{name}:#{value}"}.join(" ") end
update_block(block, print = true) { |block| ... }
click to toggle source
# File lib/avalon/eloipool.rb, line 68 def update_block block, print = true if (block.pending? ? block.blockchain_update : block.bitcoind_update ) if print Block.print_headers puts block end save_blocks yield block if block_given? end end
update_old_block()
click to toggle source
# File lib/avalon/eloipool.rb, line 56 def update_old_block if rand(@frequency) == 0 # update once per @frequency polls hash = @blocks.keys[@update_num] if @blocks[hash] @update_num += 1 update_block(@blocks[hash], true) else @update_num = 0 end end end