Traffic Based App Rewards: Compute Hashes#4847
Conversation
dfordivam
left a comment
There was a problem hiding this comment.
Posting some comment, still doing the review of sqls
| * Uses a LEFT JOIN from activity totals to reward totals because parties | ||
| * whose reward fell below the threshold have no row in `app_reward_party_totals`. |
There was a problem hiding this comment.
This sounds off. It sounds like we are numbering the parties that had activity instead of numbering the ones that have rewards, could that be the case?
I might have accidentally caused that with a premature optimization to use party_seq_num for activity totals already.
There was a problem hiding this comment.
Fixed: This has been addressed. Note that the schema changed here as suggested in other review comments
| r.total_app_reward_amount::text as amount, | ||
| (a.app_provider_party_seq_num / $batchSize) as batch_num | ||
| from #${Tables.appActivityPartyTotals} a | ||
| left join #${Tables.appRewardPartyTotals} r |
There was a problem hiding this comment.
From our discussion:
- We don't need to include parties with 0 rewards.
- Only use the reward party totals table. If possible, structure queries such that they only depend on the immediately preceding stage.
- In this case, can we move
app_provider_party_seq_numto the rewards table (only numbering the above-threshold parties), and thus avoid the join?
There was a problem hiding this comment.
Thanks, I was looking around where we noted down this comment.😅
After carefully going through the schema now I understood the issue. We can't use LEFT JOIN with the guarantee of always getting the party, and using JOIN is a code smell (or worse). So in this case moving party to app_reward_party_totals, and having app_provider_party_seq_num in it is the better choice
This would also mean that seq_num_begin seq_num_end would be contiguous, ie end=begin+batch_size.
| batch_type: | ||
| type: string | ||
| enum: [BatchOfBatches, BatchOfMintingAllowances] | ||
| child_hashes: |
There was a problem hiding this comment.
child_hashes and minting_allowances are mutually exclusive, have you considered using oneOf (it's used in a few other places in scan.yaml)?
| from #${Tables.appRewardBatchHashes} | ||
| where history_id = $historyId and round_number = $roundNumber | ||
| and batch_level = ( | ||
| select max(batch_level) from #${Tables.appRewardBatchHashes} |
There was a problem hiding this comment.
There is no index on the batch level. Is there some mechanism that keeps the table small, so that we can afford a full table scan? For example, are we planning on removing batches from the table once the rewards are issued?
Alternatively, you can have aggregateToRoot return the level of the root.
There was a problem hiding this comment.
As there are two other places with batch_level query, it makes sense to add the index. (insertNextLevel and getChildBatchHashes)
| rootHash shouldBe defined | ||
| rootHash.value.rootHash.size shouldBe 32 | ||
| latestRound.value shouldBe roundNumber |
There was a problem hiding this comment.
Would it make sense to include these checks in all other tests, instead of only checking the root hash in a single scenario?
| } | ||
| } | ||
|
|
||
| "computeRewardHashes — below-threshold party hashes same as explicit zero amount" in { |
There was a problem hiding this comment.
This test is not needed anymore if we exclude below-threshold parties in insertLeafBatches.
| ) | ||
| ) | ||
| action | ||
| .map(_ => logger.debug(s"Computed reward hashes for round $roundNumber.")) |
There was a problem hiding this comment.
This will only log once every 10min, I think this can be an INFO level log. If you have readily available details (number of leaves, number of levels, ...), include them in the message. Such details are very useful for investigating issues during testing.
| from #${Tables.appRewardBatchHashes} | ||
| where history_id = $historyId | ||
| and round_number = $roundNumber | ||
| and batch_hash = ${batchHash.toByteArray} |
There was a problem hiding this comment.
We're converting ByteString -> Array[Byte] here, and Array[Byte] -> ByteString when reading the hash in getResultAppRewardBatchHash. Ideally, we would only convert types when reading/writing HTTP requests/responses.
Would it make sense to create a named case class for the hash, where the value is stored as Array[Byte] (or whatever results in the least amount of conversions), and with methods to convert it to/from the HTTP representation?
|
An issue I noticed; |
IIRC, this was discussed at the planning meeting for this feature branch. In such a unit test, one is really just checking the interaction between computeAndStoreRewards and the functions it calls that have been themselves unit-tested
@dfordivam: What do you have in mind, any of these or something else ? |
Well naturally "it depends on context". One scenario likely not covered by integration tests is the throw by |
d224320 to
1a7d985
Compare
Added these tests |
| * | ||
| * Used for rounds where no parties are above the reward threshold. | ||
| * Inserting this as a level-0 batch and root hash marks the round as | ||
| * computed, so that ComputeAppRewardsTrigger does not retry it, and |
There was a problem hiding this comment.
ComputeAppRewardsTrigger has been mentioned twice in this file, should be RewardComputationTrigger ?
|
@rautenrieth-da, I think all the comments have been addressed, PTAL |
9e1d0dd to
c460acb
Compare
rautenrieth-da
left a comment
There was a problem hiding this comment.
Thanks! The PR looks good to me now, the merge conflicts should be easy to resolve.
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
…g tables - numbers only parties that have rewards rather than activity - remove from app_activty_party_totals where it will no longer be needed - introduce it in app_reward_party_totals which only contains thresholded parties Signed-off-by: Tim Emiola <adetokunbo@emio.la>
- they now read only from app_reward_party_totals - Now that app_reward_party_totals carries app_provider_party and its own contiguous seq_nums, the LEFT JOIN back to app_activity_party_totals and the COALESCE fallback for below-threshold parties are unnecessary. - Updates various affect unittests - Improves the scaladoc comments to clarify what role the steps are playing Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
…ray[Byte] Signed-off-by: Tim Emiola <adetokunbo@emio.la>
…eRewards Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
… error Signed-off-by: Tim Emiola <adetokunbo@emio.la>
c460acb to
4a93cdb
Compare
49e4f60
into
adetokunbo/feature-cip-104-scan-computation
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Merges the feature branch for the scan computation part of CIP-104, consisting of the following individual PRs: * Add app activity computation store and schema (#4372) * Compute aggregateActivityTotals, add ComputeAppRewardTrigger, expose new endpoints (#4420) * Adds computeRewardTotals to DbScanAppRewardsStore (#4639) * Add DB versions of Splice.Amulet.CryptoHash (#4662) * Expand GetRewardAccountingActivityTotalsResponse (#4859) * Add counters to RewardComputationTrigger (#4860) * Compute Hashes (#4847) Signed-off-by: Tim Emiola <adetokunbo@emio.la> Signed-off-by: Timothy Emiola <adetokunbo@users.noreply.github.com> Co-authored-by: Simon Meier <simon@digitalasset.com> Co-authored-by: Robert Autenrieth <31539813+rautenrieth-da@users.noreply.github.com>
Fixes #4382
Follows #4662
Tracked in #4384
Pull Request Checklist
Cluster Testing
/cluster_teston this PR to request it, and ping someone with access to the DA-internal system to approve it./hdm_teston this PR to request it, and ping someone with access to the DA-internal system to approve it./lsu_teston this PR to request it, and ping someone with access to the DA-internal system to approve it.PR Guidelines
Fixes #n, and mention issues worked on using#nMerge Guidelines