Skip to content

Commit 73c0d5b

Browse files
committed
fix: show delegated reward calls in account history
Account history is keyed on the transaction sender: transactions(where: { from: $account }) Since LIP-118 (livepeer/protocol#648) an orchestrator can nominate a reward caller to submit reward() on its behalf. That transaction is sent by the caller, so it drops out of the query and every event inside it - including the RewardEvent - disappears from the orchestrator's history. The event itself was always attributed correctly: RewardEvent.delegate is the orchestrator regardless of who signed. The blind spot is purely in how the Explorer asks for it. It cannot be fixed in place either, because Transaction.events is typed as the Event interface, whose filter exposes only id/timestamp/transaction/round - delegate lives on the concrete RewardEvent type, so events_: { delegate: ... } does not exist. So query the event entity directly, keyed on the orchestrator. This is the same shape as winningTicketRedeemedEvents, already a separate role-keyed query in this file for the same reason: a ticket's recipient is an event param, so it survives being redeemed by a separate wallet. Excluding RewardEvent from the transaction-path list is what keeps self-called rewards, which appear in both queries, from rendering twice - there is no id-based dedupe in this component. Also require every list to be exhausted before paging stops. Keying that on transactions alone cuts off exactly the accounts this fixes: an orchestrator delegating every reward call has few transactions but one reward event per round. This equally affects gateways with more tickets than transactions, which 90ab4a1 fixed for totalLoaded but not reachedEnd. Delegated calls render with the existing copy. Distinguishing them would mean comparing transaction.from against the account, which is approximate - a multisig or relayer shows as the sender. The authoritative answer is Transcoder.rewardCaller, pending livepeer/subgraph#253.
1 parent 72a24a1 commit 73c0d5b

3 files changed

Lines changed: 78 additions & 12 deletions

File tree

‎apollo/subgraph.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5764,8 +5764,8 @@ export type Transaction = {
57645764
id: Scalars['ID'];
57655765
/** Timestamp for transaction */
57665766
timestamp: Scalars['Int'];
5767-
/** The receiving party of the transaction */
5768-
to: Scalars['String'];
5767+
/** The receiving party of the transaction - null for contract-creation transactions */
5768+
to?: Maybe<Scalars['String']>;
57695769
};
57705770

57715771

@@ -9707,7 +9707,7 @@ export type TransactionsQueryVariables = Exact<{
97079707
}>;
97089708

97099709

9710-
export type TransactionsQuery = { __typename: 'Query', transactions: Array<{ __typename: 'Transaction', events?: Array<{ __typename: 'BondEvent', additionalAmount: string, delegator: { __typename: 'Delegator', id: string }, newDelegate: { __typename: 'Transcoder', id: string }, oldDelegate?: { __typename: 'Transcoder', id: string } | null, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'BurnEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'DepositFundedEvent', amount: string, sender: { __typename: 'Broadcaster', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'EarningsClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'MigrateDelegatorFinalizedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'MintEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'NewRoundEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ParameterUpdateEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'PauseEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'PollCreatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'RebondEvent', amount: string, delegate: { __typename: 'Transcoder', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ReserveClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ReserveFundedEvent', amount: string, reserveHolder: { __typename: 'Broadcaster', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'RewardEvent', rewardTokens: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ServiceURIUpdateEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'SetCurrentRewardTokensEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'StakeClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderActivatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderDeactivatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderEvictedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderResignedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderSlashedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderUpdateEvent', rewardCut: string, feeShare: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TransferBondEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TreasuryVoteEvent', id: string, reason?: string | null, support: TreasuryVoteSupport, timestamp: number, weight: string, proposal: { __typename: 'TreasuryProposal', id: string, targets: Array<string>, description: string }, treasuryVoter: { __typename: 'LivepeerAccount', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'UnbondEvent', amount: string, delegate: { __typename: 'Transcoder', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'UnpauseEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'VoteEvent', voter: string, choiceID: string, id: string, timestamp: number, poll: { __typename: 'Poll', id: string, proposal: string, endBlock: string, quorum: string, quota: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number }, round: { __typename: 'Round', id: string } } | { __typename: 'WinningTicketRedeemedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawFeesEvent', amount: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawStakeEvent', amount: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawalEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } }> | null }>, winningTicketRedeemedEvents: Array<{ __typename: 'WinningTicketRedeemedEvent', id: string, faceValue: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number }, sender: { __typename: 'Broadcaster', id: string }, recipient: { __typename: 'Transcoder', id: string } }> };
9710+
export type TransactionsQuery = { __typename: 'Query', transactions: Array<{ __typename: 'Transaction', events?: Array<{ __typename: 'BondEvent', additionalAmount: string, delegator: { __typename: 'Delegator', id: string }, newDelegate: { __typename: 'Transcoder', id: string }, oldDelegate?: { __typename: 'Transcoder', id: string } | null, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'BurnEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'DepositFundedEvent', amount: string, sender: { __typename: 'Broadcaster', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'EarningsClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'MigrateDelegatorFinalizedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'MintEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'NewRoundEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ParameterUpdateEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'PauseEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'PollCreatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'RebondEvent', amount: string, delegate: { __typename: 'Transcoder', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ReserveClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ReserveFundedEvent', amount: string, reserveHolder: { __typename: 'Broadcaster', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'RewardEvent', rewardTokens: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'ServiceURIUpdateEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'SetCurrentRewardTokensEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'StakeClaimedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderActivatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderDeactivatedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderEvictedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderResignedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderSlashedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TranscoderUpdateEvent', rewardCut: string, feeShare: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TransferBondEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'TreasuryVoteEvent', id: string, reason?: string | null, support: TreasuryVoteSupport, timestamp: number, weight: string, proposal: { __typename: 'TreasuryProposal', id: string, targets: Array<string>, description: string }, treasuryVoter: { __typename: 'LivepeerAccount', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'UnbondEvent', amount: string, delegate: { __typename: 'Transcoder', id: string }, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'UnpauseEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'VoteEvent', voter: string, choiceID: string, id: string, timestamp: number, poll: { __typename: 'Poll', id: string, proposal: string, endBlock: string, quorum: string, quota: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number }, round: { __typename: 'Round', id: string } } | { __typename: 'WinningTicketRedeemedEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawFeesEvent', amount: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawStakeEvent', amount: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } } | { __typename: 'WithdrawalEvent', round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } }> | null }>, winningTicketRedeemedEvents: Array<{ __typename: 'WinningTicketRedeemedEvent', id: string, faceValue: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number }, sender: { __typename: 'Broadcaster', id: string }, recipient: { __typename: 'Transcoder', id: string } }>, rewardEvents: Array<{ __typename: 'RewardEvent', id: string, rewardTokens: string, round: { __typename: 'Round', id: string }, transaction: { __typename: 'Transaction', id: string, timestamp: number } }> };
97119711

97129712
export type TranscoderActivatedEventsQueryVariables = Exact<{
97139713
where?: InputMaybe<TranscoderActivatedEvent_Filter>;
@@ -10781,6 +10781,24 @@ export const TransactionsDocument = gql`
1078110781
id
1078210782
}
1078310783
}
10784+
rewardEvents(
10785+
orderBy: timestamp
10786+
orderDirection: desc
10787+
where: {delegate: $account}
10788+
first: $first
10789+
skip: $skip
10790+
) {
10791+
__typename
10792+
id
10793+
round {
10794+
id
10795+
}
10796+
transaction {
10797+
id
10798+
timestamp
10799+
}
10800+
rewardTokens
10801+
}
1078410802
}
1078510803
`;
1078610804

‎components/HistoryView/index.tsx‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const Index = () => {
8383
const isVoteEvent = isType("VoteEvent");
8484
const isTreasuryVoteEvent = isType("TreasuryVoteEvent");
8585

86+
// Clamps tickets/rewards to the oldest loaded transaction so rows only
87+
// append; nothing is stranded, registration precedes both.
8688
const lastEventTimestamp = useMemo(
8789
() =>
8890
Number(events?.[(events?.length || 0) - 1]?.transaction?.timestamp ?? 0),
@@ -170,18 +172,30 @@ const Index = () => {
170172
}));
171173
}, [data?.winningTicketRedeemedEvents, account, lastEventTimestamp]);
172174

