Skip to content

SV-app add CalculateRewardsTrigger and ProcessRewardsTrigger#5552

Open
dfordivam wants to merge 37 commits into
dfordivam/cip-104-dry-run-sv-triggers-basefrom
dfordivam/cip-104-dry-run-sv-triggers
Open

SV-app add CalculateRewardsTrigger and ProcessRewardsTrigger#5552
dfordivam wants to merge 37 commits into
dfordivam/cip-104-dry-run-sv-triggers-basefrom
dfordivam/cip-104-dry-run-sv-triggers

Conversation

@dfordivam
Copy link
Copy Markdown
Contributor

Fixes: #4844

Pull Request Checklist

Cluster Testing

  • If a cluster test is required, comment /cluster_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a hard-migration test is required (from the latest release), comment /hdm_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a logical synchronizer upgrade test is required (from canton-3.5), comment /lsu_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.

PR Guidelines

  • Include any change that might be observable by our partners or affect their deployment in the release notes.
  • Specify fixed issues with Fixes #n, and mention issues worked on using #n
  • Include a screenshot for frontend-related PRs - see README or use your favorite screenshot tool

Merge Guidelines

  • Make the git commit message look sensible when squash-merging on GitHub (most likely: just copy your PR description).

Copy link
Copy Markdown
Contributor

@meiersi-da meiersi-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks a lot! Great to see of this coming together @dfordivam and @adetokunbo 👏

@adetokunbo : note that I gave quite a few pointers wrt the usage of triggers, task outcomes, and retries. Please have a look, as you are going to work on a trigger as well this week.

In general, when implementing a trigger it's always worth to check its logging behavior carefully and think about whether these logs are "right" for the work the trigger is doing. Filtering to the trigger name in lnav gets that job done quite well.

.transformWith {
case Failure(ex) =>
Future.failed(
new RuntimeException("Failed to connect to scan for root hash lookup", ex)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely be noisy in production. Scan can be down. Best is probably to just let the errors bubble up and be handled by our retry infrastructure.

Also: it seems that you are creating a fresh scan connection per task. Is this what's done in other parts of the codebase as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed this by returning None, The scan connection situation is a bit complicated actually as we will not be able to likely make use of existing abstractions being used in sv-app. My idea is to remove this ephemeral connection later when BFT support is added, such that both are provided through a well designed abstraction. So I have just added a TODO for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced fresh scan connection with a long lived one, as discussed yesterday.

acsStoreId,
domainMigrationId,
splice.amulet.rewardaccountingv2.ProcessRewardsV2.COMPANION,
orderLimit = sql"""order by reward_round limit ${sqlLimit(limit)}""",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an index that would make this sorting efficient? If not, do we need this sorting here?

There might be many coupons in prod, and we wouldn't want this query to become a problem.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced this with 'mining_round' which has index. And in some ways 'mining_round' is more appropriate for the CalculateRewardsV2 and ProcessRewardsV2. Also bumped the store version in this PR, as I forgot to do that in the earlier PR where I added the ingestion. (#4724)

Comment on lines +285 to +288
// Bootstrapping a network with mintingVersion set to trafficBasedAppRewards
// is in principle not supported, as the round 0 will never have
// activity totals/root-hash calculated, and its CalculateRewardsV2 cannot be processed.
// So the only way to handle this in test is via direct archive.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a problem when we reset TestNet the next time.

What can we do so that we don't need to skip these first five rounds? I'd have expected anyways that we only need to skip Round 0, due to our requirement for there to be activity for the round one lower.

We can probably use a similar approach as done here:

if (isFirstSv) {
logger.debug(
s"Aggregation starts from round $initialRound, store_id = $roundTotalsStoreId"
)
Future.successful(None)

i.e., if no app activity metadata record exists at all and we are the first SV, then we insert it with the initialRound and recordTime = unixEpochStart.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's also a problem for all our tests once we make traffic-based app rewards the default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have added a TODO linking to #5624

@dfordivam dfordivam self-assigned this May 20, 2026
@dfordivam dfordivam force-pushed the dfordivam/cip-104-dry-run-sv-triggers branch from 81d901c to 4d8c9e6 Compare May 20, 2026 09:16
@dfordivam dfordivam force-pushed the dfordivam/cip-104-dry-run-sv-triggers-base branch from eba9097 to b2641fb Compare May 20, 2026 09:18
dfordivam added 24 commits May 21, 2026 06:38
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Mostly a patch reapply of earlier commit done on main

Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
dfordivam added 11 commits May 21, 2026 06:38
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
@dfordivam dfordivam force-pushed the dfordivam/cip-104-dry-run-sv-triggers branch from 17a4114 to c62d886 Compare May 21, 2026 06:40
dfordivam added 2 commits May 22, 2026 17:22
Signed-off-by: Divam <dfordivam@gmail.com>
Signed-off-by: Divam <dfordivam@gmail.com>
@dfordivam dfordivam changed the title DRAFT: SV-app add CalculateRewardsTrigger and ProcessRewardsTrigger SV-app add CalculateRewardsTrigger and ProcessRewardsTrigger May 22, 2026
@dfordivam dfordivam marked this pull request as ready for review May 22, 2026 08:34
@dfordivam
Copy link
Copy Markdown
Contributor Author

@meiersi-da This PR is now ready for another review. All comments have been addressed, and/or TODOs added.

Copy link
Copy Markdown
Contributor

@meiersi-da meiersi-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks a lot!

case None =>
throw Status.FAILED_PRECONDITION
.withDescription(
s"waiting for scan to compute root hash for CalculateRewardsV2 round $round, will retry"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s"waiting for scan to compute root hash for CalculateRewardsV2 round $round, will retry"
s"Scan has not yet computed the root hash for CalculateRewardsV2 round $round."

That's the precondition that is actually violated.

taskOutcome <- queryResult match {
case QueryResult(_, Some(_)) =>
Future.successful(
TaskSuccess(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TaskSuccess(
TaskNoop(

damlBatch = convertBatch(batch)
choiceArg = new ProcessRewardsV2_ProcessBatch(
damlBatch,
new DamlSet(java.util.Collections.emptyMap()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing TODO item.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check the vetting state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants