commit 449a748b8272fd355c9759c3a6666fb72a865abe
parent e29bc6fa8c511264d40f6f6f0d8b4c2f6fb6c233
Author: nolash <dev@holbrook.no>
Date: Mon, 5 Apr 2021 12:59:45 +0200
Add external session to tx obsolete method
Diffstat:
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/chainqueue/state.py b/chainqueue/state.py
@@ -301,8 +301,9 @@ def get_state_log(chain_spec, tx_hash, session=None):
-def cancel_obsoletes_by_cache(chain_spec, tx_hash):
- session = SessionBase.create_session()
+def obsolete_by_cache(chain_spec, tx_hash, final, session=None):
+ session = SessionBase.bind_session(session)
+
q = session.query(
Otx.nonce.label('nonce'),
TxCache.sender.label('sender'),
@@ -324,7 +325,8 @@ def cancel_obsoletes_by_cache(chain_spec, tx_hash):
for otwo in q.all():
try:
- otwo.cancel(True, session=session)
+ otwo.cancel(final, session=session)
+ logg.debug('cancel {} final {}'.format(tx_hash, final))
except TxStateChangeError as e:
logg.exception('cancel non-final fail: {}'.format(e))
session.close()
@@ -334,6 +336,7 @@ def cancel_obsoletes_by_cache(chain_spec, tx_hash):
session.close()
raise(e)
session.commit()
- session.close()
+
+ SessionBase.release_session(session)
return tx_hash