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

add task that tracks stake delegation #157

Merged
merged 12 commits into from
Dec 1, 2023
Merged

Conversation

ecioppettini
Copy link
Contributor

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):

curl -X "POST" "http://localhost:3000/delegation/address" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "stake_test1uqnat2dv4gwx739kjy0vxufy7r63zkhkhuzurfsn008mh4crrhgyd",
  "until": { "absoluteSlot": 1462810 }
}'

echo ''

curl -X "POST" "http://localhost:3000/delegation/address" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "stake_test1uqnat2dv4gwx739kjy0vxufy7r63zkhkhuzurfsn008mh4crrhgyd",
  "until": { "absoluteSlot": 1462811 }
}'

echo ''

curl -X "POST" "http://localhost:3000/delegation/address" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "stake_test1uqnat2dv4gwx739kjy0vxufy7r63zkhkhuzurfsn008mh4crrhgyd",
  "until": { "absoluteSlot": 2498920 }
}'

echo ''

curl -X "POST" "http://localhost:3000/delegation/address" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "stake_test1uqnat2dv4gwx739kjy0vxufy7r63zkhkhuzurfsn008mh4crrhgyd",
  "until": { "absoluteSlot": 2498921 }
}'

Which returns

// no delegation yet
{"pool":null,"txId":null}

// the delegation certificate is in this ( the next slot ) 
{"pool":"367d927a91eb9ecf15648779beeec8c710171566edcce18feb048265","txId":"348351606a363f5c81e267e509a14eaa486003201e6b68ecf7b0cbc101f7368d"}

// last slot before re-delegation
{"pool":"367d927a91eb9ecf15648779beeec8c710171566edcce18feb048265","txId":"348351606a363f5c81e267e509a14eaa486003201e6b68ecf7b0cbc101f7368d"}

// new delegation
{"pool":"e931eea8a3e9344656f3f233e55c32ea5056303b5c313015871bc57f","txId":"1aa52d8618fdebe4afd532b0381b5ffba3ac99f6a135a2ded3a353785c2b3d16"}

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, using block/latest can be used to get the absolute epoch too (even if the name of the field is just epoch), so it's possible to just get the latest one (or a close one).

@ecioppettini ecioppettini requested a review from gostkin October 3, 2023 20:31
@ecioppettini ecioppettini self-assigned this Oct 3, 2023
Copy link
Contributor

@gostkin gostkin left a 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

@ecioppettini ecioppettini marked this pull request as ready for review October 9, 2023 12:30
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!
Copy link
Contributor Author

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.

Copy link
Contributor

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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Copy link
Contributor

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

@@ -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;
Copy link
Contributor

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)?

Copy link
Contributor Author

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,
Copy link
Contributor

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")]?

Copy link
Contributor Author

@ecioppettini ecioppettini Nov 7, 2023

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,
Copy link
Contributor

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),
Copy link
Contributor

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

Copy link
Contributor Author

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

@SebastienGllmt SebastienGllmt merged commit b3deea0 into main Dec 1, 2023
2 checks passed
@SebastienGllmt SebastienGllmt deleted the delegation-indexing-task branch December 1, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants