From 8538f55edc4a20a61c8d91b7b577cd6a2b4c524e Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Tue, 16 Mar 2021 16:45:01 +0100 Subject: [PATCH] refactor(core/bitcoin): Use global static buffer for Tx serialization. --- core/src/apps/bitcoin/sign_tx/bitcoin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/apps/bitcoin/sign_tx/bitcoin.py b/core/src/apps/bitcoin/sign_tx/bitcoin.py index 3b03d02cc..dab237cd1 100644 --- a/core/src/apps/bitcoin/sign_tx/bitcoin.py +++ b/core/src/apps/bitcoin/sign_tx/bitcoin.py @@ -36,6 +36,7 @@ if False: # the number of bytes to preallocate for serialized transaction chunks _MAX_SERIALIZED_CHUNK_SIZE = const(2048) +_SERIALIZED_TX_BUFFER = empty_bytearray(_MAX_SERIALIZED_CHUNK_SIZE) class Bitcoin: @@ -77,6 +78,8 @@ class Bitcoin: coin: CoinInfo, approver: approvers.Approver | None, ) -> None: + global _SERIALIZED_TX_BUFFER + self.tx_info = TxInfo(self, helpers.sanitize_sign_tx(tx, coin)) self.keychain = keychain self.coin = coin @@ -93,7 +96,8 @@ class Bitcoin: self.external: set[int] = set() # transaction and signature serialization - self.serialized_tx = empty_bytearray(_MAX_SERIALIZED_CHUNK_SIZE) + _SERIALIZED_TX_BUFFER[:] = bytes() + self.serialized_tx = _SERIALIZED_TX_BUFFER self.tx_req = TxRequest() self.tx_req.details = TxRequestDetailsType() self.tx_req.serialized = TxRequestSerializedType()