-
Notifications
You must be signed in to change notification settings - Fork 22
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
add task that tracks stake delegation #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks @ecioppettini
indexer/migration/src/m20230927_231206_create_stake_delegation_table.rs
Outdated
Show resolved
Hide resolved
this helps getting un-delegation events by pool, since otherwise re-delegation doesn't directly address the pool that no longer has the delegation.
"StakeDelegationCredentialRelation".previous_pool IN :pools! | ||
) AND | ||
"Block".slot > :min_slot! AND | ||
"Block".slot <= :max_slot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may want to have a way to paginate this in terms of number of entries in this range? Maybe by using the tx as a cursor, I need to check how hard would be it to re-use the existing pagination code for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typical pagination cursors do not work since they don't generally expect rollbacks. If you use a pagination cursor, it has to be set up so that if the underlying data changes in the middle of pagination you do not get in an invalid state
}; | ||
|
||
export type DelegationForPoolResponse = { | ||
credential: Address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure yet what's the best way to show this, currently it's the credential in hex
export type PoolHex = string; | ||
|
||
export type Pool = | ||
| PoolHex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would bech32 be useful to have here as an option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just picking one option is fine
indexer/migration/src/lib.rs
Outdated
@@ -17,6 +17,7 @@ mod m20220528_000012_create_plutus_data_table; | |||
mod m20220808_000013_create_transaction_reference_input_table; | |||
mod m20221031_000014_create_dex_table; | |||
mod m20230223_000015_modify_block_table; | |||
mod m20230927_231206_create_stake_delegation_table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's probably keep the naming convention (date + number)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, I didn't notice that. The weird thing is that I created this file with sea-orm-cli, so I'm not sure why it's choosing that name
pub struct Model { | ||
#[sea_orm(primary_key, column_type = "BigInteger")] | ||
pub id: i64, | ||
pub stake_credential: i64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we add #[sea_orm(column_type = "BigInteger")]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that does anything, to be honest. The columns already have bigint
type for me, and it's what the docs say should happen I think (https://www.sea-ql.org/SeaORM/docs/next/generate-entity/entity-structure/).
But I can add it just in case anyway.
pub stake_credential: i64, | ||
// pool registrations are not tracked in StakeCredentials, | ||
pub pool_credential: Option<Vec<u8>>, | ||
pub tx_id: i64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here as well
|
||
let previous_entry = entity::stake_delegation::Entity::find() | ||
.filter( | ||
entity::stake_delegation::Column::StakeCredential.eq(stake_credential_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we add an index for that col as well? postgres doesn't create it automatically afaik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't seem to make a huge difference in the first epochs, but I can add it just in case
NOTE: I still need to do some cleanup, I copy-pasted some stuff from here and there that I need to re-check. Also naming of some things.
Currently this can be used like (I'm using preview, with some arbitrary stake key that I found):
Which returns
The
until
uses the absolute slot, since if you have a timestamp you can convert it to a slot and filter by time. And also, usingblock/latest
can be used to get the absolute epoch too (even if the name of the field is justepoch
), so it's possible to just get the latest one (or a close one).