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

[DRAFT] Implement account rewards #335

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 2 additions & 15 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,7 @@ impl BaseQuery {
// specified.
let mut accounts = sqlx::query_as!(
Account,
r"SELECT * FROM (
SELECT
r"SELECT
index,
transaction_index,
address,
Expand Down Expand Up @@ -677,18 +676,7 @@ impl BaseQuery {
(CASE WHEN $5 AND NOT $8 THEN num_txs END) ASC,
(CASE WHEN $6 AND $8 THEN delegated_stake END) DESC,
(CASE WHEN $6 AND NOT $8 THEN delegated_stake END) ASC
LIMIT $9
)
-- We need to order each page ASC still, we only use the DESC/ASC ordering above
-- to select page items from the start/end of the range.
-- Each page must still independently be ordered ascending.
-- See also https://relay.dev/graphql/connections.htm#sec-Edge-order
ORDER BY CASE
WHEN $3 THEN index
WHEN $4 THEN amount
WHEN $5 THEN num_txs
WHEN $6 THEN delegated_stake
END ASC",
LIMIT $9",
query.from,
query.to,
matches!(order.field, AccountOrderField::Age),
Expand Down Expand Up @@ -3376,7 +3364,6 @@ impl AccountReleaseSchedule {
#[graphql(desc = "Returns the elements in the list that come after the specified cursor.")]
after: Option<String>,
#[graphql(desc = "Returns the last _n_ elements from the list.")] last: Option<u64>,
#[graphql(desc = "Returns the elements in the list that come before the specified cursor.")]
before: Option<String>,
) -> ApiResult<connection::Connection<String, AccountReleaseScheduleItem>> {
let config = get_config(ctx)?;
Expand Down
32 changes: 30 additions & 2 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use concordium_rust_sdk::{
RPCError,
},
};
use concordium_rust_sdk::types::SpecialTransactionOutcome;
use futures::{StreamExt, TryStreamExt};
use prometheus_client::{
metrics::{
Expand Down Expand Up @@ -312,6 +313,11 @@ impl Indexer for BlockPreProcessor {
let mut client1 = client.clone();
let mut client2 = client.clone();
let mut client3 = client.clone();
let special_events = {
let stream = client.get_block_special_events(fbi.height).await?.response;
stream.try_collect::<Vec<SpecialTransactionOutcome>>().await?
};

let get_events = async move {
let events = client3
.get_block_transaction_events(fbi.height)
Expand All @@ -323,11 +329,12 @@ impl Indexer for BlockPreProcessor {
};

let start_fetching = Instant::now();

let (block_info, chain_parameters, events, tokenomics_info) = try_join!(
client1.get_block_info(fbi.height),
client2.get_block_chain_parameters(fbi.height),
get_events,
client.get_tokenomics_info(fbi.height)
client.get_tokenomics_info(fbi.height),
)?;
let total_staked_capital = match tokenomics_info.response {
RewardsOverview::V0 {
Expand All @@ -344,7 +351,6 @@ impl Indexer for BlockPreProcessor {
..
} => total_staked_capital,
};

let node_response_time = start_fetching.elapsed();
self.node_response_time.get_or_create(label).observe(node_response_time.as_secs_f64());

Expand All @@ -355,7 +361,9 @@ impl Indexer for BlockPreProcessor {
chain_parameters: chain_parameters.response,
tokenomics_info: tokenomics_info.response,
total_staked_capital,
special_events
};

let prepared_block =
PreparedBlock::prepare(&mut client, &data).await.map_err(RPCError::ParseError)?;
Ok(prepared_block)
Expand Down Expand Up @@ -598,6 +606,7 @@ struct BlockData {
chain_parameters: ChainParameters,
tokenomics_info: RewardsOverview,
total_staked_capital: Amount,
special_events: Vec<SpecialTransactionOutcome>
}

/// Function for initializing the database with the genesis block.
Expand Down Expand Up @@ -727,6 +736,8 @@ struct PreparedBlock {
block_last_finalized: String,
/// Preprocessed block items, ready to be saved in the database.
prepared_block_items: Vec<PreparedBlockItem>,
/// Preprocessed
special_items: Vec< PreparedBlockSpecialEvent>,
}

impl PreparedBlock {
Expand Down Expand Up @@ -857,6 +868,23 @@ WHERE blocks.finalization_time IS NULL AND blocks.height <= last.height
}
}

struct PreparedBlockSpecialEvent {

}

impl PreparedBlockSpecialEvent {
async fn prepare(event: &BlockSpecialEvent) -> anyhow::Result<Self> {
todo!()
}

async fn save(
&self,
tx: &mut sqlx::Transaction<'static, sqlx::Postgres>,
) -> anyhow::Result<()> {
todo!()
}
}

/// Prepared block item (transaction), ready to be inserted in the database.
struct PreparedBlockItem {
/// Index of the block item within the block.
Expand Down
Loading