Skip to content

Commit a715393

Browse files
authored
Merge pull request #1775 from boschresearch/feature/rev-sort-config
Add flag for sorting algorithm switching
2 parents 9cedcb3 + 00d884f commit a715393

File tree

3 files changed

+100
-7
lines changed

3 files changed

+100
-7
lines changed

Diff for: indy_common/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@
116116
DIDDOC_CONTENT_SIZE_LIMIT = 10 * 1024
117117

118118
ENABLE_RICH_SCHEMAS = False
119+
120+
# Disables the legacy sorting
121+
REV_STRATEGY_USE_COMPAT_ORDERING = False

Diff for: indy_node/server/revocation_strategy.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from indy_common.compat_set import CompatSet
66
from indy_common.state import domain
77
from indy_common.types import Request
8+
from indy_common.config_util import getConfig
89
from indy_common.constants import REVOC_REG_DEF_ID, VALUE, ACCUM, PREV_ACCUM, ISSUED, REVOKED
910
from plenum.common.exceptions import InvalidClientRequest
1011
from plenum.common.txn_util import get_from, get_req_id, get_payload_data
@@ -17,6 +18,7 @@ def __init__(self, state):
1718
self.author_did = None
1819
self.revoc_reg_def_id = None
1920
self.req_id = None
21+
self.sort_legacy = getConfig().REV_STRATEGY_USE_COMPAT_ORDERING or False
2022

2123
def set_parameters_from_txn(self, author_did, revoc_reg_def_id, req_id):
2224
self.author_did = author_did
@@ -138,10 +140,17 @@ def write(self, current_reg_entry, txn):
138140
issued_from_txn = value_from_txn.get(ISSUED, [])
139141
revoked_from_txn = value_from_txn.get(REVOKED, [])
140142
# set with all previous revoked minus issued from txn
141-
result_indicies = CompatSet(indices).difference(issued_from_txn)
142-
result_indicies.update(revoked_from_txn)
143+
if self.sort_legacy:
144+
result_indicies = CompatSet(indices).difference(issued_from_txn)
145+
result_indicies.update(revoked_from_txn)
146+
result_indicies = list(result_indicies)
147+
else:
148+
result_indicies = set(indices).difference(issued_from_txn)
149+
result_indicies.update(revoked_from_txn)
150+
result_indicies = list(result_indicies)
151+
result_indicies.sort()
143152
value_from_txn[ISSUED] = []
144-
value_from_txn[REVOKED] = list(result_indicies)
153+
value_from_txn[REVOKED] = result_indicies
145154
txn_data[VALUE] = value_from_txn
146155
# contains already changed txn
147156
self.set_to_state(txn)
@@ -196,10 +205,17 @@ def write(self, current_reg_entry, txn):
196205
issued_from_txn = value_from_txn.get(ISSUED, [])
197206
revoked_from_txn = value_from_txn.get(REVOKED, [])
198207
# set with all previous issued minus revoked from txn
199-
result_indicies = CompatSet(indices).difference(revoked_from_txn)
200-
result_indicies.update(issued_from_txn)
208+
if self.sort_legacy:
209+
result_indicies = CompatSet(indices).difference(revoked_from_txn)
210+
result_indicies.update(issued_from_txn)
211+
result_indicies = list(result_indicies)
212+
else:
213+
result_indicies = set(indices).difference(revoked_from_txn)
214+
result_indicies.update(issued_from_txn)
215+
result_indicies = list(result_indicies)
216+
result_indicies.sort()
201217
value_from_txn[REVOKED] = []
202-
value_from_txn[ISSUED] = list(result_indicies)
218+
value_from_txn[ISSUED] = result_indicies
203219
txn_data[VALUE] = value_from_txn
204220
# contains already changed txn
205221
self.set_to_state(txn)

Diff for: indy_node/test/request_handlers/test_revoc_reg_entry_handler.py

+75-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from random import random
12
import pytest
23

