Skip to content

Commit

Permalink
Add nonce to rewards events
Browse files Browse the repository at this point in the history
  • Loading branch information
xmariachi committed Feb 17, 2025
1 parent 1c439f6 commit 052d6d0
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 244 deletions.
362 changes: 210 additions & 152 deletions x/emissions/api/emissions/v7/events.pulsar.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions x/emissions/module/rewards/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func getDistributionAndPayoutRewardsToTopicActors(args GetDistributionAndPayoutR
}

// Pay out rewards to topic participants
payoutErrors := payoutRewards(args.Ctx, args.K, totalRewardsDistribution)
payoutErrors := payoutRewards(args.Ctx, args.K, totalRewardsDistribution, args.TopicRewardNonce)
if len(payoutErrors) > 0 {
for _, payoutErr := range payoutErrors {
Logger(args.Ctx).Warn(fmt.Sprintf("Failed to pay out rewards to participant in Topic %d: %s", args.TopicId, payoutErr.Error()))
Expand Down Expand Up @@ -577,12 +577,13 @@ func payoutRewards(
ctx sdk.Context,
k keeper.Keeper,
rewards []types.TaskReward,
nonce BlockHeight,
) []error {
ret := make([]error, 0) // errors to return from paying individual actors
reputerAndDelegatorRewards := make([]types.TaskReward, 0)
infererRewards := make([]types.TaskReward, 0)
forecasterRewards := make([]types.TaskReward, 0)
blockHeight := ctx.BlockHeight()
blockHeightTx := ctx.BlockHeight()
for _, reward := range rewards {
if reward.Reward.IsZero() {
continue
Expand Down Expand Up @@ -668,9 +669,9 @@ func payoutRewards(
}
}

types.EmitNewInfererRewardsSettledEvent(ctx, blockHeight, infererRewards)
types.EmitNewForecasterRewardsSettledEvent(ctx, blockHeight, forecasterRewards)
types.EmitNewReputerAndDelegatorRewardsSettledEvent(ctx, blockHeight, reputerAndDelegatorRewards)
types.EmitNewInfererRewardsSettledEvent(ctx, nonce, blockHeightTx, infererRewards)
types.EmitNewForecasterRewardsSettledEvent(ctx, nonce, blockHeightTx, forecasterRewards)
types.EmitNewReputerAndDelegatorRewardsSettledEvent(ctx, nonce, blockHeightTx, reputerAndDelegatorRewards)
return ret
}

Expand Down
1 change: 1 addition & 0 deletions x/emissions/proto/emissions/v7/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ message EventRewardsSettled {
(gogoproto.customtype) = "github.com/allora-network/allora-chain/math.Dec",
(gogoproto.nullable) = false
];
int64 block_height_tx = 6;
}

message EventNetworkLossSet {
Expand Down
148 changes: 92 additions & 56 deletions x/emissions/types/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions x/emissions/types/events_emitters.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,34 @@ func EmitNewActorEMAScoresSetEvent(ctx sdk.Context, actorType ActorType, scores

/// Rewards

func EmitNewInfererRewardsSettledEvent(ctx sdk.Context, blockHeight BlockHeight, rewards []TaskReward) {
func EmitNewInfererRewardsSettledEvent(ctx sdk.Context, blockHeight, blockHeightTx BlockHeight, rewards []TaskReward) {
if len(rewards) < 1 {
return
}
metrics.IncrProducerEventCount(metrics.INFERER_REWARD_EVENT)
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_INFERER_UNSPECIFIED, blockHeight, rewards))
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_INFERER_UNSPECIFIED, blockHeight, blockHeightTx, rewards))
if err != nil {
ctx.Logger().Warn("Error emitting NewInfererRewardsSettledEvent: ", err.Error())
}
}

func EmitNewForecasterRewardsSettledEvent(ctx sdk.Context, blockHeight BlockHeight, rewards []TaskReward) {
func EmitNewForecasterRewardsSettledEvent(ctx sdk.Context, blockHeight, blockHeightTx BlockHeight, rewards []TaskReward) {
if len(rewards) < 1 {
return
}
metrics.IncrProducerEventCount(metrics.FORECASTER_REWARD_EVENT)
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_FORECASTER, blockHeight, rewards))
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_FORECASTER, blockHeight, blockHeightTx, rewards))
if err != nil {
ctx.Logger().Warn("Error emitting NewForecasterRewardsSettledEvent: ", err.Error())
}
}

func EmitNewReputerAndDelegatorRewardsSettledEvent(ctx sdk.Context, blockHeight BlockHeight, rewards []TaskReward) {
func EmitNewReputerAndDelegatorRewardsSettledEvent(ctx sdk.Context, blockHeight, blockHeightTx BlockHeight, rewards []TaskReward) {
if len(rewards) < 1 {
return
}
metrics.IncrProducerEventCount(metrics.REPUTER_REWARD_EVENT)
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_REPUTER, blockHeight, rewards))
err := ctx.EventManager().EmitTypedEvent(NewRewardsSetEventBase(ActorType_ACTOR_TYPE_REPUTER, blockHeight, blockHeightTx, rewards))
if err != nil {
ctx.Logger().Warn("Error emitting NewReputerAndDelegatorRewardsSettledEvent: ", err.Error())
}
Expand Down
Loading

0 comments on commit 052d6d0

Please sign in to comment.