grin中
挖矿的文档
https://github.com/mimblewimble/grin/blob/master/doc/stratum.md
结构体



矿工获取挖矿数据

JobTemplate中的pre_pow,这时候还没有经过hash。只是经过to_hex()

to_hex()

grin-miner中
在client.rs中
这里面有挖矿时跟节点交互的各种方法。重点关注send_message_get_job_tempalte
,这个就是向服务器发送了getjobtemplate
的jsonrpc请求。

继续看
Controller
的run
方法,方法太长,只挑选部分代码
// 向服务器发送请求
let _ = self.send_message_get_job_template();
// 从服务器读取数据
match self.read_message() {
}
// 对消息进行判断
debug!(LOGGER, "Received message: {}", m);
// Deserialize to see what type of object it is
let v: serde_json::Value = serde_json::from_str(&m).unwrap();
// Is this a response or request?
if v["id"] == String::from("Stratum") {
// this is a request
let request: types::RpcRequest =
serde_json::from_str(&m).unwrap();
let _ = self.handle_request(request);
continue;
} else {
// this is a response
let response: types::RpcResponse =
serde_json::from_str(&m).unwrap();
let _ = self.handle_response(response);
continue;
}
// run的任务未完,后面继续。。。
如果这是一个response
,就处理他let _ = self.handle_response(response);
handle_response
中会对收到的消息类型进行判断,然后进行相应的处理。

重要的是这句
let _ = self.send_miner_job(job);
,就是发送给挖矿那边了。
挖矿那边处理接受之后的信息

我们看他对信息简单加工之后,又调用了
run_solver

再找到

这里的run_solver就是c的代码了


按照之前在文档中的说明,
run_solver
中传进去的header
需要先进行hash,然后用hash生成图,然后才是cuckoo cycle
算法发挥了。



首先将nonce添加到header最后,然后进行blake2b
运算。keys->setkeys(hcrkey)
就是生成图的keys了,还不是图。
再看挖矿那边的代码
再main.rs中

solution
pub struct Proof {
/// Power of 2 used for the size of the cuckoo graph
pub edge_bits: u8,
/// The nonces
pub nonces: Vec<u64>,
}
再看找到解决方案后的hash

网友评论