Fix/add lock acapy 012#7
Open
Alisson-tech wants to merge 3 commits into
Open
Conversation
Alisson-tech
commented
Jul 6, 2026
| CATEGORY_REV_REG_DEF = "revocation_reg_def" | ||
| CATEGORY_REV_REG_DEF_PRIVATE = "revocation_reg_def_private" | ||
| CATEGORY_REV_REG_ISSUER = "revocation_reg_def_issuer" | ||
| CATEGORY_REV_REG_DEF_LOCK = "revocation_reg_def_lock" |
Alisson-tech
commented
Jul 6, 2026
| "Revocation registry definition private data not found" | ||
| # If an index was already pre-allocated by the caller (using a distributed lock), | ||
| # we don't need a transaction to increment it here. We just fetch the current state. | ||
| if preallocated_rev_reg_index is not None: |
Author
There was a problem hiding this comment.
Verifica se o rev_reg_index está disponível ou foi preallocado por outra requisição
Alisson-tech
commented
Jul 6, 2026
|
|
||
| async def _get_and_reserve_revocation_index( | ||
| self, cred_def_id: str | ||
| ) -> Tuple[bool, Optional[str], Optional[str], Optional[int]]: |
Author
There was a problem hiding this comment.
Método para reservar o index do lock
Alisson-tech
commented
Jul 6, 2026
| rev_info_tags = rev_list_entry.tags | ||
| rev_reg_index = rev_info["next_index"] | ||
|
|
||
| if rev_reg_index >= anoncreds_rev_reg_def.max_cred_num: |
Author
There was a problem hiding this comment.
Se mantém a lógica anterior a rotação acontece no penultimo index:
max_cred_def = 500
rotação = 499
Lembrando que o index 0 é ignorado no acapy (base 1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto & Problema
Durante testes de carga com emissões simultâneas de credenciais revogáveis, o ACA-Py apresentou falhas de concorrência. Ao receber múltiplas requisições paralelas para a mesma definição de credencial, ocorriam condições de corrida (race conditions) na reserva de índices do registro de revogação e na inicialização da rotação do arquivo Tails. Esse conflito corrompia o estado das transações no banco de dados e interrompia o fluxo de emissão.
Solução Proposta
Lock Pessimista no Banco de Dados: Adicionamos um lock pessimista no momento em que o agente consulta e reserva o índice no registro de revogação.
Garantia de Integridade: O recurso (revocation_registry_definition e seus índices) fica travado transacionalmente durante o acesso concorrente da credencial corrente, enfileirando de forma segura as próximas requisições de escrita.
Impacto
Eliminação de colisões de índices sob alta concorrência.
Maior segurança e robustez transacional no banco de dados.
Estabilidade no processo automático de rotação de registros sob picos de carga.