linear sync
This commit is contained in:
@@ -199,13 +199,13 @@ public function forge($nonce, $argon, $public_key, $private_key){
|
|||||||
|
|
||||||
//check the argon hash and the nonce to produce a valid block
|
//check the argon hash and the nonce to produce a valid block
|
||||||
|
|
||||||
if(!$this->mine($public_key,$nonce, $argon)) return false;
|
if(!$this->mine($public_key,$nonce, $argon)) { _log("Forge failed - Invalid argon"); return false; }
|
||||||
|
|
||||||
// the block's date timestamp must be bigger than the last block
|
// the block's date timestamp must be bigger than the last block
|
||||||
$current=$this->current();
|
$current=$this->current();
|
||||||
$height=$current['height']+=1;
|
$height=$current['height']+=1;
|
||||||
$date=time();
|
$date=time();
|
||||||
if($date<=$current['date']) return 0;
|
if($date<=$current['date']) { _log("Forge failed - Date older than last block"); return false; }
|
||||||
|
|
||||||
// get the mempool transactions
|
// get the mempool transactions
|
||||||
$txn=new Transaction;
|
$txn=new Transaction;
|
||||||
@@ -231,7 +231,7 @@ public function forge($nonce, $argon, $public_key, $private_key){
|
|||||||
|
|
||||||
// add the block to the blockchain
|
// add the block to the blockchain
|
||||||
$res=$this->add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon);
|
$res=$this->add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon);
|
||||||
if(!$res) return false;
|
if(!$res) { _log("Forge failed - Block->Add() failed"); return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
peer.php
2
peer.php
@@ -188,7 +188,7 @@ elseif($q=="submitBlock"){
|
|||||||
_log('['.$_SERVER['REMOTE_ADDR']."] block ok, repropagating - $data[height]");
|
_log('['.$_SERVER['REMOTE_ADDR']."] block ok, repropagating - $data[height]");
|
||||||
|
|
||||||
// send it to all our peers
|
// send it to all our peers
|
||||||
// system("php propagate.php block '$data[id]' > /dev/null 2>&1 &");
|
// system("php propagate.php block '$data[id]' all all linear > /dev/null 2>&1 &");
|
||||||
api_echo("block-ok");
|
api_echo("block-ok");
|
||||||
}
|
}
|
||||||
// return the current block, used in syncing
|
// return the current block, used in syncing
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ $block= new Block();
|
|||||||
$type=san($argv[1]);
|
$type=san($argv[1]);
|
||||||
$id=san($argv[2]);
|
$id=san($argv[2]);
|
||||||
$debug=false;
|
$debug=false;
|
||||||
|
$linear=false;
|
||||||
// if debug mode, all data is printed to console, no background processes
|
// if debug mode, all data is printed to console, no background processes
|
||||||
if(trim($argv[5])=='debug') $debug=true;
|
if(trim($argv[5])=='debug') $debug=true;
|
||||||
|
if(trim($argv[5])=='linear') $linear=true;
|
||||||
$peer=san(trim($argv[3]));
|
$peer=san(trim($argv[3]));
|
||||||
|
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ if((empty($peer)||$peer=='all')&&$type=="block"){
|
|||||||
$ip=filter_var($x['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
$ip=filter_var($x['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
||||||
// fork a new process to send the blocks async
|
// fork a new process to send the blocks async
|
||||||
if($debug) system("php propagate.php '$type' '$id' '$host' '$ip' debug");
|
if($debug) system("php propagate.php '$type' '$id' '$host' '$ip' debug");
|
||||||
|
elseif($linear) system("php propagate.php '$type' '$id' '$host' '$ip' linear");
|
||||||
else system("php propagate.php '$type' '$id' '$host' 'ip' > /dev/null 2>&1 &");
|
else system("php propagate.php '$type' '$id' '$host' 'ip' > /dev/null 2>&1 &");
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
@@ -80,7 +82,7 @@ if($type=="block"){
|
|||||||
$hostname=base58_decode($peer);
|
$hostname=base58_decode($peer);
|
||||||
// send the block as POST to the peer
|
// send the block as POST to the peer
|
||||||
echo "Block sent to $hostname:\n";
|
echo "Block sent to $hostname:\n";
|
||||||
$response= peer_post($hostname."/peer.php?q=submitBlock",$data,60,$debug);
|
$response= peer_post($hostname."/peer.php?q=submitBlock",$data,60, $debug);
|
||||||
if($response=="block-ok") { echo "Block $i accepted. Exiting.\n"; exit;}
|
if($response=="block-ok") { echo "Block $i accepted. Exiting.\n"; exit;}
|
||||||
elseif($response['request']=="microsync"){
|
elseif($response['request']=="microsync"){
|
||||||
// the peer requested us to send more blocks, as it's behind
|
// the peer requested us to send more blocks, as it's behind
|
||||||
|
|||||||
Reference in New Issue
Block a user