diff --git a/shard.lock b/shard.lock index ed307e0b..5a754395 100644 --- a/shard.lock +++ b/shard.lock @@ -2,7 +2,11 @@ version: 1.0 shards: db: github: crystal-lang/crystal-db - version: 0.5.0 + version: 0.5.1 + + humanhash: + github: kingsleyh/humanhash + commit: aa533045dcc8986d6dba7f6408b8a10e578dad1e radix: github: luislavena/radix @@ -10,7 +14,7 @@ shards: router: github: tbrand/router.cr - version: 0.2.3 + version: 0.2.7 scrypt: github: ysbaddaden/scrypt-crystal @@ -18,9 +22,9 @@ shards: sqlite3: github: crystal-lang/crystal-sqlite3 - version: 0.9.0 + version: 0.10.0 tokoroten: github: tbrand/tokoroten - version: 0.1.2 + version: 0.1.3 diff --git a/shard.yml b/shard.yml index 85a1d9e0..4471467c 100644 --- a/shard.yml +++ b/shard.yml @@ -27,6 +27,8 @@ dependencies: github: crystal-lang/crystal-sqlite3 scrypt: github: ysbaddaden/scrypt-crystal + humanhash: + github: kingsleyh/humanhash crystal: 0.27.0 diff --git a/spec/units/utils/chain_generator.cr b/spec/units/utils/chain_generator.cr index f1fb84d4..b5aec1ef 100644 --- a/spec/units/utils/chain_generator.cr +++ b/spec/units/utils/chain_generator.cr @@ -40,7 +40,7 @@ module ::Units::Utils::ChainGenerator @node = Sushi::Core::Node.new(true, true, "bind_host", 8008_i32, nil, nil, nil, nil, nil, @node_wallet, nil, false) @blockchain = @node.blockchain @blockchain.setup(@node) - @miner = {context: {address: miner_wallet.address, nonces: [] of UInt64}, socket: MockWebSocket.new} + @miner = {context: {address: miner_wallet.address, nonces: [] of UInt64}, socket: MockWebSocket.new, mid: "535061bddb0549f691c8b9c012a55ee2"} @transaction_factory = TransactionFactory.new(@node_wallet) @rpc = RPCController.new(@blockchain) @rest = RESTController.new(@blockchain) diff --git a/src/core.cr b/src/core.cr index b6660bc0..fc805c00 100644 --- a/src/core.cr +++ b/src/core.cr @@ -26,6 +26,7 @@ require "tokoroten" require "http/server" require "openssl/pkcs5" require "openssl/digest" +require "humanhash" require "./common" require "./core/modules" diff --git a/src/core/miner/miner.cr b/src/core/miner/miner.cr index 6a7b8945..8c161ab9 100644 --- a/src/core/miner/miner.cr +++ b/src/core/miner/miner.cr @@ -14,6 +14,7 @@ module ::Sushi::Core class Miner < HandleSocket @wallet : Wallet @use_ssl : Bool + @mid : String = HumanHash.uuid.digest @workers : Array(Tokoroten::Worker) = [] of Tokoroten::Worker @@ -52,6 +53,7 @@ module ::Sushi::Core send(socket, M_TYPE_MINER_HANDSHAKE, { version: Core::CORE_VERSION, address: @wallet.address, + mid: @mid }) socket.run @@ -95,7 +97,7 @@ module ::Sushi::Core block = _m_content.block difficulty = _m_content.difficulty - info "#{magenta("UPDATED BLOCK")}: #{light_green(block.index)} at chain difficulty: #{light_cyan(block.next_difficulty - 1)} with miner difficulty: #{light_cyan(difficulty)}" + info "#{magenta("MINED BLOCK")}: #{light_green(block.index)} at chain difficulty: #{light_cyan(block.next_difficulty - 1)} with miner difficulty: #{light_cyan(difficulty)}" debug "set difficulty: #{light_cyan(difficulty)}" debug "set block: #{light_green(block.index)}" diff --git a/src/core/node.cr b/src/core/node.cr index d23700f6..0e272a9a 100644 --- a/src/core/node.cr +++ b/src/core/node.cr @@ -284,7 +284,7 @@ module ::Sushi::Core def broadcast_block(socket : HTTP::WebSocket, block : Block, from : Chord::NodeContext? = nil) if @blockchain.latest_index + 1 == block.index - info "new block coming: #{light_cyan(@blockchain.chain.size)}" + debug "new block coming: #{light_cyan(@blockchain.chain.size)}" if _block = @blockchain.valid_block?(block) new_block(_block) diff --git a/src/core/node/components/miners_manager.cr b/src/core/node/components/miners_manager.cr index c7082679..980a9535 100644 --- a/src/core/node/components/miners_manager.cr +++ b/src/core/node/components/miners_manager.cr @@ -22,6 +22,7 @@ module ::Sushi::Core::NodeComponents alias Miner = NamedTuple( context: MinerContext, socket: HTTP::WebSocket, + mid: String ) alias Miners = Array(Miner) @@ -40,6 +41,7 @@ module ::Sushi::Core::NodeComponents version = _m_content.version address = _m_content.address + mid = _m_content.mid if Core::CORE_VERSION > version return send(socket, @@ -61,11 +63,12 @@ module ::Sushi::Core::NodeComponents end miner_context = {address: address, nonces: [] of UInt64} - miner = {context: miner_context, socket: socket} + miner = {context: miner_context, socket: socket, mid: mid} @miners << miner - info "new miner: #{light_green(miner[:context][:address][0..7])} (#{@miners.size})" + miner_name = HumanHash.humanize(mid) + info "new miner: #{light_green(miner_name)} (#{@miners.size})" send(socket, M_TYPE_MINER_HANDSHAKE_ACCEPTED, { version: Core::CORE_VERSION, @@ -92,10 +95,11 @@ module ::Sushi::Core::NodeComponents send(miner[:socket], M_TYPE_MINER_BLOCK_UPDATE, { block: @blockchain.mining_block, - difficulty: @blockchain.mining_block_difficulty_miner, + difficulty: @blockchain.mining_block_difficulty_miner }) else - info "miner #{miner[:context][:address][0..7]} found nonce (nonces: #{miner[:context][:nonces].size})" + miner_name = HumanHash.humanize(miner[:mid]) + debug "miner #{miner_name} found nonce (nonces: #{miner[:context][:nonces].size})" miner[:context][:nonces].push(nonce) @@ -116,13 +120,14 @@ module ::Sushi::Core::NodeComponents end def broadcast + info "#{magenta("MINED BLOCK")}: #{light_green(@blockchain.mining_block.index)} at chain difficulty: #{light_cyan(@blockchain.mining_block_difficulty)} with miner difficulty: #{light_cyan(@blockchain.mining_block_difficulty_miner)}" debug "new block difficulty: #{@blockchain.mining_block_difficulty}, " + "mining difficulty: #{@blockchain.mining_block_difficulty_miner}" @miners.each do |miner| send(miner[:socket], M_TYPE_MINER_BLOCK_UPDATE, { block: @blockchain.mining_block, - difficulty: @blockchain.mining_block_difficulty_miner, + difficulty: @blockchain.mining_block_difficulty_miner }) end end diff --git a/src/core/protocol/protocol.cr b/src/core/protocol/protocol.cr index a7132fc9..c941d4b7 100644 --- a/src/core/protocol/protocol.cr +++ b/src/core/protocol/protocol.cr @@ -21,6 +21,7 @@ module ::Sushi::Core::Protocol JSON.mapping({ version: Int32, address: String, + mid: String }) end @@ -46,7 +47,7 @@ module ::Sushi::Core::Protocol struct M_CONTENT_MINER_FOUND_NONCE JSON.mapping({ - nonce: UInt64, + nonce: UInt64 }) end @@ -55,7 +56,7 @@ module ::Sushi::Core::Protocol struct M_CONTENT_MINER_BLOCK_UPDATE JSON.mapping({ block: Block, - difficulty: Int32, + difficulty: Int32 }) end