aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-02-11 15:15:56 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-10-25 09:34:38 +0000
commit2899379791b7542e4eb920b5d9d58cf232806937 (patch)
tree7e97a95103837852d5c4e86ee544815d9a7a6671 /utils
parentadd a quick early out to get_blocks.bin when up to date (diff)
downloadmonero-2899379791b7542e4eb920b5d9d58cf232806937.tar.xz
daemon, wallet: new pay for RPC use system
Daemons intended for public use can be set up to require payment in the form of hashes in exchange for RPC service. This enables public daemons to receive payment for their work over a large number of calls. This system behaves similarly to a pool, so payment takes the form of valid blocks every so often, yielding a large one off payment, rather than constant micropayments. This system can also be used by third parties as a "paywall" layer, where users of a service can pay for use by mining Monero to the service provider's address. An example of this for web site access is Primo, a Monero mining based website "paywall": https://github.com/selene-kovri/primo This has some advantages: - incentive to run a node providing RPC services, thereby promoting the availability of third party nodes for those who can't run their own - incentive to run your own node instead of using a third party's, thereby promoting decentralization - decentralized: payment is done between a client and server, with no third party needed - private: since the system is "pay as you go", you don't need to identify yourself to claim a long lived balance - no payment occurs on the blockchain, so there is no extra transactional load - one may mine with a beefy server, and use those credits from a phone, by reusing the client ID (at the cost of some privacy) - no barrier to entry: anyone may run a RPC node, and your expected revenue depends on how much work you do - Sybil resistant: if you run 1000 idle RPC nodes, you don't magically get more revenue - no large credit balance maintained on servers, so they have no incentive to exit scam - you can use any/many node(s), since there's little cost in switching servers - market based prices: competition between servers to lower costs - incentive for a distributed third party node system: if some public nodes are overused/slow, traffic can move to others - increases network security - helps counteract mining pools' share of the network hash rate - zero incentive for a payer to "double spend" since a reorg does not give any money back to the miner And some disadvantages: - low power clients will have difficulty mining (but one can optionally mine in advance and/or with a faster machine) - payment is "random", so a server might go a long time without a block before getting one - a public node's overall expected payment may be small Public nodes are expected to compete to find a suitable level for cost of service. The daemon can be set up this way to require payment for RPC services: monerod --rpc-payment-address 4xxxxxx \ --rpc-payment-credits 250 --rpc-payment-difficulty 1000 These values are an example only. The --rpc-payment-difficulty switch selects how hard each "share" should be, similar to a mining pool. The higher the difficulty, the fewer shares a client will find. The --rpc-payment-credits switch selects how many credits are awarded for each share a client finds. Considering both options, clients will be awarded credits/difficulty credits for every hash they calculate. For example, in the command line above, 0.25 credits per hash. A client mining at 100 H/s will therefore get an average of 25 credits per second. For reference, in the current implementation, a credit is enough to sync 20 blocks, so a 100 H/s client that's just starting to use Monero and uses this daemon will be able to sync 500 blocks per second. The wallet can be set to automatically mine if connected to a daemon which requires payment for RPC usage. It will try to keep a balance of 50000 credits, stopping mining when it's at this level, and starting again as credits are spent. With the example above, a new client will mine this much credits in about half an hour, and this target is enough to sync 500000 blocks (currently about a third of the monero blockchain). There are three new settings in the wallet: - credits-target: this is the amount of credits a wallet will try to reach before stopping mining. The default of 0 means 50000 credits. - auto-mine-for-rpc-payment-threshold: this controls the minimum credit rate which the wallet considers worth mining for. If the daemon credits less than this ratio, the wallet will consider mining to be not worth it. In the example above, the rate is 0.25 - persistent-rpc-client-id: if set, this allows the wallet to reuse a client id across runs. This means a public node can tell a wallet that's connecting is the same as one that connected previously, but allows a wallet to keep their credit balance from one run to the other. Since the wallet only mines to keep a small credit balance, this is not normally worth doing. However, someone may want to mine on a fast server, and use that credit balance on a low power device such as a phone. If left unset, a new client ID is generated at each wallet start, for privacy reasons. To mine and use a credit balance on two different devices, you can use the --rpc-client-secret-key switch. A wallet's client secret key can be found using the new rpc_payments command in the wallet. Note: anyone knowing your RPC client secret key is able to use your credit balance. The wallet has a few new commands too: - start_mining_for_rpc: start mining to acquire more credits, regardless of the auto mining settings - stop_mining_for_rpc: stop mining to acquire more credits - rpc_payments: display information about current credits with the currently selected daemon The node has an extra command: - rpc_payments: display information about clients and their balances The node will forget about any balance for clients which have been inactive for 6 months. Balances carry over on node restart.
Diffstat (limited to 'utils')
-rw-r--r--utils/python-rpc/framework/daemon.py162
1 files changed, 130 insertions, 32 deletions
diff --git a/utils/python-rpc/framework/daemon.py b/utils/python-rpc/framework/daemon.py
index 1d6c57c56..f811535b1 100644
--- a/utils/python-rpc/framework/daemon.py
+++ b/utils/python-rpc/framework/daemon.py
@@ -37,10 +37,11 @@ class Daemon(object):
self.port = port
self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18180+idx))
- def getblocktemplate(self, address, prev_block = ""):
+ def getblocktemplate(self, address, prev_block = "", client = ""):
getblocktemplate = {
'method': 'getblocktemplate',
'params': {
+ 'client': client,
'wallet_address': address,
'reserve_size' : 1,
'prev_block' : prev_block,
@@ -51,8 +52,9 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblocktemplate)
get_block_template = getblocktemplate
- def send_raw_transaction(self, tx_as_hex, do_not_relay = False, do_sanity_checks = True):
+ def send_raw_transaction(self, tx_as_hex, do_not_relay = False, do_sanity_checks = True, client = ""):
send_raw_transaction = {
+ 'client': client,
'tx_as_hex': tx_as_hex,
'do_not_relay': do_not_relay,
'do_sanity_checks': do_sanity_checks,
@@ -70,10 +72,11 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(submitblock)
submit_block = submitblock
- def getblock(self, hash = '', height = 0, fill_pow_hash = False):
+ def getblock(self, hash = '', height = 0, fill_pow_hash = False, client = ""):
getblock = {
'method': 'getblock',
'params': {
+ 'client': client,
'hash': hash,
'height': height,
'fill_pow_hash': fill_pow_hash,
@@ -84,10 +87,11 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblock)
get_block = getblock
- def getlastblockheader(self):
+ def getlastblockheader(self, client = ""):
getlastblockheader = {
'method': 'getlastblockheader',
'params': {
+ 'client': client,
},
'jsonrpc': '2.0',
'id': '0'
@@ -95,10 +99,11 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getlastblockheader)
get_last_block_header = getlastblockheader
- def getblockheaderbyhash(self, hash = "", hashes = []):
+ def getblockheaderbyhash(self, hash = "", hashes = [], client = ""):
getblockheaderbyhash = {
'method': 'getblockheaderbyhash',
'params': {
+ 'client': client,
'hash': hash,
'hashes': hashes,
},
@@ -108,10 +113,11 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblockheaderbyhash)
get_block_header_by_hash = getblockheaderbyhash
- def getblockheaderbyheight(self, height):
+ def getblockheaderbyheight(self, height, client = ""):
getblockheaderbyheight = {
'method': 'getblockheaderbyheight',
'params': {
+ 'client': client,
'height': height,
},
'jsonrpc': '2.0',
@@ -120,10 +126,11 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblockheaderbyheight)
get_block_header_by_height = getblockheaderbyheight
- def getblockheadersrange(self, start_height, end_height, fill_pow_hash = False):
+ def getblockheadersrange(self, start_height, end_height, fill_pow_hash = False, client = ""):
getblockheadersrange = {
'method': 'getblockheadersrange',
'params': {
+ 'client': client,
'start_height': start_height,
'end_height': end_height,
'fill_pow_hash': fill_pow_hash,
@@ -134,28 +141,35 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblockheadersrange)
get_block_headers_range = getblockheadersrange
- def get_connections(self):
+ def get_connections(self, client = ""):
get_connections = {
+ 'client': client,
'method': 'get_connections',
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(get_connections)
- def get_info(self):
+ def get_info(self, client = ""):
get_info = {
- 'method': 'get_info',
- 'jsonrpc': '2.0',
- 'id': '0'
+ 'method': 'get_info',
+ 'params': {
+ 'client': client,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
}
return self.rpc.send_json_rpc_request(get_info)
getinfo = get_info
- def hard_fork_info(self):
+ def hard_fork_info(self, client = ""):
hard_fork_info = {
- 'method': 'hard_fork_info',
- 'jsonrpc': '2.0',
- 'id': '0'
+ 'method': 'hard_fork_info',
+ 'params': {
+ 'client': client,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
}
return self.rpc.send_json_rpc_request(hard_fork_info)
@@ -174,7 +188,7 @@ class Daemon(object):
}
return self.rpc.send_json_rpc_request(generateblocks)
- def get_height(self):
+ def get_height(self, client = ""):
get_height = {
'method': 'get_height',
'jsonrpc': '2.0',
@@ -208,18 +222,21 @@ class Daemon(object):
}
return self.rpc.send_request('/mining_status', mining_status)
- def get_transaction_pool(self):
+ def get_transaction_pool(self, client = ""):
get_transaction_pool = {
+ 'client': client,
}
return self.rpc.send_request('/get_transaction_pool', get_transaction_pool)
- def get_transaction_pool_hashes(self):
+ def get_transaction_pool_hashes(self, client = ""):
get_transaction_pool_hashes = {
+ 'client': client,
}
return self.rpc.send_request('/get_transaction_pool_hashes', get_transaction_pool_hashes)
- def get_transaction_pool_stats(self):
+ def get_transaction_pool_stats(self, client = ""):
get_transaction_pool_stats = {
+ 'client': client,
}
return self.rpc.send_request('/get_transaction_pool_stats', get_transaction_pool_stats)
@@ -263,8 +280,9 @@ class Daemon(object):
}
return self.rpc.send_json_rpc_request(set_bans)
- def get_transactions(self, txs_hashes = [], decode_as_json = False, prune = False, split = False):
+ def get_transactions(self, txs_hashes = [], decode_as_json = False, prune = False, split = False, client = ""):
get_transactions = {
+ 'client': client,
'txs_hashes': txs_hashes,
'decode_as_json': decode_as_json,
'prune': prune,
@@ -273,17 +291,19 @@ class Daemon(object):
return self.rpc.send_request('/get_transactions', get_transactions)
gettransactions = get_transactions
- def get_outs(self, outputs = [], get_txid = False):
+ def get_outs(self, outputs = [], get_txid = False, client = ""):
get_outs = {
+ 'client': client,
'outputs': outputs,
'get_txid': get_txid,
}
return self.rpc.send_request('/get_outs', get_outs)
- def get_coinbase_tx_sum(self, height, count):
+ def get_coinbase_tx_sum(self, height, count, client = ""):
get_coinbase_tx_sum = {
'method': 'get_coinbase_tx_sum',
'params': {
+ 'client': client,
'height': height,
'count': count,
},
@@ -292,10 +312,11 @@ class Daemon(object):
}
return self.rpc.send_json_rpc_request(get_coinbase_tx_sum)
- def get_output_distribution(self, amounts = [], from_height = 0, to_height = 0, cumulative = False, binary = False, compress = False):
+ def get_output_distribution(self, amounts = [], from_height = 0, to_height = 0, cumulative = False, binary = False, compress = False, client = ""):
get_output_distribution = {
'method': 'get_output_distribution',
'params': {
+ 'client': client,
'amounts': amounts,
'from_height': from_height,
'to_height': to_height,
@@ -308,10 +329,11 @@ class Daemon(object):
}
return self.rpc.send_json_rpc_request(get_output_distribution)
- def get_output_histogram(self, amounts = [], min_count = 0, max_count = 0, unlocked = False, recent_cutoff = 0):
+ def get_output_histogram(self, amounts = [], min_count = 0, max_count = 0, unlocked = False, recent_cutoff = 0, client = ""):
get_output_histogram = {
'method': 'get_output_histogram',
'params': {
+ 'client': client,
'amounts': amounts,
'min_count': min_count,
'max_count': max_count,
@@ -335,15 +357,17 @@ class Daemon(object):
}
return self.rpc.send_request('/set_log_categories', set_log_categories)
- def get_alt_blocks_hashes(self):
+ def get_alt_blocks_hashes(self, client = ""):
get_alt_blocks_hashes = {
+ 'client': client,
}
return self.rpc.send_request('/get_alt_blocks_hashes', get_alt_blocks_hashes)
- def get_alternate_chains(self):
+ def get_alternate_chains(self, client = ""):
get_alternate_chains = {
'method': 'get_alternate_chains',
'params': {
+ 'client': client,
},
'jsonrpc': '2.0',
'id': '0'
@@ -361,9 +385,10 @@ class Daemon(object):
}
return self.rpc.send_json_rpc_request(get_fee_estimate)
- def is_key_image_spent(self, key_images = []):
+ def is_key_image_spent(self, key_images = [], client = ""):
is_key_image_spent = {
'key_images': key_images,
+ 'client': client,
}
return self.rpc.send_request('/is_key_image_spent', is_key_image_spent)
@@ -413,7 +438,7 @@ class Daemon(object):
def in_peers(self, in_peers):
in_peers = {
- 'in_peers': in_peers,
+ 'client': client,
}
return self.rpc.send_request('/in_peers', in_peers)
@@ -446,31 +471,34 @@ class Daemon(object):
on_get_block_hash = get_block_hash
on_getblockhash = get_block_hash
- def relay_tx(self, txids = []):
+ def relay_tx(self, txids = [], client = ""):
relay_tx = {
'method': 'relay_tx',
'params': {
'txids': txids,
+ 'client': client,
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(relay_tx)
- def sync_info(self):
+ def sync_info(self, client = ""):
sync_info = {
'method': 'sync_info',
'params': {
+ 'client': client,
},
'jsonrpc': '2.0',
'id': '0'
}
return self.rpc.send_json_rpc_request(sync_info)
- def get_txpool_backlog(self):
+ def get_txpool_backlog(self, client = ""):
get_txpool_backlog = {
'method': 'get_txpool_backlog',
'params': {
+ 'client': client,
},
'jsonrpc': '2.0',
'id': '0'
@@ -498,3 +526,73 @@ class Daemon(object):
'id': '0'
}
return self.rpc.send_json_rpc_request(get_block_rate)
+
+ def rpc_access_info(self, client):
+ rpc_access_info = {
+ 'method': 'rpc_access_info',
+ 'params': {
+ 'client': client,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_info)
+
+ def rpc_access_submit_nonce(self, client, nonce, cookie):
+ rpc_access_submit_nonce = {
+ 'method': 'rpc_access_submit_nonce',
+ 'params': {
+ 'client': client,
+ 'nonce': nonce,
+ 'cookie': cookie,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_submit_nonce)
+
+ def rpc_access_pay(self, client, paying_for, payment):
+ rpc_access_pay = {
+ 'method': 'rpc_access_pay',
+ 'params': {
+ 'client': client,
+ 'paying_for': paying_for,
+ 'payment': payment,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_pay)
+
+ def rpc_access_tracking(self, clear = False):
+ rpc_access_tracking = {
+ 'method': 'rpc_access_tracking',
+ 'params': {
+ 'clear': clear,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_tracking)
+
+ def rpc_access_data(self):
+ rpc_access_data = {
+ 'method': 'rpc_access_data',
+ 'params': {
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_data)
+
+ def rpc_access_account(self, client, delta_balance = 0):
+ rpc_access_account = {
+ 'method': 'rpc_access_account',
+ 'params': {
+ 'client': client,
+ 'delta_balance': delta_balance,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(rpc_access_account)