Class: Ethereum::Miner
Class Method Summary collapse
- .check_pow(block_number, header_hash, mixhash, nonce, difficulty) ⇒ Object
- .hashimoto_light(*args) ⇒ Object
Instance Method Summary collapse
-
#initialize(block) ⇒ Miner
constructor
Mines on the current head.
- #mine(rounds = 1000, start_nonce = 0) ⇒ Object
Constructor Details
#initialize(block) ⇒ Miner
Mines on the current head. Stores received transactions.
The process of finalising a block involves four stages:
-
validate (or, if mining, determine) uncles;
-
validate (or, if mining, determine) transactions;
-
apply rewards;
-
verify (or, if mining, compute a valid) state and nonce.
36 37 38 39 40 41 |
# File 'lib/ethereum/miner.rb', line 36 def initialize(block) @nonce = 0 @block = block logger.debug "mining", block_number: @block.number, block_hash: Utils.encode_hex(@block.full_hash), block_difficulty: @block.difficulty end |
Class Method Details
.check_pow(block_number, header_hash, mixhash, nonce, difficulty) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ethereum/miner.rb', line 7 def check_pow(block_number, header_hash, mixhash, nonce, difficulty) Logger.new('eth.miner').debug "checking pow", block_number: block_number return false if mixhash.size != 32 || header_hash.size != 32 || nonce.size != 8 cache = Ethash.get_cache block_number mining_output = hashimoto_light block_number, cache, header_hash, nonce return false if mining_output[:mixhash] != mixhash return Utils.big_endian_to_int(mining_output[:result]) <= (Constant::TT256 / difficulty) end |
.hashimoto_light(*args) ⇒ Object
20 21 22 |
# File 'lib/ethereum/miner.rb', line 20 def hashimoto_light(*args) Ethash.hashimoto_light(*args) end |
Instance Method Details
#mine(rounds = 1000, start_nonce = 0) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ethereum/miner.rb', line 43 def mine(rounds=1000, start_nonce=0) blk = @block bin_nonce, mixhash = _mine(blk.number, blk.difficulty, blk.mining_hash, start_nonce, rounds) if bin_nonce.true? blk.mixhash = mixhash blk.nonce = bin_nonce return blk end end |