-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add query endpoints for balances of specific runes #3675
feat: add query endpoints for balances of specific runes #3675
Conversation
@casey Hi, can you check if this one satisfies your requirement enough? |
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.
This PR has a good form, you have a good description and also added a test. Unfortunately we need another table to make this an efficient call. You can try your hand at this, or, if you want, I could show how to add another table into the database in the next Ordinals Coding Club. Let me know what you prefer :)
src/index.rs
Outdated
for entry in self | ||
.database | ||
.begin_read()? | ||
.open_table(OUTPOINT_TO_RUNE_BALANCES)? | ||
.iter()? | ||
{ |
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.
In order to make this production ready we would need to add a new table to the index: RUNE_TO_OUTPOINTS
.
The way it works right now is that for every request it would iterate through all outpoints, making this a quite expensive call.
I can try adding it to table, thanks for your feedback |
@raphjaph I have added a new table: RUNE_ID_TO_OUTPOINTS_BALANCE which tracks rune id to bytes array of (outpoints, balance) Logic
Test
|
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.
Runes can be in multiple outpoints so this the table should be a multi map. Also we already have the table OUTPOINT_TO_RUNE_BALANCES
so we don't have to store the balance inside the new table.
src/index.rs
Outdated
@@ -63,6 +61,7 @@ define_table! { OUTPOINT_TO_RUNE_BALANCES, &OutPointValue, &[u8] } | |||
define_table! { OUTPOINT_TO_SAT_RANGES, &OutPointValue, &[u8] } | |||
define_table! { OUTPOINT_TO_VALUE, &OutPointValue, u64} | |||
define_table! { RUNE_ID_TO_RUNE_ENTRY, RuneIdValue, RuneEntryValue } | |||
define_table! { RUNE_ID_TO_OUTPOINTS_BALANCE, RuneIdValue, &[u8] } |
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.
define_table! { RUNE_ID_TO_OUTPOINTS_BALANCE, RuneIdValue, &[u8] } | |
define_multimap_table! { RUNE_ID_TO_OUTPOINTS, RuneIdValue, &OutPointValue } |
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.
Thanks, let's me see multi map
The query needs a mapping from a rune id to a byte array of multiple n outpoints.
So, I think why not also include balance of such specific rune in each out point (out point, balance of specific rune) as well, one less iteration. Thus, |
@raphjaph can you check this one again, |
d6f1ad7
to
c9b6e90
Compare
@nghuyenthevinh2000 Have you run an index with this and compared it to the size without this table? This might be a big table and take longer to index so I'm inclined to put it behind a flag like Also what is the reason to make a the 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.
See comment above
Please reopen if you plan to continue work on this. I think this could be valuable but it would need to be implemented in a space efficient way. |
fixes: #3667
The logic will fetch balances of specific rune in each outpoint. Not loading the whole balances map.
Logic
Testing
@raphjaph hi, this is my first PR, I hope to explore more into the codebase. Any constructive feedbacks are welcome!