34
from indy_common.constants import REVOC_REG_ENTRY, REVOC_REG_DEF_ID, ISSUANCE_BY_DEFAULT, \
4-
VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM
5+
VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM, REVOC_REG_DEF, CRED_DEF_ID, REVOC_TYPE, TAG
6+
from indy_common.config_util import getConfig
57
from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_def_handler import RevocRegDefHandler
68
from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_entry_handler import RevocRegEntryHandler
9+
from indy_node.test.request_handlers.conftest import revoc_reg_def_request
710
from indy_node.test.request_handlers.helper import add_to_idr
811
from plenum.common.constants import TXN_TIME, TRUSTEE
912

@@ -124,3 +127,74 @@ def test_update_state(revoc_reg_entry_handler, revoc_reg_entry_request,
124127
txn_data[VALUE] = {ACCUM: txn_data[VALUE][ACCUM]}
125128
path, _ = RevocRegEntryHandler.prepare_revoc_reg_entry_accum_for_state(txn)
126129
assert revoc_reg_entry_handler.get_from_state(path) == (txn_data, seq_no, txn_time)
130+
131+
132+
def test_legacy_switch_by_default_new(revoc_reg_entry_handler, revoc_reg_entry_request,
133+
revoc_reg_def_handler):
134+
# Default case -> False
135+
config = getConfig()
136+
assert config.REV_STRATEGY_USE_COMPAT_ORDERING is False
137+
138+
state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
139+
revoc_reg_def_handler)
140+
assert state[VALUE][REVOKED] == [5, 6, 12, 13]
141+
142+
143+
def test_legacy_switch_by_default_old(revoc_reg_entry_handler, revoc_reg_entry_request,
144+
revoc_reg_def_handler):
145+
# Set to true -> enables Usage of CompatSet
146+
config = getConfig()
147+
config.REV_STRATEGY_USE_COMPAT_ORDERING = True
148+
149+
state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
150+
revoc_reg_def_handler)
151+
assert state[VALUE][REVOKED] == [12, 13, 5, 6]
152+
153+
154+
def _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request,
155+
revoc_reg_def_handler):
156+
# create revoc_req_def
157+
seq_no = 1
158+
txn_time = 1560241030
159+
# Force a new rev reg def for these tests
160+
revoc_reg_def_request = Request(identifier=randomString(),
161+
reqId=5,
162+
signature="sig",
163+
operation={'type': REVOC_REG_DEF,
164+
CRED_DEF_ID: "credDefId",
165+
REVOC_TYPE: randomString(),
166+
TAG: randomString(),
167+
})
168+
169+
revoc_reg_def_request.operation[VALUE] = {}
170+
revoc_reg_def_request.operation[VALUE][ISSUANCE_TYPE] = ISSUANCE_BY_DEFAULT
171+
# New random string to create new registry
172+
txn = reqToTxn(revoc_reg_def_request)
173+
append_txn_metadata(txn, seq_no, txn_time)
174+
path = RevocRegDefHandler.prepare_revoc_def_for_state(txn,
175+
path_only=True)
176+
revoc_reg_def_handler.update_state(txn, None, revoc_reg_def_request)
177+
178+
# create first revoc_req_entry
179+
seq_no = 2
180+
txn_time = 1560241033
181+
revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode()
182+
revoc_reg_entry_request.operation[VALUE][ISSUED] = []
183+
revoc_reg_entry_request.operation[VALUE][REVOKED] = [4, 5, 6, 12]
184+
txn = reqToTxn(revoc_reg_entry_request)
185+
append_txn_metadata(txn, seq_no, txn_time)
186+
revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request)
187+
188+
# create second revoc_req_entry
189+
seq_no = 3
190+
txn_time = 1560241042
191+
revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode()
192+
revoc_reg_entry_request.operation[VALUE][ISSUED] = [4]
193+
revoc_reg_entry_request.operation[VALUE][REVOKED] = [13]
194+
txn = reqToTxn(revoc_reg_entry_request)
195+
append_txn_metadata(txn, seq_no, txn_time)
196+
revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request)
197+
state = revoc_reg_entry_handler.get_from_state(
198+
RevocRegEntryHandler.prepare_revoc_reg_entry_for_state(txn,
199+
path_only=True))
200+
return state[0]

0 commit comments

Comments
 (0)