forked from LBRYCommunity/lbry-sdk
fix download_progress in blockchain_headers status
-use a 0-100 range for percentage regardless of how much we have to download (if we're resuming or starting fresh) -prevent negative blocks or blocks_behind counts
This commit is contained in:
parent
36df9e8283
commit
ea481e6c5a
2 changed files with 15 additions and 16 deletions
|
@ -13,8 +13,8 @@ at anytime.
|
|||
*
|
||||
|
||||
### Fixed
|
||||
*
|
||||
*
|
||||
* `download_progress` field in `blockchain_headers` section of `status` not initializing correctly when resuming a download (https://github.com/lbryio/lbry/issues/1355)
|
||||
* `wallet_send` not accepting decimal amounts (https://github.com/lbryio/lbry/issues/1356 commit https://github.com/lbryio/lbry/commit/1098ca0494ece420c70fc57f69d6d388715a99b8)
|
||||
|
||||
### Deprecated
|
||||
*
|
||||
|
@ -25,7 +25,7 @@ at anytime.
|
|||
*
|
||||
|
||||
### Added
|
||||
* `is_locked` to `wallet` in `status` response
|
||||
* `is_locked` to `wallet` in `status` response (https://github.com/lbryio/lbry/issues/1354, commit https://github.com/lbryio/lbry/commit/153022a1a7122ab6d31d3db433dccbe469bbcb3c)
|
||||
*
|
||||
|
||||
### Removed
|
||||
|
|
|
@ -190,33 +190,32 @@ class HeadersComponent(Component):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def fetch_headers_from_s3(self):
|
||||
def collector(data, h_file):
|
||||
h_file.write(data)
|
||||
local_size = float(h_file.tell())
|
||||
final_size = float(final_size_after_download)
|
||||
self._headers_progress_percent = math.ceil(local_size / final_size * 100)
|
||||
|
||||
local_header_size = self.local_header_file_size()
|
||||
self._headers_progress_percent = 0.0
|
||||
resume_header = {"Range": "bytes={}-".format(local_header_size)}
|
||||
response = yield treq.get(HEADERS_URL, headers=resume_header)
|
||||
got_406 = response.code == 406 # our file is bigger
|
||||
final_size_after_download = response.length + local_header_size
|
||||
if got_406:
|
||||
|
||||
def collector(data, h_file, start_size):
|
||||
h_file.write(data)
|
||||
local_size = float(h_file.tell())
|
||||
final_size = float(final_size_after_download)
|
||||
self._headers_progress_percent = math.ceil((local_size - start_size) / (final_size - start_size) * 100)
|
||||
|
||||
if response.code == 406: # our file is bigger
|
||||
log.warning("s3 is more out of date than we are")
|
||||
# should have something to download and a final length divisible by the header size
|
||||
elif final_size_after_download and not final_size_after_download % HEADER_SIZE:
|
||||
s3_height = (final_size_after_download / HEADER_SIZE) - 1
|
||||
local_height = self.local_header_file_height()
|
||||
self._headers_progress_percent = math.ceil(float(local_height) / float(s3_height) * 100.0)
|
||||
if s3_height > local_height:
|
||||
if local_header_size:
|
||||
log.info("Resuming download of %i bytes from s3", response.length)
|
||||
with open(os.path.join(self.config.path, "blockchain_headers"), "a+b") as headers_file:
|
||||
yield treq.collect(response, lambda d: collector(d, headers_file))
|
||||
yield treq.collect(response, lambda d: collector(d, headers_file, local_header_size))
|
||||
else:
|
||||
with open(os.path.join(self.config.path, "blockchain_headers"), "wb") as headers_file:
|
||||
yield treq.collect(response, lambda d: collector(d, headers_file))
|
||||
yield treq.collect(response, lambda d: collector(d, headers_file, 0))
|
||||
log.info("fetched headers from s3 (s3 height: %i), now verifying integrity after download.", s3_height)
|
||||
self._check_header_file_integrity()
|
||||
else:
|
||||
|
@ -321,8 +320,8 @@ class WalletComponent(Component):
|
|||
remote_height = self.wallet.network.get_server_height()
|
||||
best_hash = yield self.wallet.get_best_blockhash()
|
||||
defer.returnValue({
|
||||
'blocks': local_height,
|
||||
'blocks_behind': remote_height - local_height,
|
||||
'blocks': max(local_height, 0),
|
||||
'blocks_behind': max(remote_height - local_height, 0),
|
||||
'best_blockhash': best_hash,
|
||||
'is_encrypted': self.wallet.wallet.use_encryption,
|
||||
'is_locked': not self.wallet.is_wallet_unlocked,
|
||||
|
|
Loading…
Reference in a new issue