173-
// WinningTicketRedeemedEvents, VoteEvents, and TreasuryVoteEvents are replaced
174-
// with enriched versions (direction-tagged tickets, IPFS-enriched votes)
175+
// Orchestrator-keyed so delegated reward calls, whose transaction is sent by
176+
// the reward caller, are included too.
177+
const rewardEvents = useMemo(
178+
() =>
179+
data?.rewardEvents?.filter(
180+
(e) => (e?.transaction?.timestamp ?? 0) > lastEventTimestamp
181+
) ?? [],
182+
[data?.rewardEvents, lastEventTimestamp]
183+
);
184+
175185
const mergedEvents = useMemo(
176186
() =>
177187
[
188+
// Dropped here and re-added below from the enriched (tickets, votes)
189+
// and superset (rewards) lists, so they are not listed twice.
178190
...events.filter(
179191
(e) =>
180192
e?.__typename !== "WinningTicketRedeemedEvent" &&
181193
e?.__typename !== "TreasuryVoteEvent" &&
182-
e?.__typename !== "VoteEvent"
194+
e?.__typename !== "VoteEvent" &&
195+
e?.__typename !== "RewardEvent"
183196
),
184197
...ticketEvents,
198+
...rewardEvents,
185199
...extendedTreasuryVoteEventsData,
186200
...extendedVoteEventsData,
187201
].sort(
@@ -191,14 +205,16 @@ const Index = () => {
191205
[
192206
events,
193207
ticketEvents,
208+
rewardEvents,
194209
extendedTreasuryVoteEventsData,
195210
extendedVoteEventsData,
196211
]
197212
);
198213

199214
const totalLoaded = Math.max(
200215
data?.transactions?.length ?? 0,
201-
data?.winningTicketRedeemedEvents?.length ?? 0
216+
data?.winningTicketRedeemedEvents?.length ?? 0,
217+
data?.rewardEvents?.length ?? 0
202218
);
203219

204220
const fetchingRef = useRef(false);
@@ -210,11 +226,19 @@ const Index = () => {
210226
try {
211227
await fetchMoreTransactions({
212228
variables: {
229+
// Shared skip: a shorter list is only over-skipped once exhausted.
213230
skip: totalLoaded,
214231
},
215232
updateQuery: (previousResult, { fetchMoreResult }) => {
216233
if (!fetchMoreResult) return previousResult;
217-
if (fetchMoreResult.transactions.length < PAGE_SIZE)
234+
// Stop only once every list is exhausted. Rewards and ticket
235+
// redemptions can be submitted by another address, so neither list is
236+
// bounded by `transactions`.
237+
if (
238+
fetchMoreResult.transactions.length < PAGE_SIZE &&
239+
fetchMoreResult.winningTicketRedeemedEvents.length < PAGE_SIZE &&
240+
fetchMoreResult.rewardEvents.length < PAGE_SIZE
241+
)
218242
setReachedEnd(true);
219243

220244
return {
@@ -223,13 +247,14 @@ const Index = () => {
223247
...previousResult.transactions,
224248
...fetchMoreResult.transactions,
225249
],
226-
// Basing the query skip for winning tickets on transactions.length is fine because there will always be more transactions than winning tickets
227-
// So, we will always have winning ticket events that are older than the last transaction timestamp
228-
// Allowing mergedEvents to filter correctly
229250
winningTicketRedeemedEvents: [
230251
...previousResult.winningTicketRedeemedEvents,
231252
...fetchMoreResult.winningTicketRedeemedEvents,
232253
],
254+
rewardEvents: [
255+
...previousResult.rewardEvents,
256+
...fetchMoreResult.rewardEvents,
257+
],
233258
};
234259
},
235260
});
@@ -276,7 +301,8 @@ const Index = () => {
276301

277302
if (
278303
!data?.transactions?.length &&
279-
!data?.winningTicketRedeemedEvents?.length
304+
!data?.winningTicketRedeemedEvents?.length &&
305+
!data?.rewardEvents?.length
280306
) {
281307
return <Box css={{ paddingTop: "$3" }}>No history</Box>;
282308
}

‎queries/transactions.graphql‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,26 @@ query transactions($account: String!, $first: Int!, $skip: Int!) {
132132
id
133133
}
134134
}
135+
# Keyed on the orchestrator (RewardEvent.delegate), not the transaction sender.
136+
# Since LIP-118 a delegated reward caller may submit reward() on the
137+
# orchestrator's behalf, so those calls are absent from the transactions query
138+
# above, which filters on `from`.
139+
rewardEvents(
140+
orderBy: timestamp
141+
orderDirection: desc
142+
where: { delegate: $account }
143+
first: $first
144+
skip: $skip
145+
) {
146+
__typename
147+
id
148+
round {
149+
id
150+
}
151+
transaction {
152+
id
153+
timestamp
154+
}
155+
rewardTokens
156+
}
135157
}

0 commit comments

Comments
 (0)