Skip to content

Commit 1369090

Browse files
committed
CIP 104: Traffic Based App Rewards: Add app activity computation store and schema (#4372)
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
1 parent a350c29 commit 1369090

File tree

5 files changed

+956
-0
lines changed

5 files changed

+956
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
-- Per-party totals of app activity weights for each round.
2+
create table app_activity_party_totals
3+
(
4+
-- History identifier for update history partitioning (same as update_history_id).
5+
history_id bigint not null,
6+
-- The mining round number for which the totals are computed.
7+
round_number bigint not null,
8+
-- Total activity weight recorded for the app provider in the given round.
9+
-- Measured in bytes of traffic.
10+
total_app_activity_weight bigint not null,
11+
-- Sequence number of the app provider party in the given round.
12+
-- Assigned in ascending order of app_provider_party starting from 0 for each round.
13+
-- Used as a compact reference to the app provider party in other tables to save space,
14+
-- as the party identifier can be long.
15+
app_provider_party_seq_num int not null,
16+
-- The app provider party for which the totals are computed.
17+
app_provider_party text not null,
18+
19+
constraint app_activity_party_totals_pkey primary key (history_id, round_number, app_provider_party_seq_num),
20+
21+
-- Uniqueness constraint and index to lookup activity totals by app provider party.
22+
constraint uq_app_activity_party unique (history_id, round_number, app_provider_party)
23+
);
24+
25+
-- Per-round totals of app activity weights across all app providers.
26+
-- Used to determine the total amount of app rewards to be distributed in a round based on the total activity and the reward curve.
27+
create table app_activity_round_totals
28+
(
29+
-- History identifier for update history partitioning (same as update_history_id).
30+
history_id bigint not null,
31+
-- The mining round number for which the totals are computed.
32+
round_number bigint not null,
33+
-- Total activity weight recorded across all app providers in the given round.
34+
-- Measured in bytes of traffic.
35+
total_round_app_activity_weight bigint not null,
36+
-- Number of parties with non-zero activity in the given round.
37+
-- Used for debugging purposes.
38+
active_app_provider_parties_count bigint not null,
39+
40+
constraint app_activity_round_totals_pkey primary key (history_id, round_number)
41+
);
42+
43+
-- Per-party totals of app rewards for each round.
44+
create table app_reward_party_totals
45+
(
46+
-- History identifier for update history partitioning (same as update_history_id).
47+
history_id bigint not null,
48+
-- The mining round number for which the totals are computed.
49+
round_number bigint not null,
50+
-- Party number within the round.
51+
app_provider_party_seq_num int not null,
52+
53+
-- Total app reward amount minting allowance for the app provider in the given round.
54+
-- Measured in Amulet.
55+
total_app_reward_amount decimal(38,10) not null,
56+
57+
constraint app_reward_party_totals_pkey primary key (history_id, round_number, app_provider_party_seq_num),
58+
59+
constraint app_reward_party_totals_activity_fkey foreign key (history_id, round_number, app_provider_party_seq_num)
60+
references app_activity_party_totals (history_id, round_number, app_provider_party_seq_num)
61+
);
62+
63+
-- Per-round totals of app rewards across all app providers.
64+
-- Used for debugging purposes only.
65+
create table app_reward_round_totals
66+
(
67+
-- History identifier for update history partitioning (same as update_history_id).
68+
history_id bigint not null,
69+
-- The mining round number for which the totals are computed.
70+
round_number bigint not null,
71+
72+
-- Total app reward amount minting allowance across all app providers in the given round.
73+
-- Measured in Amulet.
74+
total_app_reward_minting_allowance decimal(38,10) not null,
75+
76+
-- Total amount of app rewards that were burned due to being below the threshold.
77+
total_app_reward_thresholded decimal(38,10) not null,
78+
79+
-- Total amount of app rewards that were unclaimed (i.e., for which there was no rewardable activity).
80+
total_app_reward_unclaimed decimal(38,10) not null,
81+
82+
-- Number of parties with non-zero reward in the given round.
83+
-- These can be fewer than the active_app_provider_parties_count in app_activity_round_totals,
84+
-- as rewards below the threshold are burned.
85+
rewarded_app_provider_parties_count bigint not null,
86+
87+
constraint app_reward_round_totals_pkey primary key (history_id, round_number)
88+
);
89+
90+
91+
-- Merkle tree of batched reward commitments for each round.
92+
-- Served on Scan API for the SV app's ProcessRewardsTrigger to expand on-ledger.
93+
create table app_reward_batch_hashes
94+
(
95+
-- History identifier for update history partitioning (same as update_history_id).
96+
history_id bigint not null,
97+
-- The mining round number for which the batch hashes are recorded.
98+
round_number bigint not null,
99+
-- The level of the batch for the given round.
100+
-- Levels are assigned in ascending order starting from 0 for each round,
101+
-- with each batch containing a contiguous sequence of parties based on their app_provider_party_seq_num.
102+
--
103+
-- Child batches can be found by looking for batches with the same
104+
-- round_number and a lower batch_level and have a party_seq_num_begin_incl that is
105+
-- within the party_seq_num_begin_incl and party_seq_num_end_excl of the parent batch.
106+
batch_level int not null,
107+
-- Sequence number of the first party in the batch (inclusive).
108+
party_seq_num_begin_incl int not null,
109+
-- Sequence number of the last party in the batch (exclusive).
110+
-- Always matches the party_seq_num_begin_incl of the next batch for the same round and level,
111+
-- unless this is the last batch.
112+
party_seq_num_end_excl int not null,
113+
-- The hash of the batch of app rewards for the given round.
114+
-- Used for verifiable on-ledger reward coupon creation.
115+
batch_hash bytea not null,
116+
117+
constraint app_reward_batch_hashes_pkey primary key (history_id, round_number, batch_level, party_seq_num_begin_incl)
118+
);
119+
120+
create index idx_app_reward_batch_hash_by_hash on app_reward_batch_hashes (history_id, round_number, batch_hash);
121+
122+
123+
-- Root hash per round, marking completion of reward computation.
124+
-- Looked up by CalculateRewardsTrigger in the SV app to submit for BFT confirmation.
125+
create table app_reward_root_hashes
126+
(
127+
-- History identifier for update history partitioning (same as update_history_id).
128+
history_id bigint not null,
129+
-- The mining round number for which the root hashes are recorded.
130+
round_number bigint not null,
131+
-- The hash of the Merkle root of the app reward batches for the given round.
132+
-- Used for verifiable on-ledger reward coupon creation.
133+
--
134+
-- The root hash is the single batch with the maximal level.
135+
root_hash bytea not null,
136+
137+
constraint app_reward_root_hashes_pkey primary key (history_id, round_number)
138+
);

apps/common/src/test/scala/org/lfdecentralizedtrust/splice/store/db/SpliceDbTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ trait SpliceDbTest extends DbTest with BeforeAndAfterAll { this: Suite =>
9595
scan_verdict_store,
9696
scan_verdict_transaction_view_store,
9797
app_activity_record_store,
98+
app_activity_party_totals,
99+
app_activity_round_totals,
100+
app_reward_party_totals,
101+
app_reward_round_totals,
102+
app_reward_batch_hashes,
103+
app_reward_root_hashes,
98104
key_value_store,
99105
acs_incremental_snapshot_data_next,
100106
acs_incremental_snapshot_data_backfill,

0 commit comments

Comments
 (0)