Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
984aedc940 | ||
|
|
e59bb416b4 | ||
|
|
57d2257c43 | ||
|
|
8c32d1c71b | ||
|
|
b5110bf01f | ||
|
|
0567899edd | ||
|
|
66b1221e22 | ||
|
|
9e9c12fbbb | ||
|
|
c5002508d6 | ||
|
|
fbc48921f3 | ||
|
|
07dcebd895 | ||
|
|
6651ff54fc | ||
|
|
38745111ef | ||
|
|
c83895d384 | ||
|
|
62cc290b50 | ||
|
|
dab6648ae8 | ||
|
|
5c476be954 | ||
|
|
0d5f79fc20 | ||
|
|
5fc167cfbf | ||
|
|
5f4b6d9d51 | ||
|
|
e707f8daa4 | ||
|
|
a09279d091 | ||
|
|
d9e5ad94de | ||
|
|
8b006fc26a | ||
|
|
066211b2c0 | ||
|
|
06960e64e7 | ||
|
|
b276fde6da | ||
|
|
7ebf3e0e8a |
@@ -4,6 +4,12 @@ The Arionum (ARO) cryptocurrency node.
|
||||
|
||||
## Install
|
||||
|
||||
**Hardware Requirements:**
|
||||
```
|
||||
2GB RAM
|
||||
1 CPU Core
|
||||
50GB DISK
|
||||
```
|
||||
**Requirements:**
|
||||
|
||||
- PHP 7.2
|
||||
@@ -13,7 +19,7 @@ The Arionum (ARO) cryptocurrency node.
|
||||
- MySQL/MariaDB
|
||||
|
||||
1. Install MySQL or MariaDB and create a database and a user.
|
||||
2. Edit `include/config.inc.php` and set the DB login data
|
||||
2. Rename `include/config-sample.inc.php` to `include/config.inc.php` and set the DB login data
|
||||
3. Change permissions to tmp and `tmp/db-update` to 777 (`chmod 777 tmp -R`)
|
||||
4. Access the http://ip-or-domain and refresh once
|
||||
|
||||
|
||||
6
UPGRADE
Normal file
6
UPGRADE
Normal file
@@ -0,0 +1,6 @@
|
||||
In order to upgrade your Arionum Node, follow the next steps:
|
||||
1. Download the source code from https://github.com/arionum/node
|
||||
2. Edit the include/config.inc.php with the DB details
|
||||
3. Replace your old node folder with the new one.
|
||||
4. chmod 777 tmp -R
|
||||
5. Load the node's address in your browser.
|
||||
107
api.php
107
api.php
@@ -124,18 +124,23 @@ if ($q == "getAddress") {
|
||||
*
|
||||
* @apiParam {string} [public_key] Public key
|
||||
* @apiParam {string} [account] Account id / address
|
||||
* @apiParam {string} [alias] alias
|
||||
*
|
||||
* @apiSuccess {string} data The ARO balance
|
||||
*/
|
||||
|
||||
$public_key = $data['public_key'];
|
||||
$account = $data['account'];
|
||||
$alias = $data['alias'];
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
if (!empty($public_key)) {
|
||||
$account = $acc->get_address($public_key);
|
||||
}
|
||||
if (!empty($alias)) {
|
||||
$account = $acc->alias2account($alias);
|
||||
}
|
||||
if (empty($account)) {
|
||||
api_err("Invalid account id");
|
||||
}
|
||||
@@ -395,9 +400,13 @@ if ($q == "getAddress") {
|
||||
$block = new Block();
|
||||
|
||||
$trx = new Transaction();
|
||||
|
||||
$version = intval($data['version']);
|
||||
$dst = san($data['dst']);
|
||||
if ($version < 1) {
|
||||
$version = 1;
|
||||
}
|
||||
|
||||
if ($version==1) {
|
||||
if (!$acc->valid($dst)) {
|
||||
api_err("Invalid destination address");
|
||||
}
|
||||
@@ -405,6 +414,14 @@ if ($q == "getAddress") {
|
||||
if (strlen($dst_b) != 64) {
|
||||
api_err("Invalid destination address");
|
||||
}
|
||||
} elseif ($version==2) {
|
||||
$dst=strtoupper($dst);
|
||||
$dst = san($dst);
|
||||
if (!$acc->valid_alias($dst)) {
|
||||
api_err("Invalid destination alias");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$public_key = san($data['public_key']);
|
||||
@@ -430,7 +447,7 @@ if ($q == "getAddress") {
|
||||
if ($date > time() + 86400) {
|
||||
api_err("Invalid Date");
|
||||
}
|
||||
$version = intval($data['version']);
|
||||
|
||||
$message=$data['message'];
|
||||
if (strlen($message) > 128) {
|
||||
api_err("The message must be less than 128 chars");
|
||||
@@ -449,8 +466,27 @@ if ($q == "getAddress") {
|
||||
api_err("Invalid value");
|
||||
}
|
||||
|
||||
if ($version < 1) {
|
||||
$version = 1;
|
||||
// set alias
|
||||
if ($version==3) {
|
||||
$fee=10;
|
||||
$message = san($message);
|
||||
$message=strtoupper($message);
|
||||
if (!$acc->free_alias($message)) {
|
||||
api_err("Invalid alias");
|
||||
}
|
||||
if ($acc->has_alias($public_key)) {
|
||||
api_err("This account already has an alias");
|
||||
}
|
||||
}
|
||||
|
||||
if ($version>=100&&$version<110) {
|
||||
if ($version==100) {
|
||||
$message=preg_replace("/[^0-9\.]/", "", $message);
|
||||
if (!filter_var($message, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
||||
api_err("Invalid Node IP - $message !");
|
||||
}
|
||||
$val=100000;
|
||||
}
|
||||
}
|
||||
|
||||
$val = number_format($val, 8, '.', '');
|
||||
@@ -570,6 +606,69 @@ if ($q == "getAddress") {
|
||||
mt_srand($seed1, MT_RAND_MT19937);
|
||||
$res = mt_rand($min, $max);
|
||||
api_echo($res);
|
||||
} elseif ($q == "checkSignature") {
|
||||
/**
|
||||
* @api {get} /api.php?q=checkSignature 17. checkSignature
|
||||
* @apiName checkSignature
|
||||
* @apiGroup API
|
||||
* @apiDescription Checks a signature against a public key
|
||||
*
|
||||
* @apiParam {string} [public_key] Public key
|
||||
* @apiParam {string} [signature] signature
|
||||
* @apiParam {string} [data] signed data
|
||||
*
|
||||
*
|
||||
* @apiSuccess {boolean} data true or false
|
||||
*/
|
||||
|
||||
$public_key=san($data['public_key']);
|
||||
$signature=san($data['signature']);
|
||||
$data=$data['data'];
|
||||
|
||||
api_echo(ec_verify($data, $signature, $public_key));
|
||||
} elseif ($q == "masternodes") {
|
||||
/**
|
||||
* @api {get} /api.php?q=masternodes 18. masternodes
|
||||
* @apiName masternodes
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns all the masternode data
|
||||
*
|
||||
*
|
||||
*
|
||||
* @apiSuccess {boolean} data masternode date
|
||||
*/
|
||||
|
||||
$res=$db->run("SELECT * FROM masternode");
|
||||
api_echo($res);
|
||||
} elseif ($q == "getAlias") {
|
||||
/**
|
||||
* @api {get} /api.php?q=getAlias 189. getAlias
|
||||
* @apiName getAlias
|
||||
* @apiGroup API
|
||||
* @apiDescription Returns the alias of an account
|
||||
*
|
||||
* @apiParam {string} [public_key] Public key
|
||||
* @apiParam {string} [account] Account id / address
|
||||
*
|
||||
*
|
||||
* @apiSuccess {string} data alias
|
||||
*/
|
||||
|
||||
$public_key = $data['public_key'];
|
||||
$account = $data['account'];
|
||||
if (!empty($public_key) && strlen($public_key) < 32) {
|
||||
api_err("Invalid public key");
|
||||
}
|
||||
if (!empty($public_key)) {
|
||||
$account = $acc->get_address($public_key);
|
||||
}
|
||||
|
||||
if (empty($account)) {
|
||||
api_err("Invalid account id");
|
||||
}
|
||||
$account = san($account);
|
||||
|
||||
api_echo($acc->account2alias($account));
|
||||
} else {
|
||||
api_err("Invalid request");
|
||||
}
|
||||
|
||||
144
doc/api_data.js
144
doc/api_data.js
@@ -101,6 +101,57 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkSignature",
|
||||
"title": "17. checkSignature",
|
||||
"name": "checkSignature",
|
||||
"group": "API",
|
||||
"description": "<p>Checks a signature against a public key</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "signature",
|
||||
"description": "<p>signature</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "data",
|
||||
"description": "<p>signed data</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>true or false</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=currentBlock",
|
||||
@@ -249,6 +300,50 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getAlias",
|
||||
"title": "189. getAlias",
|
||||
"name": "getAlias",
|
||||
"group": "API",
|
||||
"description": "<p>Returns the alias of an account</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>alias</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getBalance",
|
||||
@@ -272,6 +367,13 @@ define({ "api": [
|
||||
"optional": true,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "alias",
|
||||
"description": "<p>alias</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -865,6 +967,30 @@ define({ "api": [
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=masternodes",
|
||||
"title": "18. masternodes",
|
||||
"name": "masternodes",
|
||||
"group": "API",
|
||||
"description": "<p>Returns all the masternode data</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>masternode date</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=mempoolSize",
|
||||
@@ -1269,6 +1395,24 @@ define({ "api": [
|
||||
"filename": "./util.php",
|
||||
"groupTitle": "UTIL"
|
||||
},
|
||||
{
|
||||
"type": "php util.php",
|
||||
"url": "clean-blacklist",
|
||||
"title": "Clean-Blacklist",
|
||||
"name": "clean_blacklist",
|
||||
"group": "UTIL",
|
||||
"description": "<p>Removes all the peers from blacklist</p>",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Example usage:",
|
||||
"content": "php util.php clean-blacklist",
|
||||
"type": "cli"
|
||||
}
|
||||
],
|
||||
"version": "0.0.0",
|
||||
"filename": "./util.php",
|
||||
"groupTitle": "UTIL"
|
||||
},
|
||||
{
|
||||
"type": "php util.php",
|
||||
"url": "current",
|
||||
|
||||
@@ -101,6 +101,57 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=checkSignature",
|
||||
"title": "17. checkSignature",
|
||||
"name": "checkSignature",
|
||||
"group": "API",
|
||||
"description": "<p>Checks a signature against a public key</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "signature",
|
||||
"description": "<p>signature</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "data",
|
||||
"description": "<p>signed data</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>true or false</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=currentBlock",
|
||||
@@ -249,6 +300,50 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getAlias",
|
||||
"title": "189. getAlias",
|
||||
"name": "getAlias",
|
||||
"group": "API",
|
||||
"description": "<p>Returns the alias of an account</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "public_key",
|
||||
"description": "<p>Public key</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>alias</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=getBalance",
|
||||
@@ -272,6 +367,13 @@
|
||||
"optional": true,
|
||||
"field": "account",
|
||||
"description": "<p>Account id / address</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"field": "alias",
|
||||
"description": "<p>alias</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -865,6 +967,30 @@
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=masternodes",
|
||||
"title": "18. masternodes",
|
||||
"name": "masternodes",
|
||||
"group": "API",
|
||||
"description": "<p>Returns all the masternode data</p>",
|
||||
"success": {
|
||||
"fields": {
|
||||
"Success 200": [
|
||||
{
|
||||
"group": "Success 200",
|
||||
"type": "boolean",
|
||||
"optional": false,
|
||||
"field": "data",
|
||||
"description": "<p>masternode date</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./api.php",
|
||||
"groupTitle": "API"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "/api.php?q=mempoolSize",
|
||||
@@ -1269,6 +1395,24 @@
|
||||
"filename": "./util.php",
|
||||
"groupTitle": "UTIL"
|
||||
},
|
||||
{
|
||||
"type": "php util.php",
|
||||
"url": "clean-blacklist",
|
||||
"title": "Clean-Blacklist",
|
||||
"name": "clean_blacklist",
|
||||
"group": "UTIL",
|
||||
"description": "<p>Removes all the peers from blacklist</p>",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Example usage:",
|
||||
"content": "php util.php clean-blacklist",
|
||||
"type": "cli"
|
||||
}
|
||||
],
|
||||
"version": "0.0.0",
|
||||
"filename": "./util.php",
|
||||
"groupTitle": "UTIL"
|
||||
},
|
||||
{
|
||||
"type": "php util.php",
|
||||
"url": "current",
|
||||
|
||||
@@ -7,7 +7,7 @@ define({
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-05-09T23:01:25.347Z",
|
||||
"time": "2018-08-05T21:17:14.214Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-05-09T23:01:25.347Z",
|
||||
"time": "2018-08-05T21:17:14.214Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
||||
@@ -93,7 +93,71 @@ class Account
|
||||
|
||||
return true;
|
||||
}
|
||||
//check alias validity
|
||||
public function free_alias($id)
|
||||
{
|
||||
global $db;
|
||||
$orig=$id;
|
||||
$id=strtoupper($id);
|
||||
$id = san($id);
|
||||
if (strlen($id)<4||strlen($id)>25) {
|
||||
return false;
|
||||
}
|
||||
if($orig!=$id){
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($db->single("SELECT COUNT(1) FROM accounts WHERE alias=:alias", [":alias"=>$id])==0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//check if an account already has an alias
|
||||
public function has_alias($public_key){
|
||||
global $db;
|
||||
$public_key=san($public_key);
|
||||
$res=$db->single("SELECT COUNT(1) FROM accounts WHERE public_key=:public_key AND alias IS NOT NULL",[":public_key"=>$public_key]);
|
||||
if($res!=0) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
//check alias validity
|
||||
public function valid_alias($id)
|
||||
{
|
||||
global $db;
|
||||
$orig=$id;
|
||||
$banned=["MERCURY","DEVS","DEVELOPMENT", "MARKETING", "MERCURY80","DEVARO", "DEVELOPER","DEVELOPERS","ARODEV", "DONATION","MERCATOX", "OCTAEX", "MERCURY", "ARIONUM", "ESCROW","OKEX","BINANCE","CRYPTOPIA","HUOBI","ITFINEX","HITBTC","UPBIT","COINBASE","KRAKEN","BITSTAMP","BITTREX","POLONIEX"];
|
||||
$id=strtoupper($id);
|
||||
$id = san($id);
|
||||
if (in_array($id, $banned)) {
|
||||
return false;
|
||||
}
|
||||
if (strlen($id)<4||strlen($id)>25) {
|
||||
return false;
|
||||
}
|
||||
if($orig!=$id){
|
||||
return false;
|
||||
}
|
||||
return $db->single("SELECT COUNT(1) FROM accounts WHERE alias=:alias", [":alias"=>$id]);
|
||||
}
|
||||
|
||||
//returns the account of an alias
|
||||
public function alias2account($alias){
|
||||
global $db;
|
||||
$alias=strtoupper($alias);
|
||||
$res=$db->single("SELECT id FROM accounts WHERE alias=:alias LIMIT 1",[":alias"=>$alias]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
//returns the alias of an account
|
||||
public function account2alias($id){
|
||||
global $db;
|
||||
$id=san($id);
|
||||
$res=$db->single("SELECT alias FROM accounts WHERE id=:id LIMIT 1",[":id"=>$id]);
|
||||
return $res;
|
||||
}
|
||||
// check the validity of an address. At the moment, it checks only the characters to be base58 and the length to be >=70 and <=128.
|
||||
public function valid($id)
|
||||
{
|
||||
@@ -234,4 +298,12 @@ class Account
|
||||
$res = $db->single("SELECT public_key FROM accounts WHERE id=:id", [":id" => $id]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function get_masternode($public_key){
|
||||
global $db;
|
||||
$res = $db->row("SELECT * FROM masternode WHERE public_key=:public_key", [":public_key" => $public_key]);
|
||||
if(empty($res['public_key'])) return false;
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class Block
|
||||
{
|
||||
public function add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon)
|
||||
public function add($height, $public_key, $nonce, $data, $date, $signature, $difficulty, $reward_signature, $argon, $bootstrapping=false)
|
||||
{
|
||||
global $db;
|
||||
$acc = new Account();
|
||||
@@ -24,6 +24,8 @@ class Block
|
||||
|
||||
// create the block data and check it against the signature
|
||||
$info = "{$generator}-{$height}-{$date}-{$nonce}-{$json}-{$difficulty}-{$argon}";
|
||||
// _log($info,3);
|
||||
if (!$bootstrapping) {
|
||||
if (!$acc->check_signature($info, $signature, $public_key)) {
|
||||
_log("Block signature check failed");
|
||||
return false;
|
||||
@@ -33,14 +35,35 @@ class Block
|
||||
_log("Parse block failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE, masternode WRITE, peers write, config WRITE");
|
||||
|
||||
$reward = $this->reward($height, $data);
|
||||
|
||||
$msg = '';
|
||||
|
||||
if($height>=80460){
|
||||
//reward the masternode
|
||||
|
||||
$mn_winner=$db->single(
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
||||
[":current"=>$height, ":start"=>$height-360]
|
||||
);
|
||||
_log("MN Winner: $mn_winner",2);
|
||||
if($mn_winner!==false){
|
||||
$mn_reward=round(0.33*$reward,8);
|
||||
$reward=round($reward-$mn_reward,8);
|
||||
$reward=number_format($reward,8,".","");
|
||||
$mn_reward=number_format($mn_reward,8,".","");
|
||||
_log("MN Reward: $mn_reward",2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// the reward transaction
|
||||
$transaction = [
|
||||
"src" => $generator,
|
||||
@@ -55,16 +78,19 @@ class Block
|
||||
$transaction['signature'] = $reward_signature;
|
||||
// hash the transaction
|
||||
$transaction['id'] = $trx->hash($transaction);
|
||||
if (!$bootstrapping) {
|
||||
// check the signature
|
||||
$info = $transaction['val']."-".$transaction['fee']."-".$transaction['dst']."-".$transaction['message']."-".$transaction['version']."-".$transaction['public_key']."-".$transaction['date'];
|
||||
if (!$acc->check_signature($info, $reward_signature, $public_key)) {
|
||||
_log("Reward signature failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
// insert the block into the db
|
||||
$db->beginTransaction();
|
||||
$total = count($data);
|
||||
|
||||
|
||||
$bind = [
|
||||
":id" => $hash,
|
||||
":generator" => $generator,
|
||||
@@ -91,8 +117,36 @@ class Block
|
||||
// insert the reward transaction in the db
|
||||
$trx->add($hash, $height, $transaction);
|
||||
|
||||
if($mn_winner!==false){
|
||||
$db->run("UPDATE accounts SET balance=balance+:bal WHERE public_key=:pub",[":pub"=>$mn_winner, ":bal"=>$mn_reward]);
|
||||
$bind = [
|
||||
":id" => hex2coin(hash("sha512", "mn".$hash.$height.$mn_winner)),
|
||||
":public_key" => $public_key,
|
||||
":height" => $height,
|
||||
":block" => $hash,
|
||||
":dst" => $acc->get_address($mn_winner),
|
||||
":val" => $mn_reward,
|
||||
":fee" => 0,
|
||||
":signature" => $reward_signature,
|
||||
":version" => 0,
|
||||
":date" => $date,
|
||||
":message" => 'masternode',
|
||||
];
|
||||
$res = $db->run(
|
||||
"INSERT into transactions SET id=:id, public_key=:public_key, block=:block, height=:height, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
||||
$bind
|
||||
);
|
||||
$this->reset_fails_masternodes($mn_winner, $height, $hash);
|
||||
|
||||
}
|
||||
|
||||
// parse the block's transactions and insert them to db
|
||||
$res = $this->parse_block($hash, $height, $data, false);
|
||||
$res = $this->parse_block($hash, $height, $data, false, $bootstrapping);
|
||||
|
||||
if (($height-1)%3==2 && $height>=80000&&$height<80460) {
|
||||
$this->blacklist_masternodes();
|
||||
$this->reset_fails_masternodes($public_key, $height, $hash);
|
||||
}
|
||||
// if any fails, rollback
|
||||
if ($res == false) {
|
||||
$db->rollback();
|
||||
@@ -104,6 +158,41 @@ class Block
|
||||
return true;
|
||||
}
|
||||
|
||||
// resets the number of fails when winning a block and marks it with a transaction
|
||||
|
||||
public function reset_fails_masternodes($public_key, $height, $hash)
|
||||
{
|
||||
global $db;
|
||||
$res=$this->masternode_log($public_key, $height, $hash);
|
||||
|
||||
if ($res) {
|
||||
$db->run("UPDATE masternode SET last_won=:last_won,fails=0 WHERE public_key=:public_key", [":public_key"=>$public_key, ":last_won"=>$height]);
|
||||
}
|
||||
}
|
||||
|
||||
//logs the current masternode status
|
||||
public function masternode_log($public_key, $height, $hash)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$mn=$db->row("SELECT blacklist,last_won,fails FROM masternode WHERE public_key=:public_key", [":public_key"=>$public_key]);
|
||||
|
||||
if (!$mn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = hex2coin(hash("sha512", "resetfails-$hash-$height-$public_key"));
|
||||
$msg="$mn[blacklist],$mn[last_won],$mn[fails]";
|
||||
|
||||
$db->run(
|
||||
|
||||
"INSERT into transactions SET id=:id, block=:block, height=:height, dst=:dst, val=0, fee=0, signature=:sig, version=111, message=:msg, date=:date, public_key=:public_key",
|
||||
[":id"=>$id, ":block"=>$hash, ":height"=>$height, ":dst"=>$hash, ":sig"=>$hash, ":msg"=>$msg, ":date"=>time(), ":public_key"=>$public_key]
|
||||
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns the current block, without the transactions
|
||||
public function current()
|
||||
{
|
||||
@@ -155,12 +244,16 @@ class Block
|
||||
return $current['difficulty'];
|
||||
}
|
||||
|
||||
// before mnn hf
|
||||
if ($height<80000) {
|
||||
// elapsed time between the last 20 blocks
|
||||
$first = $db->row("SELECT `date` FROM blocks ORDER by height DESC LIMIT $limit,1");
|
||||
$time = $current['date'] - $first['date'];
|
||||
|
||||
// avg block time
|
||||
$result = ceil($time / $limit);
|
||||
_log("Block time: $result", 3);
|
||||
|
||||
|
||||
// if larger than 200 sec, increase by 5%
|
||||
if ($result > 220) {
|
||||
@@ -172,6 +265,49 @@ class Block
|
||||
// keep current difficulty
|
||||
$dif = $current['difficulty'];
|
||||
}
|
||||
} else {
|
||||
// hardfork 80000, fix difficulty targetting
|
||||
|
||||
|
||||
|
||||
$type=$height%3;
|
||||
// for mn, we use gpu diff
|
||||
if ($type == 2) {
|
||||
return $current['difficulty'];
|
||||
}
|
||||
|
||||
$blks=0;
|
||||
$total_time=0;
|
||||
$blk = $db->run("SELECT `date`, height FROM blocks ORDER by height DESC LIMIT 60");
|
||||
for ($i=0;$i<59;$i++) {
|
||||
$ctype=$blk[$i+1]['height']%3;
|
||||
$time=$blk[$i]['date']-$blk[$i+1]['date'];
|
||||
if ($type!=$ctype) {
|
||||
continue;
|
||||
}
|
||||
$blks++;
|
||||
$total_time+=$time;
|
||||
}
|
||||
$result=ceil($total_time/$blks);
|
||||
_log("Block time: $result", 3);
|
||||
|
||||
// if larger than 260 sec, increase by 5%
|
||||
if ($result > 260) {
|
||||
$dif = bcmul($current['difficulty'], 1.05);
|
||||
} elseif ($result < 220) {
|
||||
// if lower, decrease by 5%
|
||||
$dif = bcmul($current['difficulty'], 0.95);
|
||||
} else {
|
||||
// keep current difficulty
|
||||
$dif = $current['difficulty'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (strpos($dif, '.') !== false) {
|
||||
$dif = substr($dif, 0, strpos($dif, '.'));
|
||||
}
|
||||
@@ -183,7 +319,7 @@ class Block
|
||||
if ($dif > 9223372036854775800) {
|
||||
$dif = 9223372036854775800;
|
||||
}
|
||||
|
||||
_log("Difficulty: $dif", 3);
|
||||
return $dif;
|
||||
}
|
||||
|
||||
@@ -233,8 +369,13 @@ class Block
|
||||
return false;
|
||||
}
|
||||
$acc = new Account();
|
||||
// generator's public key must be valid
|
||||
|
||||
if($data['date']>time()+30){
|
||||
_log("Future block - $data[date] $data[public_key]",2);
|
||||
return false;
|
||||
}
|
||||
|
||||
// generator's public key must be valid
|
||||
if (!$acc->valid_key($data['public_key'])) {
|
||||
_log("Invalid public key - $data[public_key]");
|
||||
return false;
|
||||
@@ -247,7 +388,7 @@ class Block
|
||||
}
|
||||
|
||||
//check the argon hash and the nonce to produce a valid block
|
||||
if (!$this->mine($data['public_key'], $data['nonce'], $data['argon'])) {
|
||||
if (!$this->mine($data['public_key'], $data['nonce'], $data['argon'], $data['difficulty'], 0, 0, $data['date'])) {
|
||||
_log("Mine check failed");
|
||||
return false;
|
||||
}
|
||||
@@ -290,6 +431,25 @@ class Block
|
||||
|
||||
// reward transaction and signature
|
||||
$reward = $this->reward($height, $data);
|
||||
|
||||
if($height>=80460){
|
||||
//reward the masternode
|
||||
global $db;
|
||||
$mn_winner=$db->single(
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
||||
[":current"=>$height, ":start"=>$height-360]
|
||||
);
|
||||
_log("MN Winner: $mn_winner",2);
|
||||
if($mn_winner!==false){
|
||||
$mn_reward=round(0.33*$reward,8);
|
||||
$reward=round($reward-$mn_reward,8);
|
||||
$reward=number_format($reward,8,".","");
|
||||
$mn_reward=number_format($mn_reward,8,".","");
|
||||
_log("MN Reward: $mn_reward",2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$msg = '';
|
||||
$transaction = [
|
||||
"src" => $generator,
|
||||
@@ -323,34 +483,185 @@ class Block
|
||||
return true;
|
||||
}
|
||||
|
||||
public function blacklist_masternodes()
|
||||
{
|
||||
global $db;
|
||||
_log("Checking if there are masternodes to be blacklisted", 2);
|
||||
$current = $this->current();
|
||||
if (($current['height']-1)%3!=2) {
|
||||
_log("bad height");
|
||||
return;
|
||||
}
|
||||
$last=$this->get($current['height']-1);
|
||||
$total_time=$current['date']-$last['date'];
|
||||
_log("blacklist total time $total_time");
|
||||
if ($total_time<=600&&$current['height']<80500) {
|
||||
return;
|
||||
}
|
||||
if($current['height']>=80500&&$total_time<360){
|
||||
return false;
|
||||
}
|
||||
if($current['height']>=80500){
|
||||
$total_time-=360;
|
||||
$tem=floor($total_time/120)+1;
|
||||
if($tem>5) $tem=5;
|
||||
} else {
|
||||
$tem=floor($total_time/600);
|
||||
}
|
||||
_log("We have masternodes to blacklist - $tem", 2);
|
||||
$ban=$db->run(
|
||||
"SELECT public_key, blacklist, fails, last_won FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 0,$tem",
|
||||
[":current"=>$last['height'], ":start"=>$last['height']-360]
|
||||
);
|
||||
_log(json_encode($ban));
|
||||
$i=0;
|
||||
foreach ($ban as $b) {
|
||||
$this->masternode_log($b['public_key'], $current['height'], $current['id']);
|
||||
_log("Blacklisting masternode - $i $b[public_key]", 2);
|
||||
$btime=10;
|
||||
if($current['height']>83000) $btime=360;
|
||||
$db->run("UPDATE masternode SET fails=fails+1, blacklist=:blacklist WHERE public_key=:public_key", [":public_key"=>$b['public_key'], ":blacklist"=> $current['height']+(($b['fails']+1)*$btime)]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the arguments are good for mining a specific block
|
||||
public function mine($public_key, $nonce, $argon, $difficulty = 0, $current_id = 0, $current_height = 0)
|
||||
public function mine($public_key, $nonce, $argon, $difficulty = 0, $current_id = 0, $current_height = 0, $time=0)
|
||||
{
|
||||
global $_config;
|
||||
|
||||
// invalid future blocks
|
||||
if($time>time()+30){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// if no id is specified, we use the current
|
||||
if ($current_id === 0) {
|
||||
if ($current_id === 0 || $current_height === 0) {
|
||||
$current = $this->current();
|
||||
$current_id = $current['id'];
|
||||
$current_height = $current['height'];
|
||||
}
|
||||
_log("Block Timestamp $time", 3);
|
||||
if ($time == 0) {
|
||||
$time=time();
|
||||
}
|
||||
// get the current difficulty if empty
|
||||
if ($difficulty === 0) {
|
||||
$difficulty = $this->difficulty();
|
||||
}
|
||||
|
||||
if (empty($public_key)) {
|
||||
_log("Empty public key", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($current_height<80000) {
|
||||
|
||||
// the argon parameters are hardcoded to avoid any exploits
|
||||
if ($current_height > 10800) {
|
||||
_log("Block below 80000 but after 10800, using 512MB argon", 2);
|
||||
$argon = '$argon2i$v=19$m=524288,t=1,p=1'.$argon; //10800 block hard fork - resistance against gpu
|
||||
} else {
|
||||
_log("Block below 10800, using 16MB argon", 2);
|
||||
$argon = '$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
}
|
||||
|
||||
} elseif($current_height>=80460){
|
||||
if ($current_height%2==0) {
|
||||
// cpu mining
|
||||
_log("CPU Mining - $current_height", 2);
|
||||
$argon = '$argon2i$v=19$m=524288,t=1,p=1'.$argon;
|
||||
} else {
|
||||
// gpu mining
|
||||
_log("GPU Mining - $current_height", 2);
|
||||
$argon = '$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
}
|
||||
|
||||
} else {
|
||||
_log("Block > 80000 - $current_height", 2);
|
||||
if ($current_height%3==0) {
|
||||
// cpu mining
|
||||
_log("CPU Mining - $current_height", 2);
|
||||
$argon = '$argon2i$v=19$m=524288,t=1,p=1'.$argon;
|
||||
} elseif ($current_height%3==1) {
|
||||
// gpu mining
|
||||
_log("GPU Mining - $current_height", 2);
|
||||
$argon = '$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
} else {
|
||||
_log("Masternode Mining - $current_height", 2);
|
||||
// masternode
|
||||
global $db;
|
||||
|
||||
// fake time
|
||||
if ($time>time()) {
|
||||
_log("Masternode block in the future - $time", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
// selecting the masternode winner in order
|
||||
$winner=$db->single(
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
||||
[":current"=>$current_height, ":start"=>$current_height-360]
|
||||
);
|
||||
|
||||
// if there are no active masternodes, give the block to gpu
|
||||
if ($winner===false) {
|
||||
_log("No active masternodes, reverting to gpu", 1);
|
||||
$argon = '$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
} else {
|
||||
_log("The first masternode winner should be $winner", 1);
|
||||
// 4 mins need to pass since last block
|
||||
$last_time=$db->single("SELECT `date` FROM blocks WHERE height=:height", [":height"=>$current_height]);
|
||||
if ($time-$last_time<240&&$_config['testnet']==false) {
|
||||
_log("4 minutes have not passed since the last block - $time", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($public_key==$winner) {
|
||||
return true;
|
||||
}
|
||||
// if 10 mins have passed, try to give the block to the next masternode and do this every 10mins
|
||||
_log("Last block time: $last_time, difference: ".($time-$last_time), 3);
|
||||
if (($time-$last_time>600&&$current_height<80500)||($time-$last_time>360&&$current_height>=80500)) {
|
||||
_log("Current public_key $public_key", 3);
|
||||
if($current_height>=80500){
|
||||
$total_time=$time-$last_time;
|
||||
$total_time-=360;
|
||||
$tem=floor($total_time/120)+1;
|
||||
|
||||
} else {
|
||||
$tem=floor(($time-$last_time)/600);
|
||||
}
|
||||
$winner=$db->single(
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT $tem,1",
|
||||
[":current"=>$current_height, ":start"=>$current_height-360]
|
||||
);
|
||||
_log("Moving to the next masternode - $tem - $winner", 1);
|
||||
// if all masternodes are dead, give the block to gpu
|
||||
if ($winner===false||($tem>=5&&$current_height>=80500)) {
|
||||
_log("All masternodes failed, giving the block to gpu", 1);
|
||||
$argon = '$argon2i$v=19$m=16384,t=1,p=1'.$argon;
|
||||
} elseif ($winner==$public_key) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
_log("A different masternode should win this block $public_key - $winner", 2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the hash base for agon
|
||||
$base = "$public_key-$nonce-".$current_id."-$difficulty";
|
||||
|
||||
|
||||
// check argon's hash validity
|
||||
if (!password_verify($base, $argon)) {
|
||||
_log("Argon verify failed - $base - $argon", 2);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -390,7 +701,7 @@ class Block
|
||||
|
||||
|
||||
// parse the block transactions
|
||||
public function parse_block($block, $height, $data, $test = true)
|
||||
public function parse_block($block, $height, $data, $test = true, $bootstrapping=false)
|
||||
{
|
||||
global $db;
|
||||
// data must be array
|
||||
@@ -411,16 +722,22 @@ class Block
|
||||
}
|
||||
|
||||
$balance = [];
|
||||
$mns = [];
|
||||
|
||||
foreach ($data as &$x) {
|
||||
// get the sender's account if empty
|
||||
if (empty($x['src'])) {
|
||||
$x['src'] = $acc->get_address($x['public_key']);
|
||||
}
|
||||
|
||||
if (!$bootstrapping) {
|
||||
//validate the transaction
|
||||
if (!$trx->check($x, $height)) {
|
||||
return false;
|
||||
}
|
||||
if ($x['version']>=100&&$x['version']<110) {
|
||||
$mns[] = $x['public_key'];
|
||||
}
|
||||
|
||||
|
||||
// prepare total balance
|
||||
$balance[$x['src']] += $x['val'] + $x['fee'];
|
||||
@@ -430,7 +747,14 @@ class Block
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//only a single masternode transaction per block for any masternode
|
||||
if (count($mns) != count(array_unique($mns))) {
|
||||
_log("Too many masternode transactions", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$bootstrapping) {
|
||||
// check if the account has enough balance to perform the transaction
|
||||
foreach ($balance as $id => $bal) {
|
||||
$res = $db->single(
|
||||
@@ -441,7 +765,7 @@ class Block
|
||||
return false; // not enough balance for the transactions
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// if the test argument is false, add the transactions to the blockchain
|
||||
if ($test == false) {
|
||||
foreach ($data as $d) {
|
||||
@@ -511,7 +835,7 @@ class Block
|
||||
return;
|
||||
}
|
||||
$db->beginTransaction();
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE, masternode WRITE");
|
||||
foreach ($r as $x) {
|
||||
$res = $trx->reverse($x['id']);
|
||||
if ($res === false) {
|
||||
@@ -536,7 +860,6 @@ class Block
|
||||
// delete specific block
|
||||
public function delete_id($id)
|
||||
{
|
||||
|
||||
global $db;
|
||||
$trx = new Transaction();
|
||||
|
||||
@@ -574,7 +897,6 @@ class Block
|
||||
// sign a new block, used when mining
|
||||
public function sign($generator, $height, $date, $nonce, $data, $key, $difficulty, $argon)
|
||||
{
|
||||
|
||||
$json = json_encode($data);
|
||||
$info = "{$generator}-{$height}-{$date}-{$nonce}-{$json}-{$difficulty}-{$argon}";
|
||||
|
||||
@@ -612,6 +934,10 @@ class Block
|
||||
$r = $db->run("SELECT * FROM transactions WHERE version>0 AND block=:block", [":block" => $block['id']]);
|
||||
$transactions = [];
|
||||
foreach ($r as $x) {
|
||||
if ($x['version']>110) {
|
||||
//internal transactions
|
||||
continue;
|
||||
}
|
||||
$trans = [
|
||||
"id" => $x['id'],
|
||||
"dst" => $x['dst'],
|
||||
@@ -631,7 +957,7 @@ class Block
|
||||
|
||||
// the reward transaction always has version 0
|
||||
$gen = $db->row(
|
||||
"SELECT public_key, signature FROM transactions WHERE version=0 AND block=:block",
|
||||
"SELECT public_key, signature FROM transactions WHERE version=0 AND block=:block AND message=''",
|
||||
[":block" => $block['id']]
|
||||
);
|
||||
$block['public_key'] = $gen['public_key'];
|
||||
|
||||
114
include/config-sample.inc.php
Executable file
114
include/config-sample.inc.php
Executable file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// The database DSN
|
||||
$_config['db_connect'] = 'mysql:host=localhost;dbname=ENTER-DB-NAME';
|
||||
|
||||
// The database username
|
||||
$_config['db_user'] = 'ENTER-DB-USER';
|
||||
|
||||
// The database password
|
||||
$_config['db_pass'] = 'ENTER-DB-PASS';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| General Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Maximum number of connected peers
|
||||
$_config['max_peers'] = 30;
|
||||
|
||||
// Enable testnet mode for development
|
||||
$_config['testnet'] = false;
|
||||
|
||||
// To avoid any problems if other clones are made
|
||||
$_config['coin'] = 'arionum';
|
||||
|
||||
// Allow others to connect to the node api (if set to false, only the below 'allowed_hosts' are allowed)
|
||||
$_config['public_api'] = true;
|
||||
|
||||
// Hosts that are allowed to mine on this node
|
||||
$_config['allowed_hosts'] = [
|
||||
'127.0.0.1',
|
||||
];
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Peer Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// The number of peers to send each new transaction to
|
||||
$_config['transaction_propagation_peers'] = 5;
|
||||
|
||||
// How many new peers to check from each peer
|
||||
$_config['max_test_peers'] = 5;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mempool Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// The maximum transactions to accept from a single peer
|
||||
$_config['peer_max_mempool'] = 100;
|
||||
|
||||
// The maximum number of mempool transactions to be rebroadcasted
|
||||
$_config['max_mempool_rebroadcast'] = 5000;
|
||||
|
||||
// The number of blocks between rebroadcasting transactions
|
||||
$_config['sanity_rebroadcast_height'] = 30;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanity Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Recheck the last blocks on sanity
|
||||
$_config['sanity_recheck_blocks'] = 10;
|
||||
|
||||
// The interval to run the sanity in seconds
|
||||
$_config['sanity_interval'] = 900;
|
||||
|
||||
// Enable setting a new hostname (should be used only if you want to change the hostname)
|
||||
$_config['allow_hostname_change'] = false;
|
||||
|
||||
// Rebroadcast local transactions when running sanity
|
||||
$_config['sanity_rebroadcast_locals'] = true;
|
||||
|
||||
// Get more peers?
|
||||
$_config['get_more_peers']=true;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Logging Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Enable log output to the specified file
|
||||
$_config['enable_logging'] = false;
|
||||
|
||||
// The specified file to write to (this should not be publicly visible)
|
||||
$_config['log_file'] = '/var/log/aro.log';
|
||||
|
||||
// Log verbosity (default 0, maximum 3)
|
||||
$_config['log_verbosity'] = 0;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Masternode Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Enable this node as a masternode
|
||||
$_config['masternode'] = false;
|
||||
|
||||
// The public key for the masternode
|
||||
$_config['masternode_public_key'] = '';
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
// Database connection
|
||||
$_config['db_connect']="mysql:host=localhost;dbname=ENTER-DB-NAME";
|
||||
$_config['db_user']="ENTER-DB-USER";
|
||||
$_config['db_pass']="ENTER-DB-PASS";
|
||||
|
||||
// Maximum number of connected peers
|
||||
$_config['max_peers']=30;
|
||||
// Testnet, used for development
|
||||
$_config['testnet']=false;
|
||||
// To avoid any problems if other clones are made
|
||||
$_config['coin']="arionum";
|
||||
// maximum transactions accepted from a single peer
|
||||
$_config['peer_max_mempool']=100;
|
||||
// maximum mempool transactions to be rebroadcasted
|
||||
$_config['max_mempool_rebroadcast']=5000;
|
||||
// after how many blocks should the transactions be rebroadcasted
|
||||
$_config['sanity_rebroadcast_height']=30;
|
||||
// each new received transaction is sent to X peers
|
||||
$_config['transaction_propagation_peers']=5;
|
||||
// how many new peers to check from each peer.
|
||||
$_config['max_test_peers']=5;
|
||||
// recheck the last blocks on sanity
|
||||
$_config['sanity_recheck_blocks']=10;
|
||||
// allow others to connect to node api. If set to false, only allowed_hosts are allowed
|
||||
$_config['public_api']=true;
|
||||
// hosts allowed to mine on this node
|
||||
$_config['allowed_hosts']=array("127.0.0.1");
|
||||
// sanity is run every X seconds
|
||||
$_config['sanity_interval']=900;
|
||||
// accept the setting of new hostnames / should be used only if you want to change the hostname
|
||||
$_config['allow_hostname_change']=false;
|
||||
// rebroadcast local transactions on each sanity
|
||||
$_config['sanity_rebroadcast_locals']=true;
|
||||
// write logs to file
|
||||
$_config['enable_logging']=false;
|
||||
// log file, should not be publicly viewable
|
||||
$_config['log_file']="/var/log/aro.log";
|
||||
@@ -31,6 +31,7 @@ class DB extends PDO
|
||||
|
||||
private function debug()
|
||||
{
|
||||
global $_config;
|
||||
if (!$this->debugger) {
|
||||
return;
|
||||
}
|
||||
@@ -56,9 +57,9 @@ class DB extends PDO
|
||||
$msg .= "\n\n$key:\n$val";
|
||||
}
|
||||
|
||||
if ($this->debugger) {
|
||||
echo nl2br($msg);
|
||||
}
|
||||
|
||||
_log($msg);
|
||||
|
||||
}
|
||||
|
||||
private function cleanup($bind, $sql = "")
|
||||
|
||||
@@ -37,7 +37,7 @@ function api_echo($data)
|
||||
}
|
||||
|
||||
// log function, shows only in cli atm
|
||||
function _log($data)
|
||||
function _log($data, $verbosity = 0)
|
||||
{
|
||||
$date = date("[Y-m-d H:i:s]");
|
||||
$trace = debug_backtrace();
|
||||
@@ -57,7 +57,7 @@ function _log($data)
|
||||
echo $res;
|
||||
}
|
||||
global $_config;
|
||||
if ($_config['enable_logging'] == true) {
|
||||
if ($_config['enable_logging'] == true && $_config['log_verbosity'] >= $verbosity) {
|
||||
@file_put_contents($_config['log_file'], $res, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
// ARO version
|
||||
define("VERSION", "0.3.0");
|
||||
define("VERSION", "0.4.2");
|
||||
// Amsterdam timezone by default, should probably be moved to config
|
||||
date_default_timezone_set("Europe/Amsterdam");
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
//error_reporting(E_ALL & ~E_NOTICE);
|
||||
error_reporting(0);
|
||||
@@ -24,7 +24,7 @@ if ($_config['db_pass'] == "ENTER-DB-PASS") {
|
||||
die("Please update your config file and set your db password");
|
||||
}
|
||||
// initial DB connection
|
||||
$db = new DB($_config['db_connect'], $_config['db_user'], $_config['db_pass'], 0);
|
||||
$db = new DB($_config['db_connect'], $_config['db_user'], $_config['db_pass'], $_config['enable_logging']);
|
||||
if (!$db) {
|
||||
die("Could not connect to the DB backend.");
|
||||
}
|
||||
@@ -63,6 +63,14 @@ if ($_config['maintenance'] == 1) {
|
||||
|
||||
// update the db schema, on every git pull or initial install
|
||||
if (file_exists("tmp/db-update")) {
|
||||
//checking if the server has at least 2GB of ram
|
||||
$ram=file_get_contents("/proc/meminfo");
|
||||
$ramz=explode("MemTotal:",$ram);
|
||||
$ramb=explode("kB",$ramz[1]);
|
||||
$ram=intval(trim($ramb[0]));
|
||||
if($ram<1700000) {
|
||||
die("The node requires at least 2 GB of RAM");
|
||||
}
|
||||
$res = unlink("tmp/db-update");
|
||||
if ($res) {
|
||||
echo "Updating db schema! Please refresh!\n";
|
||||
|
||||
@@ -140,6 +140,33 @@ if ($dbversion == 6) {
|
||||
$db->run("ALTER TABLE `accounts` ADD `alias` VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL AFTER `balance`; ");
|
||||
$dbversion++;
|
||||
}
|
||||
if ($dbversion == 7) {
|
||||
$db->run("ALTER TABLE `accounts` ADD INDEX(`alias`); ");
|
||||
$db->run("ALTER TABLE `transactions` ADD KEY `dst` (`dst`), ADD KEY `height` (`height`), ADD KEY `public_key` (`public_key`);");
|
||||
$dbversion++;
|
||||
}
|
||||
if ($dbversion == 8) {
|
||||
$db->run("CREATE TABLE `masternode` (
|
||||
`public_key` varchar(128) COLLATE utf8mb4_bin NOT NULL,
|
||||
`height` int(11) NOT NULL,
|
||||
`ip` varchar(16) COLLATE utf8mb4_bin NOT NULL,
|
||||
`last_won` int(11) NOT NULL DEFAULT '0',
|
||||
`blacklist` int(11) NOT NULL DEFAULT '0',
|
||||
`fails` int(11) NOT NULL DEFAULT '0',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");
|
||||
|
||||
$db->run("ALTER TABLE `masternode`
|
||||
ADD PRIMARY KEY (`public_key`),
|
||||
ADD KEY `last_won` (`last_won`),
|
||||
ADD KEY `status` (`status`),
|
||||
ADD KEY `blacklist` (`blacklist`),
|
||||
ADD KEY `height` (`height`);");
|
||||
$dbversion++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update the db version to the latest one
|
||||
if ($dbversion != $_config['dbversion']) {
|
||||
$db->run("UPDATE config SET val=:val WHERE cfg='dbversion'", [":val" => $dbversion]);
|
||||
|
||||
@@ -7,16 +7,27 @@ class Transaction
|
||||
{
|
||||
global $db;
|
||||
$acc = new Account();
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:block", [":block" => $block]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:block ORDER by `version` ASC", [":block" => $block]);
|
||||
foreach ($r as $x) {
|
||||
if (empty($x['src'])) {
|
||||
$x['src'] = $acc->get_address($x['public_key']);
|
||||
}
|
||||
if ($x['version'] == 2) {
|
||||
// payment sent to alias
|
||||
$db->run(
|
||||
"UPDATE accounts SET balance=balance-:val WHERE alias=:alias",
|
||||
[":alias" => $x['dst'], ":val" => $x['val']]
|
||||
);
|
||||
} else {
|
||||
// other type of transactions
|
||||
|
||||
if($x['version']!=100) { $db->run(
|
||||
"UPDATE accounts SET balance=balance-:val WHERE id=:id",
|
||||
[":id" => $x['dst'], ":val" => $x['val']]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
// on version 0 / reward transaction, don't credit anyone
|
||||
if ($x['version'] > 0) {
|
||||
$db->run(
|
||||
@@ -24,9 +35,57 @@ class Transaction
|
||||
[":id" => $x['src'], ":val" => $x['val'] + $x['fee']]
|
||||
);
|
||||
}
|
||||
// removing the alias if the alias transaction is reversed
|
||||
if ($x['version']==3) {
|
||||
$db->run(
|
||||
"UPDATE accounts SET alias=NULL WHERE id=:id",
|
||||
[":id" => $x['src']]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if ($x['version']>=100&&$x['version']<110&&$x['height']>=80000) {
|
||||
if ($x['version']==100) {
|
||||
$db->run("DELETE FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==101) {
|
||||
$db->run(
|
||||
"UPDATE masternode SET status=1 WHERE public_key=:public_key",
|
||||
[':public_key'=>$x['public_key']]
|
||||
);
|
||||
} elseif ($x['version']==102) {
|
||||
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==103) {
|
||||
$mnt=$db->row("SELECT height, `message` FROM transactions WHERE version=100 AND public_key=:public_key ORDER by height DESC LIMIT 1", [":public_key"=>$x['public_key']]);
|
||||
$vers=$db->single(
|
||||
"SELECT `version` FROM transactions WHERE (version=101 or version=102) AND public_key=:public_key AND height>:height ORDER by height DESC LIMIT 1",
|
||||
[":public_key"=>$x['public_key'],":height"=>$mnt['height']]
|
||||
);
|
||||
|
||||
$status=1;
|
||||
|
||||
if ($vers==101) {
|
||||
$status=0;
|
||||
}
|
||||
|
||||
$db->run(
|
||||
"INSERT into masternode SET `public_key`=:public_key, `height`=:height, `ip`=:ip, `status`=:status",
|
||||
[":public_key"=>$x['public_key'], ":height"=>$mnt['height'], ":ip"=>$mnt['message'], ":status"=>$status]
|
||||
);
|
||||
$db->run("UPDATE accounts SET balance=balance-100000 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
}
|
||||
}
|
||||
// internal masternode history
|
||||
if ($x['version']==111) {
|
||||
$m=explode(",", $x['message']);
|
||||
|
||||
$db->run(
|
||||
"UPDATE masternode SET fails=:fails, blacklist=:blacklist, last_won=:last_won WHERE public_key=:public_key",
|
||||
[":public_key"=>$x['public_key'], ":blacklist"=> $m[0], ":fails"=>$m[2], ":last_won"=>$m[1]]
|
||||
);
|
||||
}
|
||||
|
||||
// add the transactions to mempool
|
||||
if ($x['version'] > 0) {
|
||||
if ($x['version'] > 0 && $x['version']<=110) {
|
||||
$this->add_mempool($x);
|
||||
}
|
||||
$res = $db->run("DELETE FROM transactions WHERE id=:id", [":id" => $x['id']]);
|
||||
@@ -124,6 +183,9 @@ class Transaction
|
||||
{
|
||||
global $db;
|
||||
$block = new Block();
|
||||
if ($x['version']>110) {
|
||||
return true;
|
||||
}
|
||||
$current = $block->current();
|
||||
$height = $current['height'];
|
||||
$x['id'] = san($x['id']);
|
||||
@@ -141,6 +203,16 @@ class Transaction
|
||||
":date" => $x['date'],
|
||||
":message" => $x['message'],
|
||||
];
|
||||
|
||||
//only a single masternode command of same type, per block
|
||||
if ($x['version']>=100&&$x['version']<110) {
|
||||
$check=$db->single("SELECT COUNT(1) FROM mempool WHERE public_key=:public_key", [":public_key"=>$x['public_key']]);
|
||||
if ($check!=0) {
|
||||
_log("Masternode transaction already in mempool", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$db->run(
|
||||
"INSERT into mempool SET peer=:peer, id=:id, public_key=:public_key, height=:height, src=:src, dst=:dst, val=:val, fee=:fee, signature=:signature, version=:version, message=:message, `date`=:date",
|
||||
$bind
|
||||
@@ -154,7 +226,9 @@ class Transaction
|
||||
global $db;
|
||||
$acc = new Account();
|
||||
$acc->add($x['public_key'], $block);
|
||||
if ($x['version']==1) {
|
||||
$acc->add_id($x['dst'], $block);
|
||||
}
|
||||
$x['id'] = san($x['id']);
|
||||
$bind = [
|
||||
":id" => $x['id'],
|
||||
@@ -176,7 +250,21 @@ class Transaction
|
||||
if ($res != 1) {
|
||||
return false;
|
||||
}
|
||||
if ($x['version'] == 2&&$height>=80000) {
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE alias=:alias", [":alias" => $x['dst'], ":val" => $x['val']]);
|
||||
} elseif ($x['version']==100&&$height>=80000) {
|
||||
//master node deposit
|
||||
} elseif ($x['version']==103&&$height>=80000) {
|
||||
$blk=new Block();
|
||||
$blk->masternode_log($x['public_key'],$height,$block);
|
||||
|
||||
//master node withdrawal
|
||||
} else {
|
||||
$db->run("UPDATE accounts SET balance=balance+:val WHERE id=:id", [":id" => $x['dst'], ":val" => $x['val']]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// no debit when the transaction is reward
|
||||
if ($x['version'] > 0) {
|
||||
$db->run(
|
||||
@@ -184,6 +272,36 @@ class Transaction
|
||||
[":id" => $x['src'], ":val" => $x['val'], ":fee" => $x['fee']]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// set the alias
|
||||
if ($x['version']==3&&$height>=80000) {
|
||||
$db->run(
|
||||
"UPDATE accounts SET alias=:alias WHERE id=:id",
|
||||
[":id" => $x['src'], ":alias"=>$x['message']]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if ($x['version']>=100&&$x['version']<110&&$height>=80000) {
|
||||
$message=$x['message'];
|
||||
$message=preg_replace("/[^0-9\.]/", "", $message);
|
||||
if ($x['version']==100) {
|
||||
$db->run("INSERT into masternode SET `public_key`=:public_key, `height`=:height, `ip`=:ip, `status`=1", [":public_key"=>$x['public_key'], ":height"=>$height, ":ip"=>$message]);
|
||||
} else {
|
||||
if ($x['version']==101) {
|
||||
$db->run("UPDATE masternode SET status=0 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==102) {
|
||||
$db->run("UPDATE masternode SET status=1 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
} elseif ($x['version']==103) {
|
||||
$db->run("DELETE FROM masternode WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
$db->run("UPDATE accounts SET balance=balance+100000 WHERE public_key=:public_key", [':public_key'=>$x['public_key']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$db->run("DELETE FROM mempool WHERE id=:id", [":id" => $x['id']]);
|
||||
return true;
|
||||
}
|
||||
@@ -208,15 +326,25 @@ class Transaction
|
||||
$acc = new Account();
|
||||
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
||||
|
||||
// hard fork at 80000 to implement alias, new mining system, assets
|
||||
// if($x['version']>1 && $height<80000){
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// internal transactions
|
||||
if($x['version']>110){
|
||||
return false;
|
||||
}
|
||||
|
||||
// the value must be >=0
|
||||
if ($x['val'] < 0) {
|
||||
_log("$x[id] - Value below 0");
|
||||
_log("$x[id] - Value below 0", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
// the fee must be >=0
|
||||
if ($x['fee'] < 0) {
|
||||
_log("$x[id] - Fee below 0");
|
||||
_log("$x[id] - Fee below 0", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -226,46 +354,115 @@ class Transaction
|
||||
if ($fee < 0.00000001) {
|
||||
$fee = 0.00000001;
|
||||
}
|
||||
//alias fee
|
||||
if ($x['version']==3&&$height>=80000) {
|
||||
$fee=10;
|
||||
if (!$acc->free_alias($x['message'])) {
|
||||
_log("Alias not free", 3);
|
||||
return false;
|
||||
}
|
||||
// alias can only be set once per account
|
||||
if ($acc->has_alias($x['public_key'])) {
|
||||
_log("The account already has an alias", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//masternode transactions
|
||||
|
||||
if ($x['version']>=100&&$x['version']<110&&$height>=80000) {
|
||||
if ($x['version']==100) {
|
||||
$message=$x['message'];
|
||||
$message=preg_replace("/[^0-9\.]/", "", $message);
|
||||
if (!filter_var($message, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
||||
_log("The Masternode IP is invalid", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($x['version']==100&&$x['val']!=100000) {
|
||||
_log("The masternode transaction is not 100k", 3);
|
||||
return false;
|
||||
} elseif ($x['version']!=100) {
|
||||
$mn=$acc->get_masternode($x['public_key']);
|
||||
|
||||
if (!$mn) {
|
||||
_log("The masternode does not exist", 3);
|
||||
return false;
|
||||
}
|
||||
if ($x['version']==101&&$mn['status']!=1) {
|
||||
_log("The masternode does is not running", 3);
|
||||
return false;
|
||||
} elseif ($x['version']==102 && $mn['status']!=0) {
|
||||
_log("The masternode is not paused", 3);
|
||||
return false;
|
||||
} elseif ($x['version']==103) {
|
||||
if ($mn['status']!=0) {
|
||||
_log("The masternode is not paused", 3);
|
||||
return false;
|
||||
} elseif ($height-$mn['last_won']<10800) { //10800
|
||||
_log("The masternode last won block is less than 10800 blocks", 3);
|
||||
return false;
|
||||
} elseif ($height-$mn['height']<32400) { //32400
|
||||
_log("The masternode start height is less than 32400 blocks! $height - $mn[height]", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// max fee after block 10800 is 10
|
||||
if ($height > 10800 && $fee > 10) {
|
||||
$fee = 10; //10800
|
||||
}
|
||||
// added fee does not match
|
||||
if ($fee != $x['fee']) {
|
||||
_log("$x[id] - Fee not 0.25%");
|
||||
_log("$x[id] - Fee not 0.25%", 3);
|
||||
_log(json_encode($x), 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($x['version']==1) {
|
||||
// invalid destination address
|
||||
if (!$acc->valid($x['dst'])) {
|
||||
_log("$x[id] - Invalid destination address");
|
||||
_log("$x[id] - Invalid destination address", 3);
|
||||
return false;
|
||||
}
|
||||
} elseif ($x['version']==2&&$height>=80000) {
|
||||
if (!$acc->valid_alias($x['dst'])) {
|
||||
_log("$x[id] - Invalid destination alias", 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// reward transactions are not added via this function
|
||||
if ($x['version'] < 1) {
|
||||
_log("$x[id] - Invalid version <1");
|
||||
_log("$x[id] - Invalid version <1", 3);
|
||||
return false;
|
||||
}
|
||||
//if($x['version']>1) { _log("$x[id] - Invalid version >1"); return false; }
|
||||
|
||||
// public key must be at least 15 chars / probably should be replaced with the validator function
|
||||
if (strlen($x['public_key']) < 15) {
|
||||
_log("$x[id] - Invalid public key size");
|
||||
_log("$x[id] - Invalid public key size", 3);
|
||||
return false;
|
||||
}
|
||||
// no transactions before the genesis
|
||||
if ($x['date'] < 1511725068) {
|
||||
_log("$x[id] - Date before genesis");
|
||||
_log("$x[id] - Date before genesis", 3);
|
||||
return false;
|
||||
}
|
||||
// no future transactions
|
||||
if ($x['date'] > time() + 86400) {
|
||||
_log("$x[id] - Date in the future");
|
||||
_log("$x[id] - Date in the future", 3);
|
||||
return false;
|
||||
}
|
||||
// prevent the resending of broken base58 transactions
|
||||
if ($height > 16900 && $x['date'] < 1519327780) {
|
||||
_log("$x[id] - Broken base58 transaction", 3);
|
||||
return false;
|
||||
}
|
||||
$id = $this->hash($x);
|
||||
@@ -284,7 +481,7 @@ class Transaction
|
||||
|
||||
//verify the ecdsa signature
|
||||
if (!$acc->check_signature($info, $x['signature'], $x['public_key'])) {
|
||||
_log("$x[id] - Invalid signature");
|
||||
_log("$x[id] - Invalid signature - $info");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -295,6 +492,7 @@ class Transaction
|
||||
public function sign($x, $private_key)
|
||||
{
|
||||
$info = $x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
||||
|
||||
$signature = ec_sign($info, $private_key);
|
||||
|
||||
return $signature;
|
||||
@@ -339,7 +537,7 @@ class Transaction
|
||||
|
||||
if ($x['version'] == 0) {
|
||||
$trans['type'] = "mining";
|
||||
} elseif ($x['version'] == 1) {
|
||||
} elseif ($x['version'] == 1 || $x['version'] == 2) {
|
||||
if ($x['dst'] == $id) {
|
||||
$trans['type'] = "credit";
|
||||
} else {
|
||||
@@ -371,6 +569,9 @@ class Transaction
|
||||
}
|
||||
$res = [];
|
||||
foreach ($r as $x) {
|
||||
if ($x['version']>110) {
|
||||
continue; //internal transactions
|
||||
}
|
||||
$trans = [
|
||||
"block" => $x['block'],
|
||||
"height" => $x['height'],
|
||||
@@ -389,7 +590,7 @@ class Transaction
|
||||
|
||||
if ($x['version'] == 0) {
|
||||
$trans['type'] = "mining";
|
||||
} elseif ($x['version'] == 1) {
|
||||
} elseif ($x['version'] == 1||$x['version'] == 2) {
|
||||
if ($x['dst'] == $id) {
|
||||
$trans['type'] = "credit";
|
||||
} else {
|
||||
|
||||
297
index.php
297
index.php
@@ -24,9 +24,300 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
require_once("include/init.inc.php");
|
||||
require_once __DIR__.'/include/init.inc.php';
|
||||
$block = new Block();
|
||||
$current = $block->current();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Arionum Node</title>
|
||||
<style>
|
||||
.title:not(:last-child) {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
echo "<h3>Arionum Node</h3>";
|
||||
echo "System check complete.<br><br> Current block: $current[height]";
|
||||
body, h1, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
font-size: 16px;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
min-width: 300px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-moz-text-size-adjust: 100%;
|
||||
-ms-text-size-adjust: 100%;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
*, ::after, ::before {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #4a4a4a;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
span {
|
||||
font-style: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
strong {
|
||||
color: #363636;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.field.is-grouped {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.field.is-grouped > .control {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.field.is-grouped > .control:not(:last-child) {
|
||||
margin-bottom: 0;
|
||||
margin-right: .75rem;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline > .control:last-child, .field.is-grouped.is-grouped-multiline > .control:not(:last-child) {
|
||||
margin-bottom: .75rem;
|
||||
}
|
||||
|
||||
.field.is-grouped.is-grouped-multiline:last-child {
|
||||
margin-bottom: -.75rem;
|
||||
}
|
||||
|
||||
.control {
|
||||
font-size: 1rem;
|
||||
position: relative;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tags {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.tags .tag {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.tags .tag:not(:last-child) {
|
||||
margin-right: .5rem;
|
||||
}
|
||||
|
||||
.tags:last-child {
|
||||
margin-bottom: -.5rem;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag:not(:first-child) {
|
||||
border-bottom-left-radius: 0;
|
||||
border-top-left-radius: 0;
|
||||
}
|
||||
|
||||
.tags.has-addons .tag:not(:last-child) {
|
||||
border-bottom-right-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
|
||||
.tag:not(body) {
|
||||
align-items: center;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
color: #4a4a4a;
|
||||
display: inline-flex;
|
||||
font-size: .75rem;
|
||||
height: 2em;
|
||||
justify-content: center;
|
||||
line-height: 1.5;
|
||||
padding-left: .75em;
|
||||
padding-right: .75em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tag:not(body).is-light {
|
||||
background-color: #f5f5f5;
|
||||
color: #363636;
|
||||
}
|
||||
|
||||
.tag:not(body).is-info {
|
||||
background-color: #209cee;
|
||||
color: #fff;
|
||||
}
|
||||
.tag:not(body).is-danger {
|
||||
background-color: #f48f42;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.tag:not(body).is-success {
|
||||
background-color: #23d160;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.title {
|
||||
word-break: break-word;
|
||||
color: #363636;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.125;
|
||||
}
|
||||
|
||||
.hero {
|
||||
align-items: stretch;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.hero.is-dark {
|
||||
background-color: #363636;
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.hero.is-dark strong {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.hero.is-dark .title {
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.hero.is-fullheight .hero-body {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.hero.is-fullheight .hero-body > .container {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
.hero.is-fullheight {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.hero-body {
|
||||
flex-grow: 1;
|
||||
flex-shrink: 0;
|
||||
padding: 3rem 1.5rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #3273dc;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #363636;
|
||||
}
|
||||
|
||||
a.is-dark {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1088px) {
|
||||
|
||||
.container {
|
||||
max-width: 960px;
|
||||
width: 960px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1280px) {
|
||||
|
||||
.container {
|
||||
max-width: 1152px;
|
||||
width: 1152px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1472px) {
|
||||
|
||||
.container {
|
||||
max-width: 1344px;
|
||||
width: 1344px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section class="hero is-dark is-fullheight">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<h1 class="title">Arionum Node</h1>
|
||||
|
||||
<div class="field is-grouped is-grouped-multiline">
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-success">Current Block</strong>
|
||||
<span class="tag is-light"><?= $current['height']; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-danger">Version</strong>
|
||||
<span class="tag is-light"><?= VERSION; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<div class="tags has-addons">
|
||||
<strong class="tag is-info">Public API</strong>
|
||||
<span class="tag is-light"><?= ($_config['public_api']) ? 'yes' : 'no'; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<a class="tags is-dark" href="./doc/" target="_blank">
|
||||
<strong class="tag is-info">Documentation</strong>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
136
mine.php
136
mine.php
@@ -45,11 +45,49 @@ if ($q == "info") {
|
||||
$diff = $block->difficulty();
|
||||
$current = $block->current();
|
||||
|
||||
$current_height=$current['height'];
|
||||
$recommendation="mine";
|
||||
$argon_mem=16384;
|
||||
$argon_threads=4;
|
||||
$argon_time=4;
|
||||
if ($current_height<80000) {
|
||||
if ($current_height > 10800) {
|
||||
$argon_mem=524288;
|
||||
$argon_threads=1;
|
||||
$argon_time=1;
|
||||
}
|
||||
} elseif($current_height>=80460&&$current_height%2==0){
|
||||
$argon_mem=524288;
|
||||
$argon_threads=1;
|
||||
$argon_time=1;
|
||||
|
||||
|
||||
} else {
|
||||
if ($current_height%3==0) {
|
||||
$argon_mem=524288;
|
||||
$argon_threads=1;
|
||||
$argon_time=1;
|
||||
} elseif ($current_height%3==2) {
|
||||
global $db;
|
||||
$winner=$db->single(
|
||||
"SELECT public_key FROM masternode WHERE status=1 AND blacklist<:current AND height<:start ORDER by last_won ASC, public_key ASC LIMIT 1",
|
||||
[":current"=>$current_height, ":start"=>$current_height-360]
|
||||
);
|
||||
$recommendation="pause";
|
||||
if ($winner===false) {
|
||||
$recommendation="mine";
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = [
|
||||
"difficulty" => $diff,
|
||||
"block" => $current['id'],
|
||||
"height" => $current['height'],
|
||||
"testnet" => $_config['testnet'],
|
||||
"recommendation"=> $recommendation,
|
||||
"argon_mem" => $argon_mem,
|
||||
"argon_threads" => $argon_threads,
|
||||
"argon_time" => $argon_time,
|
||||
];
|
||||
api_echo($res);
|
||||
exit;
|
||||
@@ -78,6 +116,104 @@ if ($q == "info") {
|
||||
}
|
||||
}
|
||||
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 {
|
||||
api_err("invalid command");
|
||||
}
|
||||
|
||||
16
peer.php
16
peer.php
@@ -44,6 +44,14 @@ if ($q == "peer") {
|
||||
// sanitize the hostname
|
||||
$hostname = filter_var($data['hostname'], FILTER_SANITIZE_URL);
|
||||
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
$tpeer=str_replace(["https://","http://","//"], "", $hostname);
|
||||
foreach ($bad_peers as $bp) {
|
||||
if (strpos($tpeer, $bp)===0) {
|
||||
api_err("invalid-hostname");
|
||||
}
|
||||
}
|
||||
|
||||
if (!filter_var($hostname, FILTER_VALIDATE_URL)) {
|
||||
api_err("invalid-hostname");
|
||||
}
|
||||
@@ -166,17 +174,14 @@ if ($q == "peer") {
|
||||
if ($current['height'] == $data['height'] && $current['id'] != $data['id']) {
|
||||
// different forks, same height
|
||||
$accept_new = false;
|
||||
if ($current['transactions'] < $data['transactions']) {
|
||||
// accept the one with most transactions
|
||||
$accept_new = true;
|
||||
} elseif ($current['transactions'] == $data['transactions']) {
|
||||
|
||||
// convert the first 12 characters from hex to decimal and the block with the largest number wins
|
||||
$no1 = hexdec(substr(coin2hex($current['id']), 0, 12));
|
||||
$no2 = hexdec(substr(coin2hex($data['id']), 0, 12));
|
||||
if (gmp_cmp($no1, $no2) == 1) {
|
||||
$accept_new = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($accept_new) {
|
||||
// if the new block is accepted, run a microsanity to sync it
|
||||
_log('['.$ip."] Starting microsanity - $data[height]");
|
||||
@@ -247,7 +252,6 @@ elseif ($q == "currentBlock") {
|
||||
} // return a specific block, used in syncing
|
||||
elseif ($q == "getBlock") {
|
||||
$height = intval($data['height']);
|
||||
|
||||
$export = $block->export("", $height);
|
||||
if (!$export) {
|
||||
api_err("invalid-block");
|
||||
|
||||
@@ -67,6 +67,7 @@ if ((empty($peer) || $peer == 'all') && $type == "block") {
|
||||
}
|
||||
$r = $db->run("SELECT * FROM peers WHERE blacklisted < UNIX_TIMESTAMP() AND reserve=0 $ewhr");
|
||||
foreach ($r as $x) {
|
||||
if($x['hostname']==$_config['hostname']) continue;
|
||||
// encode the hostname in base58 and sanitize the IP to avoid any second order shell injections
|
||||
$host = base58_encode($x['hostname']);
|
||||
$ip = filter_var($x['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
||||
@@ -105,6 +106,7 @@ if ($type == "block") {
|
||||
// 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);
|
||||
_log("Propagating block to $hostname - [result: $response] $data[height] - $data[id]",2);
|
||||
if ($response == "block-ok") {
|
||||
echo "Block $i accepted. Exiting.\n";
|
||||
exit;
|
||||
|
||||
117
sanity.php
117
sanity.php
@@ -70,10 +70,72 @@ if ($_config['dbversion'] < 2) {
|
||||
exit;
|
||||
}
|
||||
|
||||
ini_set('memory_limit', '2G');
|
||||
|
||||
$block = new Block();
|
||||
$acc = new Account();
|
||||
$current = $block->current();
|
||||
|
||||
// bootstrapping the initial sync
|
||||
if ($current['height']==1) {
|
||||
echo "Bootstrapping!\n";
|
||||
$last=file_get_contents("http://dumps.arionum.com/last");
|
||||
$last=intval($last);
|
||||
$failed_sync=false;
|
||||
for ($i=1000;$i<=$last;$i=$i+1000) {
|
||||
echo "Download file $i\n";
|
||||
$res=trim(file_get_contents("http://dumps.arionum.com/aro.db.$i"));
|
||||
if ($res===false) {
|
||||
echo "Could not download the bootstrap file $i. Syncing the old fashioned way.\n";
|
||||
break;
|
||||
}
|
||||
$data=json_decode($res, true);
|
||||
|
||||
if ($data===false||is_null($data)) {
|
||||
echo "Could not parse the bootstrap file $i. Syncing the old fashioned way.\n";
|
||||
echo json_last_error_msg();
|
||||
break;
|
||||
}
|
||||
foreach ($data as $x) {
|
||||
if (count($x['data'])>0) {
|
||||
$transactions=[];
|
||||
|
||||
foreach ($x['data'] as $d) {
|
||||
$trans = [
|
||||
"id" => $d[0],
|
||||
"dst" => $d[1],
|
||||
"val" => $d[2],
|
||||
"fee" => $d[3],
|
||||
"signature" => $d[4],
|
||||
"message" => $d[5],
|
||||
"version" => $d[6],
|
||||
"date" => $d[7],
|
||||
"public_key" => $d[8],
|
||||
];
|
||||
ksort($trans);
|
||||
$transactions[$d[0]] = $trans;
|
||||
}
|
||||
ksort($transactions);
|
||||
$x['data']=$transactions;
|
||||
}
|
||||
|
||||
|
||||
echo "-> Adding block $x[height]\n";
|
||||
|
||||
$res=$block->add($x['height'], $x['public_key'], $x['nonce'], $x['data'], $x['date'], $x['signature'], $x['difficulty'], $x['reward_signature'], $x['argon'], true);
|
||||
if (!$res) {
|
||||
echo "Error: Adding the block failed. Syncing the old way.\n";
|
||||
$failed_sync=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($failed_sync) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$current = $block->current();
|
||||
}
|
||||
// the microsanity process is an anti-fork measure that will determine the best blockchain to choose for the last block
|
||||
$microsanity = false;
|
||||
if ($arg == "microsanity" && !empty($arg2)) {
|
||||
@@ -104,10 +166,7 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
||||
}
|
||||
|
||||
// the blockchain with the most transactions wins the fork (to encourage the miners to include as many transactions as possible) / might backfire on garbage
|
||||
if ($current['transactions'] > $data['transactions']) {
|
||||
echo "Block has less transactions\n";
|
||||
break;
|
||||
} elseif ($current['transactions'] == $data['transactions']) {
|
||||
|
||||
// transform the first 12 chars into an integer and choose the blockchain with the biggest value
|
||||
$no1 = hexdec(substr(coin2hex($current['id']), 0, 12));
|
||||
$no2 = hexdec(substr(coin2hex($data['id']), 0, 12));
|
||||
@@ -116,7 +175,7 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
||||
echo "Block hex larger than current\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the block is valid
|
||||
$prev = $block->get($current['height'] - 1);
|
||||
$public = $acc->public_key($data['generator']);
|
||||
@@ -126,7 +185,8 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
||||
$data['argon'],
|
||||
$block->difficulty($current['height'] - 1),
|
||||
$prev['id'],
|
||||
$prev['height']
|
||||
$prev['height'],
|
||||
$data['date']
|
||||
)) {
|
||||
echo "Invalid prev-block\n";
|
||||
break;
|
||||
@@ -142,6 +202,8 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
||||
// add the new block
|
||||
echo "Starting to sync last block from $x[hostname]\n";
|
||||
$b = $data;
|
||||
|
||||
|
||||
$res = $block->add(
|
||||
$b['height'],
|
||||
$b['public_key'],
|
||||
@@ -206,10 +268,15 @@ if ($total_peers == 0 && $_config['testnet'] == false) {
|
||||
foreach ($f as $peer) {
|
||||
//peer with all until max_peers, this will ask them to send a peering request to our peer.php where we add their peer to the db.
|
||||
$peer = trim(san_host($peer));
|
||||
$bad_peers = ["127.0.0.1", "localhost", "10.0.0", "192.168.0"];
|
||||
if (str_replace($bad_peers, "", $peer) != $peer) {
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
|
||||
$tpeer=str_replace(["https://","http://","//"], "", $peer);
|
||||
foreach ($bad_peers as $bp) {
|
||||
if (strpos($tpeer, $bp)===0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$peer = filter_var($peer, FILTER_SANITIZE_URL);
|
||||
if (!filter_var($peer, FILTER_VALIDATE_URL)) {
|
||||
continue;
|
||||
@@ -247,6 +314,7 @@ foreach ($r as $x) {
|
||||
_log("Contacting peer $x[hostname]");
|
||||
$url = $x['hostname']."/peer.php?q=";
|
||||
// get their peers list
|
||||
if($_config['get_more_peers']==true){
|
||||
$data = peer_post($url."getPeers", [], 5);
|
||||
if ($data === false) {
|
||||
_log("Peer $x[hostname] unresponsive");
|
||||
@@ -257,7 +325,6 @@ foreach ($r as $x) {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($data as $peer) {
|
||||
// store the hostname as md5 hash, for easier checking
|
||||
@@ -269,10 +336,13 @@ foreach ($r as $x) {
|
||||
continue;
|
||||
}
|
||||
$peered[$pid] = 1;
|
||||
$bad_peers = ["127.0.0.1", "localhost", "10.0.0.", "192.168.0."];
|
||||
if (str_replace($bad_peers, "", $peer['hostname']) != $peer['hostname']) {
|
||||
$bad_peers = ["127.", "localhost", "10.", "192.168.","172.16.","172.17.","172.18.","172.19.","172.20.","172.21.","172.22.","172.23.","172.24.","172.25.","172.26.","172.27.","172.28.","172.29.","172.30.","172.31."];
|
||||
$tpeer=str_replace(["https://","http://","//"], "", $peer['hostname']);
|
||||
foreach ($bad_peers as $bp) {
|
||||
if (strpos($tpeer, $bp)===0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if it's our hostname, ignore
|
||||
if ($peer['hostname'] == $_config['hostname']) {
|
||||
continue;
|
||||
@@ -301,7 +371,7 @@ foreach ($r as $x) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get the current block and check it's blockchain
|
||||
$data = peer_post($url."currentBlock", [], 5);
|
||||
@@ -350,11 +420,8 @@ foreach ($r as $x) {
|
||||
$largest_height = $data['height'];
|
||||
$largest_height_block = $data['id'];
|
||||
} else {
|
||||
// if this block has more transactions, declare it as winner
|
||||
if ($blocks[$largest_height_block]['transactions'] < $data['transactions']) {
|
||||
$largest_height = $data['height'];
|
||||
$largest_height_block = $data['id'];
|
||||
} elseif ($blocks[$largest_height_block]['transactions'] == $data['transactions']) {
|
||||
|
||||
|
||||
// if the blocks have the same number of transactions, choose the one with the highest derived integer from the first 12 hex characters
|
||||
$no1 = hexdec(substr(coin2hex($largest_height_block), 0, 12));
|
||||
$no2 = hexdec(substr(coin2hex($data['id']), 0, 12));
|
||||
@@ -363,7 +430,6 @@ foreach ($r as $x) {
|
||||
$largest_height_block = $data['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($data['difficulty'] < $blocks[$largest_height_block]['difficulty']) {
|
||||
// choose smallest (hardest) difficulty
|
||||
$largest_height = $data['height'];
|
||||
@@ -428,6 +494,9 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
$last_good = $i;
|
||||
}
|
||||
}
|
||||
if ($last_good==$current['height']-1&&$last_good%3==2) {
|
||||
$block->pop(1);
|
||||
}
|
||||
// if last 10 blocks are good, verify all the blocks
|
||||
if ($invalid == false) {
|
||||
$cblock = [];
|
||||
@@ -441,13 +510,17 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
}
|
||||
// check if the block mining data is correct
|
||||
for ($i = $last_good + 1; $i <= $largest_height; $i++) {
|
||||
if (($i-1)%3==2) {
|
||||
continue;
|
||||
}
|
||||
if (!$block->mine(
|
||||
$cblock[$i]['public_key'],
|
||||
$cblock[$i]['nonce'],
|
||||
$cblock[$i]['argon'],
|
||||
$cblock[$i]['difficulty'],
|
||||
$cblock[$i - 1]['id'],
|
||||
$cblock[$i - 1]['height']
|
||||
$cblock[$i - 1]['height'],
|
||||
$cblock[$i]['date']
|
||||
)) {
|
||||
$invalid = true;
|
||||
break;
|
||||
@@ -456,6 +529,7 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
|
||||
}
|
||||
// if the blockchain proves ok, delete until the last block
|
||||
if ($invalid == false) {
|
||||
_log("Changing fork, deleting $last_good", 1);
|
||||
$block->delete($last_good);
|
||||
$current = $block->current();
|
||||
$data = $current;
|
||||
@@ -591,7 +665,7 @@ foreach ($f as $x) {
|
||||
|
||||
|
||||
//recheck the last blocks
|
||||
if ($_config['sanity_recheck_blocks'] > 0) {
|
||||
if ($_config['sanity_recheck_blocks'] > 0 && $_config['testnet'] == false&&1==2) {
|
||||
_log("Rechecking blocks");
|
||||
$blocks = [];
|
||||
$all_blocks_ok = true;
|
||||
@@ -616,7 +690,8 @@ if ($_config['sanity_recheck_blocks'] > 0) {
|
||||
$data['argon'],
|
||||
$data['difficulty'],
|
||||
$blocks[$i - 1]['id'],
|
||||
$blocks[$i - 1]['height']
|
||||
$blocks[$i - 1]['height'],
|
||||
$data['date']
|
||||
)) {
|
||||
$db->run("UPDATE config SET val=1 WHERE cfg='sanity_sync'");
|
||||
_log("Invalid block detected. Deleting everything after $data[height] - $data[id]");
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
4.0.1
|
||||
|
||||
49
util.php
49
util.php
@@ -43,10 +43,12 @@ $cmd = trim($argv[1]);
|
||||
*/
|
||||
|
||||
if ($cmd == 'clean') {
|
||||
$tables = ["blocks", "accounts", "transactions", "mempool"];
|
||||
$db->run("SET foreign_key_checks=0;");
|
||||
$tables = ["accounts", "transactions", "mempool", "masternode","blocks"];
|
||||
foreach ($tables as $table) {
|
||||
$db->run("DELETE FROM {$table}");
|
||||
$db->run("TRUNCATE TABLE {$table}");
|
||||
}
|
||||
$db->run("SET foreign_key_checks=1;");
|
||||
|
||||
echo "\n The database has been cleared\n";
|
||||
} /**
|
||||
@@ -214,7 +216,8 @@ elseif ($cmd == "recheck-blocks") {
|
||||
$data['argon'],
|
||||
$data['difficulty'],
|
||||
$blocks[$i - 1]['id'],
|
||||
$blocks[$i - 1]['height']
|
||||
$blocks[$i - 1]['height'],
|
||||
$data['date']
|
||||
)) {
|
||||
_log("Invalid block detected. We should delete everything after $data[height] - $data[id]");
|
||||
break;
|
||||
@@ -408,7 +411,8 @@ elseif ($cmd == "check-address") {
|
||||
}
|
||||
|
||||
echo "The address is valid\n";
|
||||
} /**
|
||||
}
|
||||
/**
|
||||
* @api {php util.php} get-address Get-Address
|
||||
* @apiName get-address
|
||||
* @apiGroup UTIL
|
||||
@@ -429,6 +433,43 @@ elseif ($cmd == 'get-address') {
|
||||
die("Invalid public key");
|
||||
}
|
||||
print($acc->get_address($public_key));
|
||||
/**
|
||||
* @api {php util.php} clean-blacklist Clean-Blacklist
|
||||
* @apiName clean-blacklist
|
||||
* @apiGroup UTIL
|
||||
* @apiDescription Removes all the peers from blacklist
|
||||
*
|
||||
* @apiExample {cli} Example usage:
|
||||
* php util.php clean-blacklist
|
||||
*
|
||||
*/
|
||||
|
||||
} elseif ($cmd == 'clean-blacklist') {
|
||||
$db->run("UPDATE peers SET blacklisted=0, fails=0, stuckfail=0");
|
||||
echo "All the peers have been removed from the blacklist\n";
|
||||
}elseif($cmd == 'resync-accounts'){
|
||||
// resyncs the balance on all accounts
|
||||
|
||||
// lock table to avoid race conditions on blocks
|
||||
$db->exec("LOCK TABLES blocks WRITE, accounts WRITE, transactions WRITE, mempool WRITE");
|
||||
|
||||
$r=$db->run("SELECT * FROM accounts");
|
||||
foreach($r as $x){
|
||||
$alias=$x['alias'];
|
||||
if(empty($alias)) $alias="A";
|
||||
$rec=$db->single("SELECT SUM(val) FROM transactions WHERE (dst=:id or dst=:alias) AND (height<80000 OR (version!=100 AND version!=103)) and version<111",[":id"=>$x['id'], ":alias"=>$alias]);
|
||||
$spent=$db->single("SELECT SUM(val+fee) FROM transactions WHERE public_key=:pub AND version>0",[":pub"=>$x['public_key']]);
|
||||
if($spent==false) $spent=0;
|
||||
$balance=round(($rec-$spent),8);
|
||||
if($x['balance']!=$balance){
|
||||
echo "rec: $rec, spent: $spent, bal: $x[balance], should be: $balance - $x[id] $x[public_key]\n";
|
||||
$db->run("UPDATE accounts SET balance=:bal WHERE id=:id",[":id"=>$x['id'], ":bal"=>$balance]);
|
||||
}
|
||||
}
|
||||
$db->exec("UNLOCK TABLES");
|
||||
echo "All done";
|
||||
|
||||
|
||||
} else {
|
||||
echo "Invalid command\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user