external mansternode miner support
This commit is contained in:
@@ -24,6 +24,7 @@ class Block
|
|||||||
|
|
||||||
// create the block data and check it against the signature
|
// create the block data and check it against the signature
|
||||||
$info = "{$generator}-{$height}-{$date}-{$nonce}-{$json}-{$difficulty}-{$argon}";
|
$info = "{$generator}-{$height}-{$date}-{$nonce}-{$json}-{$difficulty}-{$argon}";
|
||||||
|
_log($info,3);
|
||||||
if (!$bootstrapping) {
|
if (!$bootstrapping) {
|
||||||
if (!$acc->check_signature($info, $signature, $public_key)) {
|
if (!$acc->check_signature($info, $signature, $public_key)) {
|
||||||
_log("Block signature check failed");
|
_log("Block signature check failed");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// ARO version
|
// ARO version
|
||||||
define("VERSION", "0.4.0");
|
define("VERSION", "0.4.1");
|
||||||
// Amsterdam timezone by default, should probably be moved to config
|
// Amsterdam timezone by default, should probably be moved to config
|
||||||
date_default_timezone_set("UTC");
|
date_default_timezone_set("UTC");
|
||||||
|
|
||||||
|
|||||||
100
mine.php
100
mine.php
@@ -55,7 +55,7 @@ if ($q == "info") {
|
|||||||
$argon_mem=524288;
|
$argon_mem=524288;
|
||||||
$argon_threads=1;
|
$argon_threads=1;
|
||||||
$argon_time=1;
|
$argon_time=1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($current_height%3==0) {
|
if ($current_height%3==0) {
|
||||||
$argon_mem=524288;
|
$argon_mem=524288;
|
||||||
@@ -110,6 +110,104 @@ if ($q == "info") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
api_err("rejected");
|
api_err("rejected");
|
||||||
|
} elseif ($q == "submitBlock") {
|
||||||
|
// in case the blocks are syncing, reject all
|
||||||
|
if ($_config['sanity_sync'] == 1) {
|
||||||
|
api_err("sanity-sync");
|
||||||
|
}
|
||||||
|
$nonce = san($_POST['nonce']);
|
||||||
|
$argon = $_POST['argon'];
|
||||||
|
$public_key = san($_POST['public_key']);
|
||||||
|
// check if the miner won the block
|
||||||
|
|
||||||
|
$result = $block->mine($public_key, $nonce, $argon);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
// generate the new block
|
||||||
|
$date = intval($_POST['date']);
|
||||||
|
if ($date <= $current['date']) {
|
||||||
|
api_err("rejected - date");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the mempool transactions
|
||||||
|
$txn = new Transaction();
|
||||||
|
$current = $block->current();
|
||||||
|
$height = $current['height'] += 1;
|
||||||
|
|
||||||
|
// get the mempool transactions
|
||||||
|
$txn = new Transaction();
|
||||||
|
|
||||||
|
|
||||||
|
$difficulty = $block->difficulty();
|
||||||
|
$acc = new Account();
|
||||||
|
$generator = $acc->get_address($public_key);
|
||||||
|
|
||||||
|
$data=json_decode($_POST['data'], true);
|
||||||
|
|
||||||
|
// sign the block
|
||||||
|
$signature = san($_POST['signature']);
|
||||||
|
|
||||||
|
// reward transaction and signature
|
||||||
|
$reward = $block->reward($height, $data);
|
||||||
|
$msg = '';
|
||||||
|
$transaction = [
|
||||||
|
"src" => $generator,
|
||||||
|
"dst" => $generator,
|
||||||
|
"val" => $reward,
|
||||||
|
"version" => 0,
|
||||||
|
"date" => $date,
|
||||||
|
"message" => $msg,
|
||||||
|
"fee" => "0.00000000",
|
||||||
|
"public_key" => $public_key,
|
||||||
|
];
|
||||||
|
ksort($transaction);
|
||||||
|
$reward_signature = san($_POST['reward_signature']);
|
||||||
|
|
||||||
|
// add the block to the blockchain
|
||||||
|
$res = $block->add(
|
||||||
|
$height,
|
||||||
|
$public_key,
|
||||||
|
$nonce,
|
||||||
|
$data,
|
||||||
|
$date,
|
||||||
|
$signature,
|
||||||
|
$difficulty,
|
||||||
|
$reward_signature,
|
||||||
|
$argon
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if ($res) {
|
||||||
|
//if the new block is generated, propagate it to all peers in background
|
||||||
|
$current = $block->current();
|
||||||
|
system("php propagate.php block $current[id] > /dev/null 2>&1 &");
|
||||||
|
api_echo("accepted");
|
||||||
|
} else {
|
||||||
|
api_err("rejected - add");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
api_err("rejected");
|
||||||
|
} elseif ($q == "getWork") {
|
||||||
|
if ($_config['sanity_sync'] == 1) {
|
||||||
|
api_err("sanity-sync");
|
||||||
|
}
|
||||||
|
$block = new Block();
|
||||||
|
$current = $block->current();
|
||||||
|
$height = $current['height'] += 1;
|
||||||
|
$date = time();
|
||||||
|
// get the mempool transactions
|
||||||
|
$txn = new Transaction();
|
||||||
|
$data = $txn->mempool($block->max_transactions());
|
||||||
|
|
||||||
|
|
||||||
|
$difficulty = $block->difficulty();
|
||||||
|
// always sort the transactions in the same way
|
||||||
|
ksort($data);
|
||||||
|
|
||||||
|
|
||||||
|
// reward transaction and signature
|
||||||
|
$reward = $block->reward($height, $data);
|
||||||
|
api_echo(["height"=>$height, "data"=>$data, "reward"=>$reward, "block"=>$current['id'], "difficulty"=>$difficulty]);
|
||||||
} else {
|
} else {
|
||||||
api_err("invalid command");
|
api_err("invalid command");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user