зеркало из https://github.com/microsoft/CCF.git
Python ledger tweaks (#2677)
This commit is contained in:
Родитель
f71a37dc01
Коммит
dca2cfe182
|
@ -88,7 +88,7 @@ Alternatively, ``read_ledger.py`` can parse the content of a snapshot file:
|
|||
|
||||
.. note::
|
||||
|
||||
The output of the ``read_ledger.py`` utility can be filtered by key-value store :ref:`table <build_apps/kv/kv_how_to/Creating a Map>` using the ``--tables <regex>`` arguments, e.g.:
|
||||
The output of the ``read_ledger.py`` utility can be filtered by :ref:`key-value store table <build_apps/kv/kv_how_to:Creating a Map>` using the ``--tables <regex>`` arguments, e.g.:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
@ -129,4 +129,4 @@ API
|
|||
:members:
|
||||
|
||||
.. automodule:: ccf.receipt
|
||||
:members:
|
||||
:members:
|
|
@ -221,11 +221,11 @@ class PublicDomain:
|
|||
|
||||
|
||||
def _byte_read_safe(file, num_of_bytes):
|
||||
offset = file.tell()
|
||||
ret = file.read(num_of_bytes)
|
||||
if len(ret) != num_of_bytes:
|
||||
raise ValueError(
|
||||
"Failed to read precise number of bytes: %u, actual = %u"
|
||||
% (num_of_bytes, len(ret))
|
||||
f"Failed to read precise number of bytes in {file.name} at offset {offset}: {len(ret)}/{num_of_bytes}"
|
||||
)
|
||||
return ret
|
||||
|
||||
|
@ -702,25 +702,16 @@ class Ledger:
|
|||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def signature_count(self):
|
||||
return self._ledger_validator.signature_count
|
||||
|
||||
def last_verified_txid(self):
|
||||
return TxID(
|
||||
self._ledger_validator.last_verified_view,
|
||||
self._ledger_validator.last_verified_seqno,
|
||||
)
|
||||
|
||||
def get_transaction(self, seqno: int) -> Transaction:
|
||||
"""
|
||||
Return the :py:class:`ccf.Ledger.Transaction` recorded in the ledger at the given sequence number.
|
||||
Return the :py:class:`ccf.ledger.Transaction` recorded in the ledger at the given sequence number.
|
||||
|
||||
Note that the transaction returned may not yet be verified by a
|
||||
signature transaction nor committed by the service.
|
||||
|
||||
:param int seqno: Sequence number of the transaction to fetch.
|
||||
|
||||
:return: :py:class:`ccf.Ledger.Transaction`
|
||||
:return: :py:class:`ccf.ledger.Transaction`
|
||||
"""
|
||||
if seqno < 1:
|
||||
raise ValueError("Ledger first seqno is 1")
|
||||
|
@ -775,6 +766,29 @@ class Ledger:
|
|||
|
||||
return public_tables, latest_seqno
|
||||
|
||||
def signature_count(self) -> int:
|
||||
"""
|
||||
Return the number of verified signature transactions in the *parsed* ledger.
|
||||
|
||||
Note: The ledger should first be parsed before calling this function.
|
||||
|
||||
:return int: Number of verified signature transactions.
|
||||
"""
|
||||
return self._ledger_validator.signature_count
|
||||
|
||||
def last_verified_txid(self) -> TxID:
|
||||
"""
|
||||
Return the :py:class:`ccf.tx_id.TxID` of the last verified signature transaction in the *parsed* ledger.
|
||||
|
||||
Note: The ledger should first be parsed before calling this function.
|
||||
|
||||
:return: :py:class:`ccf.tx_id.TxID`
|
||||
"""
|
||||
return TxID(
|
||||
self._ledger_validator.last_verified_view,
|
||||
self._ledger_validator.last_verified_seqno,
|
||||
)
|
||||
|
||||
|
||||
class InvalidRootException(Exception):
|
||||
"""MerkleTree root doesn't match with the root reported in the signature's table"""
|
||||
|
|
|
@ -118,13 +118,18 @@ if __name__ == "__main__":
|
|||
LOG.info(f"Reading ledger from {ledger_dirs}")
|
||||
LOG.info(f"Contains {counted_string(ledger, 'chunk')}")
|
||||
|
||||
for chunk in ledger:
|
||||
try:
|
||||
for chunk in ledger:
|
||||
LOG.info(
|
||||
f"chunk {chunk.filename()} ({'' if chunk.is_committed() else 'un'}committed)"
|
||||
)
|
||||
for transaction in chunk:
|
||||
dump_entry(transaction, table_filter)
|
||||
except Exception as e:
|
||||
LOG.exception(f"Error parsing ledger: {e}")
|
||||
else:
|
||||
LOG.success("Ledger verification complete")
|
||||
finally:
|
||||
LOG.info(
|
||||
f"chunk {chunk.filename()} ({'' if chunk.is_committed() else 'un'}committed)"
|
||||
f"Found {ledger.signature_count()} signatures, and verified until {ledger.last_verified_txid()}"
|
||||
)
|
||||
for transaction in chunk:
|
||||
dump_entry(transaction, table_filter)
|
||||
|
||||
LOG.success(
|
||||
f"Ledger verification complete. Found {ledger.signature_count()} signatures, and verified until {ledger.last_verified_txid()}"
|
||||
)
|
||||
|
|
Загрузка…
Ссылка в новой задаче