Check if auction is already used for a deployment

This commit is contained in:
Prathamesh Musale 2024-10-03 12:45:49 +05:30
parent 1a55bc4df3
commit 37a436b44c
3 changed files with 43 additions and 16 deletions

View File

@ -33,6 +33,7 @@ from stack_orchestrator.deploy.webapp.util import (
LaconicRegistryClient, LaconicRegistryClient,
TimedLogger, TimedLogger,
build_container_image, build_container_image,
confirm_auction,
push_container_image, push_container_image,
file_hash, file_hash,
deploy_to_k8s, deploy_to_k8s,
@ -585,23 +586,20 @@ def command( # noqa: C901
requests_to_execute = [] requests_to_execute = []
for r in requests_to_check_for_payment: for r in requests_to_check_for_payment:
# Check if auction id is set
if r.attributes.auction: if r.attributes.auction:
if auction_requests: if auction_requests:
# Check if the deployer payment address is an auction winner if confirm_auction(
auction_id = r.attributes.auction laconic,
auction = laconic.get_auction(auction_id) r,
if not auction: lrn,
main_logger.log( payment_address,
f"Skipping request {r.id}: unable to locate auction: {auction_id}" main_logger
) ):
dump_known_requests(state_file, [r], status="SKIP") main_logger.log(f"{r.id}: Auction confirmed.")
elif payment_address in auction.winnerAddresses:
main_logger.log(f"{r.id}: auction winnner address confirmed.")
requests_to_execute.append(r) requests_to_execute.append(r)
else: else:
main_logger.log( main_logger.log(
f"Skipping request {r.id}: deployer payment address not found in auction winners." f"Skipping request {r.id}: unable to verify auction."
) )
dump_known_requests(state_file, [r], status="SKIP") dump_known_requests(state_file, [r], status="SKIP")
else: else:

View File

@ -112,6 +112,10 @@ def command( # noqa: C901
if not auction: if not auction:
fatal(f"Unable to locate auction: {auction_id}") fatal(f"Unable to locate auction: {auction_id}")
# Check auction owner
if auction.ownerAddress != laconic.whoami().address:
fatal(f"Auction owner mismatch")
# Check auction kind # Check auction kind
if auction.kind != AUCTION_KIND_PROVIDER: if auction.kind != AUCTION_KIND_PROVIDER:
fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}") fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}")

View File

@ -752,12 +752,15 @@ def publish_deployment(
}, },
} }
} }
if app_deployment_request: if app_deployment_request:
new_deployment_record["record"]["request"] = app_deployment_request.id new_deployment_record["record"]["request"] = app_deployment_request.id
if app_deployment_request.attributes.payment:
new_deployment_record["record"][ # Set auction or payment id from request
"payment" if app_deployment_request.attributes.auction:
] = app_deployment_request.attributes.payment new_deployment_record["record"]["auction"] = app_deployment_request.attributes.auction
elif app_deployment_request.attributes.payment:
new_deployment_record["record"]["payment"] = app_deployment_request.attributes.payment
if webapp_deployer_record: if webapp_deployer_record:
new_deployment_record["record"]["deployer"] = webapp_deployer_record.names[0] new_deployment_record["record"]["deployer"] = webapp_deployer_record.names[0]
@ -873,3 +876,25 @@ def confirm_payment(laconic: LaconicRegistryClient, record, payment_address, min
return False return False
return True return True
def confirm_auction(laconic: LaconicRegistryClient, record, deployer_lrn, payment_address, logger):
auction_id = record.attributes.auction
auction = laconic.get_auction(auction_id)
if not auction:
logger.log(f"{record.id}: unable to locate auction {auction_id}")
return False
# Check if the deployer payment address is in auction winners list
if payment_address not in auction.winnerAddresses:
logger.log(f"{record.id}: deployer payment address not in auction winners.")
return False
# Check if the auction was already used on a deployment
used = laconic.app_deployments({"deployer": deployer_lrn, "auction": auction_id}, all=True)
if len(used):
logger.log(f"{record.id}: auction {auction_id} already used on deployment {used}")
return False
return True