From 5bf895eefe958b06f641f17c03f998896d3ed8af Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Wed, 9 Mar 2016 12:26:07 -0500 Subject: [PATCH 1/5] update documentation to reflect using lbryum by default --- INSTALL.md | 38 ++--------- README.md | 2 +- RUNNING.md | 75 ++++++++++++---------- lbrynet/lbrynet_console/ConsoleControl.py | 12 +--- lbrynet/lbrynet_console/ControlHandlers.py | 8 +-- 5 files changed, 55 insertions(+), 80 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index a964c8a8f..6dc552bcf 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,38 +1,14 @@ -Prerequisites -------------- - -To use the LBRYWallet, which enables spending and accepting LBRYcrds in exchange for data, the -LBRYcrd application (insert link to LBRYcrd website here) must be installed and running. If -this is not desired, the testing client can be used to simulate trading points, which is -built into LBRYnet. - -on Ubuntu: - -``` -sudo apt-get install libgmp3-dev build-essential python-dev python-pip -``` - -Getting the source ------------------- - -Don't you already have it? - -Setting up the environment +#### Installing lbrynet on Linux -------------------------- -It's recommended that you use a virtualenv +The following packages are necessary (the following are their names on Ubuntu): +libgmp3-dev build-essential python2.7 python2.7-dev python-pip -``` -sudo apt-get install python-virtualenv -cd -virtualenv . -source bin/activate -``` +To install them on Ubuntu: +sudo apt-get install libgmp3-dev build-essential python2.7 python2.7-dev python-pip -(to deactivate the virtualenv, enter 'deactivate') - -``` -python setup.py install +python setup.py build bdist_egg +sudo python setup.py install ``` this will install all of the libraries and a few applications diff --git a/README.md b/README.md index d9f7cd98e..dc8b5c81f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ See [INSTALL](INSTALL.md) ## Developers Documentation: doc.lbry.io -Source code: trac.lbry.io/browser +Source code: https://github.com/lbryio/lbry To contribute to the development of LBRYnet or lbrynet-console, contact jimmy@lbry.io diff --git a/RUNNING.md b/RUNNING.md index 137487360..b9f60acc9 100644 --- a/RUNNING.md +++ b/RUNNING.md @@ -9,20 +9,38 @@ Download the file https://raw.githubusercontent.com/lbryio/lbry-setup/master/lbr Once it's done building, type: ``` -./lbrycrd/src/lbrycrdd -server -daemon -lbrynet-gui +lbrynet-console ``` -A window should show up with an entry box +A console application will load, and after a moment you will be presented with a ">" signifying +that the console is ready for commands. -Type wonderfullife into the box, hit go, and choose to stream or save +If it's your first time running lbrynet-console, you should be given some credits to test the +network. If they don't show up within a minute or two, let us know, and we'll send you some. -To stop lbrycrdd: `./lbrycrd/src/lbrycrd-cli stop` +After your credits have shown up, type + +``` +get wonderfullife +``` + +into the prompt and hit enter. + +You will be asked if you want to cancel, change options, save, and perhaps stream the file. + +Enter 's' for save and then hit enter. + +The file should start downloading. Enter the command 'status' to check on the status of files +that are in the process of being downloaded. + +To stop lbrynet-console, enter the command 'exit'. ## Slightly longer install guide -### Installing lbrycrd from source +### Installing lbrycrd, the full blockchain client + +Note: this process takes upwards of an hour and is not necessary to use lbrynet. ``` git clone --depth=1 -b alpha https://github.com/lbryio/lbrycrd.git @@ -89,11 +107,21 @@ sudo python setup.py install ## Slightly longer running guide -###In order to use lbrynet-console or lbrynet-gui, lbyrcrd must be running. +### lbrynet-console can be set to use lbrycrdd instead of the built in lightweight client. -### Running lbrycrd +To run lbrynet-console with lbrycrdd: -If you ran the easy install script, the lbrycrd folder will be in the directory you ran lbry_setup.sh from. Otherwise it is the root of the cloned lbrycrd repository. Go to that directory. +``` +lbrynet-console +``` + +If lbrycrdd is not already running, lbrynet will launch it at that path, and will shut it down +when lbrynet exits. If lbrycrdd is already running, lbrynet will not launch it and will not +shut it down, but it will connect to it and use it. + +### Running lbrycrdd manually + +From the lbrycrd directory, run: ``` ./src/lbrycrdd -server -daemon @@ -105,37 +133,14 @@ If you want to mine LBC, also use the flag '-gen', so: ./src/lbrycrdd -server -daemon -gen ``` +Warning: This will put a heavy load on your CPU + It will take a few minutes for your client to download the whole block chain. -lbrycrdd must be running in order for lbrynet to function. - -To shut lbrycrdd down: from the lbrycrd directory, run +To shut lbrycrdd down: from the lbrycrd directory, run: ``` ./src/lbrycrd-cli stop ``` -### Option 1) Running lbrynet-console - -If you used the virtualenv instructions above, make sure the virtualenv is still active. If not, reactivate it according to the instructions above, under "Installing lbrynet from source" - -In your terminal: `lbrynet-console` - -You should be presented with a prompt. - -Watch It's a Wonderful Life via LBRY - -Type into the prompt: `get wonderfullife` - -To shut it down, press ctrl-c at any time or enter `exit` into the prompt. - -### Option 2) Running lbrynet-gui - -If you used the virtualenv instructions above, make sure the virtualenv is still active. If not, reactivate it according to the instructions above, under "Installing lbrynet from source" - -In your terminal: `lbrynet-gui` - -A window should pop up with an entry box. Type `wonderfullife` into the box, hit go, and then choose to save it or stream it. -Enjoy! - Any questions or problems, email jimmy@lbry.io diff --git a/lbrynet/lbrynet_console/ConsoleControl.py b/lbrynet/lbrynet_console/ConsoleControl.py index 8b6552e6e..be52da843 100644 --- a/lbrynet/lbrynet_console/ConsoleControl.py +++ b/lbrynet/lbrynet_console/ConsoleControl.py @@ -29,16 +29,10 @@ class ConsoleControl(basic.LineReceiver): def send_initial_prompt(self): self.sendLine("") - self.sendLine("In this early release of LBRY, some functions will not work\n" - "until you have downloaded a full copy of our blockchain. To\n" - "check whether you've caught up with the blockchain, use the\n" - "command 'get-blockchain-status'.\n\n" - "If, for example, you are unable to download some files or\n" - "your balance is showing 0 when you know it shouldn't be, it\n" - "is likely that the culprit is the blockchain.\n\n" - "You should have received 1000 LBC the first time you ran\n" + self.sendLine("You should have received 1000 LBC the first time you ran\n" "this program. If you did not, let us know! But first give\n" - "them a couple of minutes to show up.\n\n" + "them a moment to show up. The block time is currently 30\n" + "seconds so they should show up within a couple of minutes.\n\n" "Welcome to lbrynet-console!") self.sendLine("") self.sendLine("Enter a command. Try 'get wonderfullife' or 'help' to see more options.") diff --git a/lbrynet/lbrynet_console/ControlHandlers.py b/lbrynet/lbrynet_console/ControlHandlers.py index 6cac5da64..6542505c2 100644 --- a/lbrynet/lbrynet_console/ControlHandlers.py +++ b/lbrynet/lbrynet_console/ControlHandlers.py @@ -323,7 +323,7 @@ class GetWalletBalances(CommandHandler): def _show_time_behind_blockchain(self, rounded_time): if rounded_time.unit >= RoundedTime.HOUR: self.console.sendLine("\n\nYour balance may be out of date. This application\n" - "is %s behind the LBC blockchain. It should take a few minutes to\n" + "is %s behind the LBC blockchain. It may take a few minutes to\n" "catch up the first time you run this early version of LBRY.\n" "Please be patient =).\n\n" % str(rounded_time)) else: @@ -797,7 +797,7 @@ class AddStream(CommandHandler): self.console.sendLine("\nThis application is %s behind the LBC blockchain, so some of your\n" "funds may not be available. Use 'get-blockchain-status' to check if\n" "your application is up to date with the blockchain.\n\n" - "It should take a few minutes to catch up the first time you run this\n" + "It may take a few minutes to catch up the first time you run this\n" "early version of LBRY. Please be patient =).\n\n" % str(rounded_time)) def _log_recent_blockchain_time_error_download(self, err): @@ -913,7 +913,7 @@ class AddStreamFromLBRYcrdName(AddStreamFromHash): self.console.sendLine("\nThis application is %s behind the LBC blockchain, which may be\n" "preventing this name from being resolved correctly. Use 'get-blockchain-status'\n" "to check if your application is up to date with the blockchain.\n\n" - "It should take a few minutes to catch up the first time you run\n" + "It may take a few minutes to catch up the first time you run\n" "this early version of LBRY. Please be patient =).\n\n" % str(rounded_time)) else: self.console.sendLine("\n") @@ -1850,7 +1850,7 @@ class Publish(CommandHandler): if rounded_time.unit >= RoundedTime.HOUR: self.console.sendLine("This application is %s behind the LBC blockchain\n" "and therefore may not have all of the funds you expect\n" - "available at this time. It should take a few minutes to\n" + "available at this time. It may take a few minutes to\n" "catch up the first time you run this early version of LBRY.\n" "Please be patient =).\n" % str(rounded_time)) From 45f9a10bfbbdcf0ba22fc2431f1e061353106075 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:08:15 -0500 Subject: [PATCH 2/5] hide exceptions that show up in the dht and due to bad metadata in the blockchain --- lbrynet/core/LBRYcrdWallet.py | 4 ++-- lbrynet/dht/encoding.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index 46279a2e4..09bc1e7bc 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -294,7 +294,7 @@ class LBRYWallet(object): value = result['value'] try: value_dict = json.loads(value) - except ValueError: + except (ValueError, TypeError): return Failure(InvalidStreamInfoError(name)) known_fields = ['stream_hash', 'name', 'description', 'key_fee', 'key_fee_address', 'thumbnail', 'content_license'] @@ -395,7 +395,7 @@ class LBRYWallet(object): if 'name' in claim and str(claim['name']) == name and 'value' in claim: try: value_dict = json.loads(claim['value']) - except ValueError: + except (ValueError, TypeError): return None if 'stream_hash' in value_dict and str(value_dict['stream_hash']) == sd_hash: if 'is controlling' in claim and claim['is controlling']: diff --git a/lbrynet/dht/encoding.py b/lbrynet/dht/encoding.py index a57747628..e0b42ee4f 100644 --- a/lbrynet/dht/encoding.py +++ b/lbrynet/dht/encoding.py @@ -99,7 +99,10 @@ class Bencode(Encoding): """ if len(data) == 0: raise DecodeError, 'Cannot decode empty string' - return self._decodeRecursive(data)[0] + try: + return self._decodeRecursive(data)[0] + except ValueError as e: + raise DecodeError, e.message @staticmethod def _decodeRecursive(data, startIndex=0): From e91f34f09b5cb30e65c11630e798c8dd432997ab Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:25:46 -0500 Subject: [PATCH 3/5] change metadata structure to use sources key --- lbrynet/core/LBRYcrdWallet.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index 09bc1e7bc..ef7c95baf 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -297,10 +297,19 @@ class LBRYWallet(object): except (ValueError, TypeError): return Failure(InvalidStreamInfoError(name)) known_fields = ['stream_hash', 'name', 'description', 'key_fee', 'key_fee_address', 'thumbnail', - 'content_license'] + 'content_license', 'sources'] + known_sources = ['lbry_sd_hash'] for field in known_fields: if field in value_dict: - r_dict[field] = value_dict[field] + if field == 'sources': + for source in known_sources: + if source in value_dict[field]: + if source == 'lbry_sd_hash': + r_dict['stream_hash'] = value_dict[field][source] + else: + r_dict[source] = value_dict[field][source] + else: + r_dict[field] = value_dict[field] if 'stream_hash' in r_dict and 'txid' in result: d = self._save_name_metadata(name, r_dict['stream_hash'], str(result['txid'])) else: @@ -312,8 +321,8 @@ class LBRYWallet(object): return Failure(UnknownNameError(name)) def claim_name(self, name, sd_hash, amount, description=None, key_fee=None, - key_fee_address=None, thumbnail=None, content_license=None): - value = {"stream_hash": sd_hash} + key_fee_address=None, thumbnail=None, content_license=None): + value = {"sources": {'lbry_sd_hash': sd_hash}} if description is not None: value['description'] = description if key_fee is not None: @@ -397,7 +406,12 @@ class LBRYWallet(object): value_dict = json.loads(claim['value']) except (ValueError, TypeError): return None - if 'stream_hash' in value_dict and str(value_dict['stream_hash']) == sd_hash: + claim_sd_hash = None + if 'stream_hash' in value_dict: + claim_sd_hash = str(value_dict['stream_hash']) + if 'sources' in value_dict and 'lbrynet_sd_hash' in value_dict['sources']: + claim_sd_hash = str(value_dict['sources']['lbry_sd_hash']) + if claim_sd_hash is not None and claim_sd_hash == sd_hash: if 'is controlling' in claim and claim['is controlling']: return name, "valid" if claim['in claim trie']: From 14ab2b52e94afc9c1a81b0932db224b25c52289a Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:42:57 -0500 Subject: [PATCH 4/5] create fee field in metadata --- lbrynet/core/LBRYcrdWallet.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index ef7c95baf..153b27e56 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -297,8 +297,9 @@ class LBRYWallet(object): except (ValueError, TypeError): return Failure(InvalidStreamInfoError(name)) known_fields = ['stream_hash', 'name', 'description', 'key_fee', 'key_fee_address', 'thumbnail', - 'content_license', 'sources'] + 'content_license', 'sources', 'fee'] known_sources = ['lbry_sd_hash'] + known_fee_types = {'LBC': ['amount', 'address']} for field in known_fields: if field in value_dict: if field == 'sources': @@ -308,6 +309,18 @@ class LBRYWallet(object): r_dict['stream_hash'] = value_dict[field][source] else: r_dict[source] = value_dict[field][source] + elif field == 'fee': + fee = value_dict['fee'] + if 'type' in fee: + if fee['type'] in known_fee_types: + fee_fields = known_fee_types[fee['type']] + if all([f in fee for f in fee_fields]): + r_dict['key_fee'] = fee['amount'] + r_dict['key_fee_address'] = fee['address'] + else: + for f in ['key_fee', 'key_fee_address']: + if f in r_dict: + del r_dict[f] else: r_dict[field] = value_dict[field] if 'stream_hash' in r_dict and 'txid' in result: @@ -325,10 +338,8 @@ class LBRYWallet(object): value = {"sources": {'lbry_sd_hash': sd_hash}} if description is not None: value['description'] = description - if key_fee is not None: - value['key_fee'] = key_fee - if key_fee_address is not None: - value['key_fee_address'] = key_fee_address + if key_fee is not None and key_fee_address is not None: + value['fee'] = {'type': 'LBC', 'amount': key_fee, 'address': key_fee_address} if thumbnail is not None: value['thumbnail'] = thumbnail if content_license is not None: From dff0fcb1fd9d9d1303036cd361be3d097bd7b4a4 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:58:58 -0500 Subject: [PATCH 5/5] ensure the lbryum wallet is caught up before giving the prompt --- lbrynet/core/LBRYcrdWallet.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index 153b27e56..88a9686ef 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -869,7 +869,7 @@ class LBRYumWallet(LBRYWallet): def setup_network(): self.config = SimpleConfig() self.network = Network(self.config) - alert.info("Starting the wallet...") + alert.info("Loading the wallet...") return defer.succeed(self.network.start()) d = setup_network() @@ -882,7 +882,6 @@ class LBRYumWallet(LBRYWallet): return False start_check.stop() if self.network.is_connected(): - alert.info("Wallet started.") network_start_d.callback(True) else: network_start_d.errback(ValueError("Failed to connect to network.")) @@ -926,9 +925,24 @@ class LBRYumWallet(LBRYWallet): wallet.synchronize() self.wallet = wallet + blockchain_caught_d = defer.Deferred() + + def check_caught_up(): + local_height = self.network.get_local_height() + remote_height = self.network.get_server_height() + + if remote_height != 0 and remote_height - local_height <= 5: + alert.info('Wallet loaded.') + catch_up_check.stop() + blockchain_caught_d.callback(True) + + catch_up_check = task.LoopingCall(check_caught_up) + d = threads.deferToThread(get_wallet) d.addCallback(self._save_wallet) d.addCallback(lambda _: self.wallet.start_threads(self.network)) + d.addCallback(lambda _: catch_up_check.start(.1)) + d.addCallback(lambda _: blockchain_caught_d) return d def _get_cmd_runner(self):