From 1c3dfceb308940d857b7a9f9db74d18efe3930cb Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 29 Oct 2024 10:43:06 +0530 Subject: [PATCH 1/2] Allow payment reuse for application redeployment --- .../deploy/webapp/deploy_webapp_from_registry.py | 1 + stack_orchestrator/deploy/webapp/util.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index 4e57659d..88137d33 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -616,6 +616,7 @@ def command( # noqa: C901 if confirm_payment( laconic, r, + lrn, payment_address, min_required_payment, main_logger, diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index dd3bfe96..2be1c007 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -798,7 +798,7 @@ def skip_by_tag(r, include_tags, exclude_tags): return False -def confirm_payment(laconic: LaconicRegistryClient, record, payment_address, min_amount, logger): +def confirm_payment(laconic: LaconicRegistryClient, record, deployer_lrn, payment_address, min_amount, logger): req_owner = laconic.get_owner(record) if req_owner == payment_address: # No need to confirm payment if the sender and recipient are the same account. @@ -846,16 +846,19 @@ def confirm_payment(laconic: LaconicRegistryClient, record, payment_address, min ) return False - # Check if the payment was already used on a + # Check if the payment was already used on a deployment used = laconic.app_deployments( - {"deployer": payment_address, "payment": tx.hash}, all=True + {"deployer": deployer_lrn, "payment": tx.hash}, all=True ) if len(used): - logger.log(f"{record.id}: payment {tx.hash} already used on deployment {used}") - return False + # Check that payment was used for deployment of same application + app_record = laconic.get_record(record.attributes.application, require=True) + if app_record.id != used[0].attributes.application: + logger.log(f"{record.id}: payment {tx.hash} already used on a different application deployment {used}") + return False used = laconic.app_deployment_removals( - {"deployer": payment_address, "payment": tx.hash}, all=True + {"deployer": deployer_lrn, "payment": tx.hash}, all=True ) if len(used): logger.log( -- 2.45.2 From d661f478f74b96f69afa1d9ff554d4db43808d70 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 29 Oct 2024 11:20:01 +0530 Subject: [PATCH 2/2] Use deployer LRN from request record --- .../deploy/webapp/deploy_webapp_from_registry.py | 1 - stack_orchestrator/deploy/webapp/util.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index 88137d33..4e57659d 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -616,7 +616,6 @@ def command( # noqa: C901 if confirm_payment( laconic, r, - lrn, payment_address, min_required_payment, main_logger, diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index 2be1c007..5f670270 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -798,7 +798,7 @@ def skip_by_tag(r, include_tags, exclude_tags): return False -def confirm_payment(laconic: LaconicRegistryClient, record, deployer_lrn, payment_address, min_amount, logger): +def confirm_payment(laconic: LaconicRegistryClient, record, payment_address, min_amount, logger): req_owner = laconic.get_owner(record) if req_owner == payment_address: # No need to confirm payment if the sender and recipient are the same account. @@ -848,7 +848,7 @@ def confirm_payment(laconic: LaconicRegistryClient, record, deployer_lrn, paymen # Check if the payment was already used on a deployment used = laconic.app_deployments( - {"deployer": deployer_lrn, "payment": tx.hash}, all=True + {"deployer": record.attributes.deployer, "payment": tx.hash}, all=True ) if len(used): # Check that payment was used for deployment of same application @@ -858,7 +858,7 @@ def confirm_payment(laconic: LaconicRegistryClient, record, deployer_lrn, paymen return False used = laconic.app_deployment_removals( - {"deployer": deployer_lrn, "payment": tx.hash}, all=True + {"deployer": record.attributes.deployer, "payment": tx.hash}, all=True ) if len(used): logger.log( -- 2.45.2