Open sentientforest opened 20 hours ago
Would the fix have any effect on FetchAllowances
requests where the only filter is grantedTo
?
@mistval - no, requests that leave out other TokenAllowance
ChainKey
s, like additionalKey
, instance
, allowanceType
, would not be affected. They would still execute a range query with a larger results set and then filter by grantedTo
after the fact.
Fix here: https://github.com/GalaChain/sdk/pull/382
Existing tests pass. But our current tests don't have a straightforward way to test two transactions executing in the same block so for expediency I have not added new tests with the above.
Finished some updates to the public SDK's e2e test facilities. Replicated bug and fix with a new e2e test in chaincode-template
:
Given the following:
https://github.com/GalaChain/sdk/blob/main/chaincode/src/allowances/fetchAllowances.ts#L32-L55
https://github.com/GalaChain/sdk/blob/main/chain-api/src/types/TokenAllowance.ts#L68-L71
When we encounter a hypothetical scenario such as:
AllowanceType.Burn
Then we will see
PHANTOM_READ
conflicts due to:Even if all
ChainKey
s, 1 through 7, are provided to theFetchAllowances
method, fromowner
through tograntedBy
, the range queries' specificity will still only be limited to theallowanceType
and it will filter bygrantedBy
after the fact.So if multiple users are granting some allowance to a game admin, and then attempting to fetch/use their own specific allowances concurrently, the read set on their individual transactions will include a range read with all other users
grantedBy
values, even though their write set only includes their own individualTokenAllowance
write.Propose adding some small logic such that
a)
grantedBy
is included in thetakeUntilUndefined()
query and b)filterByGrantedBy
is not executed if all keys up to and includinggrantedBy
were previously provided to thegetObjectsByPartialCompositeKey()
query.