Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement account rewards #335

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3c54e66
fix related issues
lassemand Dec 19, 2024
d9d856b
implement more
lassemand Dec 19, 2024
f053228
source
lassemand Dec 19, 2024
461ceef
merge
lassemand Dec 19, 2024
929b43c
updated variable
lassemand Dec 19, 2024
5576820
update Object
lassemand Dec 19, 2024
fd466fb
test
lassemand Dec 19, 2024
b3e9377
fix indexer
lassemand Dec 23, 2024
1432074
start migrating db
lassemand Dec 23, 2024
d6a789c
fmt
lassemand Dec 23, 2024
49b8809
made account statements compile while indexer works
lassemand Dec 23, 2024
b182e29
fmt
lassemand Dec 23, 2024
35af314
made migration
lassemand Dec 27, 2024
255214b
merge with main
lassemand Dec 27, 2024
3e6352c
fmt
lassemand Dec 27, 2024
6e26f15
account balance
lassemand Dec 27, 2024
bdfc349
fixed indexer
lassemand Dec 27, 2024
561e50e
fixed amount increase
lassemand Dec 27, 2024
0c8756b
renamed account index
lassemand Dec 27, 2024
24c1597
fix streaming behaviour
lassemand Dec 27, 2024
85728d4
redo streaming
lassemand Dec 27, 2024
555a756
fix rewards
lassemand Dec 29, 2024
2c2c7b0
added rewards
lassemand Dec 29, 2024
bb931de
finished up rewards
lassemand Dec 29, 2024
23528b8
test
lassemand Dec 30, 2024
62545fb
filter 0 value
lassemand Dec 30, 2024
f333f7d
fix ordering
lassemand Dec 30, 2024
8c27505
fixed types
lassemand Dec 30, 2024
8195974
cleaned up some more
lassemand Dec 30, 2024
007ed9a
move to be using a bec instead of stream
lassemand Dec 30, 2024
11acf28
made useless comment
lassemand Dec 30, 2024
b54a153
made it a vec
lassemand Dec 30, 2024
1a07418
fix paging
lassemand Dec 31, 2024
fc8f2ca
updated query cache
lassemand Dec 31, 2024
11cfd6f
removed index
lassemand Jan 2, 2025
252d0aa
Update backend-rust/src/graphql_api.rs
lassemand Jan 2, 2025
e103cda
undo change in account token
lassemand Jan 2, 2025
de0ff7b
Merge branch 'lma/CCD-74/implement-accountrewards' of github.com:Conc…
lassemand Jan 2, 2025
d576baf
refactor code
lassemand Jan 2, 2025
c90e5e3
merge with main
lassemand Jan 3, 2025
97b58b2
update transaction id comment
lassemand Jan 3, 2025
5802f6e
fmt
lassemand Jan 3, 2025
c536493
sqlx
lassemand Jan 3, 2025
cc08132
updated types
lassemand Jan 3, 2025
de7d628
improve comment
lassemand Jan 3, 2025
6604fb0
fmt
lassemand Jan 3, 2025
16646a6
update sql
lassemand Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

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

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

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

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

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

38 changes: 38 additions & 0 deletions backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ CREATE TYPE pool_open_status AS ENUM (
'ClosedForAll'
);

CREATE TYPE account_statement_entry_type AS ENUM (
'TransferIn',
'TransferOut',
'AmountDecrypted',
'AmountEncrypted',
'TransactionFee',
'FinalizationReward',
'FoundationReward',
'BakerReward',
'TransactionFeeReward'
);

CREATE TYPE account_statement_reward_type AS ENUM (
'FinalizationReward',
'FoundationReward',
'BakerReward',
'TransactionFeeReward'
);

CREATE TYPE module_reference_contract_link_action AS ENUM (
'Added',
'Removed'
Expand Down Expand Up @@ -229,6 +248,7 @@ CREATE TABLE accounts(
CREATE INDEX accounts_amount_idx ON accounts (amount);
CREATE INDEX accounts_delegated_stake_idx ON accounts (delegated_stake);
CREATE INDEX accounts_num_txs_idx ON accounts (num_txs);
CREATE INDEX accounts_address_index ON accounts (address);
lassemand marked this conversation as resolved.
Show resolved Hide resolved

-- Add foreign key constraint now that the account table is created.
ALTER TABLE transactions
Expand Down Expand Up @@ -514,3 +534,21 @@ $trigger$ LANGUAGE plpgsql;
CREATE TRIGGER account_updated_notify_trigger AFTER INSERT
ON affected_accounts
FOR EACH ROW EXECUTE PROCEDURE account_updated_notify_trigger_function();

CREATE TABLE account_statements (
lassemand marked this conversation as resolved.
Show resolved Hide resolved
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
account_index BIGINT REFERENCES accounts(index) NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
lassemand marked this conversation as resolved.
Show resolved Hide resolved
entry_type account_statement_entry_type NOT NULL,
amount BIGINT NOT NULL,
lassemand marked this conversation as resolved.
Show resolved Hide resolved
account_balance BIGINT NOT NULL,
lassemand marked this conversation as resolved.
Show resolved Hide resolved
block_height BIGINT REFERENCES blocks(height) NOT NULL,
transaction_id BIGINT NULL
lassemand marked this conversation as resolved.
Show resolved Hide resolved
);

CREATE INDEX account_statements_entry_type_idx ON account_statements (entry_type);

CREATE VIEW account_rewards AS
Copy link
Contributor

@limemloh limemloh Jan 3, 2025

Choose a reason for hiding this comment

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

Not sure how this performs, since the query we need is the rewards for some account_index and this view is first filtering rewards across every account, and then we filter the ones related to the account (scanning potentially). Maybe postgres is smart enough to rearrange to avoid scanning, but a more direct approach would be to have the index:

account_statements (account_index, entry_type)

And then query directly:

SELECT ... FROM account_statements WHERE account_index = $1 AND entry_type IN (...)

Which I expect to scale better

SELECT id, account_index, timestamp, entry_type::TEXT::account_statement_reward_type AS reward_type, amount, block_height
FROM account_statements
WHERE entry_type::TEXT IN (SELECT unnest(enum_range(NULL::account_statement_reward_type))::TEXT);
lassemand marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading