2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2018-10-02 21:02:48 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2018-10-02 21:02:48 +02:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2018-10-02 21:02:48 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2018-10-02 21:02:48 +02:00
|
|
|
|
|
|
|
//! Helpers for submit a POW work.
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use rlp;
|
|
|
|
use ethcore::miner::{BlockChainClient, MinerService};
|
2019-02-25 14:27:28 +01:00
|
|
|
use ethereum_types::{H64, H256};
|
2018-10-02 21:02:48 +02:00
|
|
|
use jsonrpc_core::Error;
|
|
|
|
use v1::helpers::errors;
|
|
|
|
|
|
|
|
// Submit a POW work and return the block's hash
|
|
|
|
pub fn submit_work_detail<C: BlockChainClient, M: MinerService>(client: &Arc<C>, miner: &Arc<M>, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result<H256, Error> {
|
|
|
|
// TODO [ToDr] Should disallow submissions in case of PoA?
|
|
|
|
trace!(target: "miner", "submit_work_detail: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash);
|
2018-10-09 22:07:25 +02:00
|
|
|
let seal = vec![rlp::encode(&mix_hash), rlp::encode(&nonce)];
|
2018-10-02 21:02:48 +02:00
|
|
|
let import = miner.submit_seal(pow_hash, seal)
|
|
|
|
.and_then(|block| client.import_sealed_block(block));
|
|
|
|
match import {
|
|
|
|
Ok(hash) => {
|
|
|
|
Ok(hash.into())
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
warn!(target: "miner", "Cannot submit work - {:?}.", err);
|
|
|
|
Err(errors::cannot_submit_work(err))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|