linear sync

This commit is contained in:
Arionum
2018-04-01 16:46:38 +03:00
parent a13c7285fd
commit 148c002f93
3 changed files with 8 additions and 6 deletions

View File

@@ -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
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
$current=$this->current();
$height=$current['height']+=1;
$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
$txn=new Transaction;
@@ -231,7 +231,7 @@ public function forge($nonce, $argon, $public_key, $private_key){
// add the block to the blockchain
$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;
}

View File

@@ -188,7 +188,7 @@ elseif($q=="submitBlock"){
_log('['.$_SERVER['REMOTE_ADDR']."] block ok, repropagating - $data[height]");
// 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");
}
// return the current block, used in syncing

View File

@@ -30,9 +30,10 @@ $block= new Block();
$type=san($argv[1]);
$id=san($argv[2]);
$debug=false;
$linear=false;
// if debug mode, all data is printed to console, no background processes
if(trim($argv[5])=='debug') $debug=true;
if(trim($argv[5])=='linear') $linear=true;
$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);
// fork a new process to send the blocks async
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 &");
}
exit;
@@ -80,7 +82,7 @@ if($type=="block"){
$hostname=base58_decode($peer);
// send the block as POST to the peer
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;}
elseif($response['request']=="microsync"){
// the peer requested us to send more blocks, as it's behind