From 832ab7d346e5888320b8ba98fbf4cac922d55bf6 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Mon, 26 Oct 2020 16:29:41 -0700 Subject: [PATCH] Start constructor migration --- README.md | 7 +- .../config.json} | 0 .../bitcoin.ros} | 197 ++++++++---------- rosetta-cli-conf/testnet/config.json | 50 +++++ 4 files changed, 138 insertions(+), 116 deletions(-) rename rosetta-cli-conf/{bitcoin_mainnet.json => mainnet/config.json} (100%) rename rosetta-cli-conf/{bitcoin_testnet.json => testnet/bitcoin.ros} (78%) create mode 100644 rosetta-cli-conf/testnet/config.json diff --git a/README.md b/README.md index 5865e97..3c71dfe 100644 --- a/README.md +++ b/README.md @@ -207,10 +207,9 @@ in recently processed blocks to save to disk. ## Testing with rosetta-cli To validate `rosetta-bitcoin`, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install) and run one of the following commands: -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/bitcoin_testnet.json` -* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/bitcoin_testnet.json` -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/bitcoin_mainnet.json` -* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/bitcoin_mainnet.json` +* `rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json` +* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json` +* `rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json` ## Future Work * Publish benchamrks for sync speed, storage usage, and load testing diff --git a/rosetta-cli-conf/bitcoin_mainnet.json b/rosetta-cli-conf/mainnet/config.json similarity index 100% rename from rosetta-cli-conf/bitcoin_mainnet.json rename to rosetta-cli-conf/mainnet/config.json diff --git a/rosetta-cli-conf/bitcoin_testnet.json b/rosetta-cli-conf/testnet/bitcoin.ros similarity index 78% rename from rosetta-cli-conf/bitcoin_testnet.json rename to rosetta-cli-conf/testnet/bitcoin.ros index 90ceee5..e9f3aa2 100644 --- a/rosetta-cli-conf/bitcoin_testnet.json +++ b/rosetta-cli-conf/testnet/bitcoin.ros @@ -1,87 +1,88 @@ -{ - "network": { - "blockchain": "Bitcoin", - "network": "Testnet3" - }, - "data_directory": "bitcoin-testnet-data", - "http_timeout": 300, - "max_retries": 5, - "retry_elapsed_time": 0, - "max_online_connections": 0, - "max_sync_concurrency": 0, - "tip_delay": 1800, - "log_configuration": false, - "construction": { - "max_offline_connections": 0, - "stale_depth": 0, - "broadcast_limit": 0, - "ignore_broadcast_failures": false, - "clear_broadcasts": false, - "broadcast_behind_tip": false, - "block_broadcast_limit": 0, - "rebroadcast_all": false, - "workflows": [ - { - "name": "request_funds", - "concurrency": 1, - "scenarios": [ - { - "name": "find_account", - "actions": [ - { - "input": "{\"symbol\":\"tBTC\", \"decimals\":8}", - "type": "set_variable", - "output_path": "currency" - }, - { - "input": "{\"minimum_balance\":{\"value\": \"0\", \"currency\": {{currency}}}, \"create_limit\":1}", - "type": "find_balance", - "output_path": "random_account" - } - ] - }, - { - "name": "request", - "actions": [ - { - "input": "{\"account_identifier\": {{random_account.account_identifier}}, \"minimum_balance\":{\"value\": \"1000000\", \"currency\": {{currency}}}}", - "type": "find_balance", - "output_path": "loaded_account" - } - ] - } - ] - }, - { - "name": "create_account", - "concurrency": 1, - "scenarios": [ - { - "name": "create_account", - "actions": [ - { - "input": "{\"network\":\"Testnet3\", \"blockchain\":\"Bitcoin\"}", - "type": "set_variable", - "output_path": "network" - }, - { - "input": "{\"curve_type\": \"secp256k1\"}", - "type": "generate_key", - "output_path": "key" - }, - { - "input": "{\"network_identifier\": {{network}}, \"public_key\": {{key.public_key}}}", - "type": "derive", - "output_path": "account" - }, - { - "input": "{\"account_identifier\": {{account.account_identifier}}, \"keypair\": {{key}}}", - "type": "save_account" - } - ] - } - ] - }, +request_funds(1) { + find_account{ + currency = {"symbol":"tBTC", "decimals":8}; + random_account = find_balance({ + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit":1 + }); + }, + + // Create a separate scenario to request funds so that + // the address we are using to request funds does not + // get rolled back if funds do not yet exist. + request{ + loaded_account = find_balance({ + "account_identifier": {{random_account.account_identifier}}, + "minimum_balance":{ + "value": "1000000", + "currency": {{currency}} + } + }); + } +} + +create_account(1){ + create{ + network = {"network":"Testnet3", "blockchain":"Bitcoin"}; + key = generate_key({"curve_type": "secp256k1"}); + account = derive({ + "network_identifier": {{network}}, + "public_key": {{key.public_key}} + }); + + // If the account is not saved, the key will be lost! + save_account({ + "account_identifier": {{account.account_identifier}}, + "keypair": {{key}} + }); + } +} + +transfer(10){ + transfer_dry_run{ + transfer_dry_run.network = {"network":"Testnet3", "blockchain":"Bitcoin"}; + currency = {"symbol":"tBTC", "decimals":8}; + + // We set the max_fee_amount to know how much buffer we should + // leave for fee payment when selecting a sender account. + dust_amount = "600"; + max_fee_amount = "1200"; + send_buffer = {{dust_amount}} + {{max_fee_amount}}; + + // reserved_amount is max_fee_amount + min_utxo size x 2 + reserved_amount = "2400"; + sender = find_balance({ + "minimum_balance":{ + "value": {{reserved_amount}}, + "currency": {{currency}} + }, + "require_coin": true + }); + + available_amount = {{sender.balance.value}} - {{send_buffer}}; + recipient_amount = random_number({ + "minimum": {{dust_amount}}, + "maximum": {{available_amount}} + }); + print_message({ + "recipient_amount":{{recipient_amount}} + }); + + total_change_amount = {{sender.balance.value}} - {{recipient_amount}}; + change_amount = {{total_change_amount}} - {{max_fee_amount}}; + print_message({ + "change_amount":{{change_amount}} + }); + + sender_amount = 0 - {{sender.balance.value}}; + + }, + transfer{ + }, +} { "name": "transfer", "concurrency": 10, @@ -350,31 +351,3 @@ } ] } - ], - "end_conditions": { - "create_account": 10, - "transfer": 10 - } - }, - "data": { - "active_reconciliation_concurrency": 0, - "inactive_reconciliation_concurrency": 0, - "inactive_reconciliation_frequency": 0, - "log_blocks": false, - "log_transactions": false, - "log_balance_changes": false, - "log_reconciliations": false, - "ignore_reconciliation_error": false, - "exempt_accounts": "", - "bootstrap_balances": "", - "interesting_accounts": "", - "reconciliation_disabled": false, - "inactive_discrepency_search_disabled": false, - "balance_tracking_disabled": false, - "coin_tracking_disabled": false, - "end_conditions": { - "reconciliation_coverage": 0.95 - }, - "results_output_file": "" - } -} diff --git a/rosetta-cli-conf/testnet/config.json b/rosetta-cli-conf/testnet/config.json new file mode 100644 index 0000000..c73810f --- /dev/null +++ b/rosetta-cli-conf/testnet/config.json @@ -0,0 +1,50 @@ +{ + "network": { + "blockchain": "Bitcoin", + "network": "Testnet3" + }, + "data_directory": "bitcoin-testnet-data", + "http_timeout": 300, + "max_retries": 5, + "retry_elapsed_time": 0, + "max_online_connections": 0, + "max_sync_concurrency": 0, + "tip_delay": 1800, + "log_configuration": false, + "construction": { + "max_offline_connections": 0, + "stale_depth": 0, + "broadcast_limit": 0, + "ignore_broadcast_failures": false, + "clear_broadcasts": false, + "broadcast_behind_tip": false, + "block_broadcast_limit": 0, + "rebroadcast_all": false, + "constructor_dsl_file": "bitcoin.ros", + "end_conditions": { + "create_account": 10, + "transfer": 10 + } + }, + "data": { + "active_reconciliation_concurrency": 0, + "inactive_reconciliation_concurrency": 0, + "inactive_reconciliation_frequency": 0, + "log_blocks": false, + "log_transactions": false, + "log_balance_changes": false, + "log_reconciliations": false, + "ignore_reconciliation_error": false, + "exempt_accounts": "", + "bootstrap_balances": "", + "interesting_accounts": "", + "reconciliation_disabled": false, + "inactive_discrepency_search_disabled": false, + "balance_tracking_disabled": false, + "coin_tracking_disabled": false, + "end_conditions": { + "reconciliation_coverage": 0.95 + }, + "results_output_file": "" + } +}