Skip to content

Commit

Permalink
Merge pull request #1775 from boschresearch/feature/rev-sort-config
Browse files Browse the repository at this point in the history
Add flag for sorting algorithm switching
  • Loading branch information
WadeBarnes authored Sep 12, 2022
2 parents 9cedcb3 + 00d884f commit a715393
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 7 deletions.
3 changes: 3 additions & 0 deletions indy_common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@
DIDDOC_CONTENT_SIZE_LIMIT = 10 * 1024

ENABLE_RICH_SCHEMAS = False

# Disables the legacy sorting
REV_STRATEGY_USE_COMPAT_ORDERING = False
28 changes: 22 additions & 6 deletions indy_node/server/revocation_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from indy_common.compat_set import CompatSet
from indy_common.state import domain
from indy_common.types import Request
from indy_common.config_util import getConfig
from indy_common.constants import REVOC_REG_DEF_ID, VALUE, ACCUM, PREV_ACCUM, ISSUED, REVOKED
from plenum.common.exceptions import InvalidClientRequest
from plenum.common.txn_util import get_from, get_req_id, get_payload_data
Expand All @@ -17,6 +18,7 @@ def __init__(self, state):
self.author_did = None
self.revoc_reg_def_id = None
self.req_id = None
self.sort_legacy = getConfig().REV_STRATEGY_USE_COMPAT_ORDERING or False

def set_parameters_from_txn(self, author_did, revoc_reg_def_id, req_id):
self.author_did = author_did
Expand Down Expand Up @@ -138,10 +140,17 @@ def write(self, current_reg_entry, txn):
issued_from_txn = value_from_txn.get(ISSUED, [])
revoked_from_txn = value_from_txn.get(REVOKED, [])
# set with all previous revoked minus issued from txn
result_indicies = CompatSet(indices).difference(issued_from_txn)
result_indicies.update(revoked_from_txn)
if self.sort_legacy:
result_indicies = CompatSet(indices).difference(issued_from_txn)
result_indicies.update(revoked_from_txn)
result_indicies = list(result_indicies)
else:
result_indicies = set(indices).difference(issued_from_txn)
result_indicies.update(revoked_from_txn)
result_indicies = list(result_indicies)
result_indicies.sort()
value_from_txn[ISSUED] = []
value_from_txn[REVOKED] = list(result_indicies)
value_from_txn[REVOKED] = result_indicies
txn_data[VALUE] = value_from_txn
# contains already changed txn
self.set_to_state(txn)
Expand Down Expand Up @@ -196,10 +205,17 @@ def write(self, current_reg_entry, txn):
issued_from_txn = value_from_txn.get(ISSUED, [])
revoked_from_txn = value_from_txn.get(REVOKED, [])
# set with all previous issued minus revoked from txn
result_indicies = CompatSet(indices).difference(revoked_from_txn)
result_indicies.update(issued_from_txn)
if self.sort_legacy:
result_indicies = CompatSet(indices).difference(revoked_from_txn)
result_indicies.update(issued_from_txn)
result_indicies = list(result_indicies)
else:
result_indicies = set(indices).difference(revoked_from_txn)
result_indicies.update(issued_from_txn)
result_indicies = list(result_indicies)
result_indicies.sort()
value_from_txn[REVOKED] = []
value_from_txn[ISSUED] = list(result_indicies)
value_from_txn[ISSUED] = result_indicies
txn_data[VALUE] = value_from_txn
# contains already changed txn
self.set_to_state(txn)
Expand Down
76 changes: 75 additions & 1 deletion indy_node/test/request_handlers/test_revoc_reg_entry_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from random import random
import pytest

from indy_common.constants import REVOC_REG_ENTRY, REVOC_REG_DEF_ID, ISSUANCE_BY_DEFAULT, \
VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM
VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM, REVOC_REG_DEF, CRED_DEF_ID, REVOC_TYPE, TAG
from indy_common.config_util import getConfig
from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_def_handler import RevocRegDefHandler
from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_entry_handler import RevocRegEntryHandler
from indy_node.test.request_handlers.conftest import revoc_reg_def_request
from indy_node.test.request_handlers.helper import add_to_idr
from plenum.common.constants import TXN_TIME, TRUSTEE

Expand Down Expand Up @@ -124,3 +127,74 @@ def test_update_state(revoc_reg_entry_handler, revoc_reg_entry_request,
txn_data[VALUE] = {ACCUM: txn_data[VALUE][ACCUM]}
path, _ = RevocRegEntryHandler.prepare_revoc_reg_entry_accum_for_state(txn)
assert revoc_reg_entry_handler.get_from_state(path) == (txn_data, seq_no, txn_time)


def test_legacy_switch_by_default_new(revoc_reg_entry_handler, revoc_reg_entry_request,
revoc_reg_def_handler):
# Default case -> False
config = getConfig()
assert config.REV_STRATEGY_USE_COMPAT_ORDERING is False

state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
revoc_reg_def_handler)
assert state[VALUE][REVOKED] == [5, 6, 12, 13]


def test_legacy_switch_by_default_old(revoc_reg_entry_handler, revoc_reg_entry_request,
revoc_reg_def_handler):
# Set to true -> enables Usage of CompatSet
config = getConfig()
config.REV_STRATEGY_USE_COMPAT_ORDERING = True

state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
revoc_reg_def_handler)
assert state[VALUE][REVOKED] == [12, 13, 5, 6]


def _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
revoc_reg_def_handler):
# create revoc_req_def
seq_no = 1
txn_time = 1560241030
# Force a new rev reg def for these tests
revoc_reg_def_request = Request(identifier=randomString(),
reqId=5,
signature="sig",
operation={'type': REVOC_REG_DEF,
CRED_DEF_ID: "credDefId",
REVOC_TYPE: randomString(),
TAG: randomString(),
})

revoc_reg_def_request.operation[VALUE] = {}
revoc_reg_def_request.operation[VALUE][ISSUANCE_TYPE] = ISSUANCE_BY_DEFAULT
# New random string to create new registry
txn = reqToTxn(revoc_reg_def_request)
append_txn_metadata(txn, seq_no, txn_time)
path = RevocRegDefHandler.prepare_revoc_def_for_state(txn,
path_only=True)
revoc_reg_def_handler.update_state(txn, None, revoc_reg_def_request)

# create first revoc_req_entry
seq_no = 2
txn_time = 1560241033
revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode()
revoc_reg_entry_request.operation[VALUE][ISSUED] = []
revoc_reg_entry_request.operation[VALUE][REVOKED] = [4, 5, 6, 12]
txn = reqToTxn(revoc_reg_entry_request)
append_txn_metadata(txn, seq_no, txn_time)
revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request)

# create second revoc_req_entry
seq_no = 3
txn_time = 1560241042
revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode()
revoc_reg_entry_request.operation[VALUE][ISSUED] = [4]
revoc_reg_entry_request.operation[VALUE][REVOKED] = [13]
txn = reqToTxn(revoc_reg_entry_request)
append_txn_metadata(txn, seq_no, txn_time)
revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request)
state = revoc_reg_entry_handler.get_from_state(
RevocRegEntryHandler.prepare_revoc_reg_entry_for_state(txn,
path_only=True))
return state[0]

0 comments on commit a715393

Please sign in to comment.