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

Create new index for tracking Asset metadata #2445

Merged
merged 289 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
289 commits
Select commit Hold shift + click to select a range
d215844
Add support for `balances()` (plural) query
rafal-ch Oct 22, 2024
53131a3
Handle error properly instead of using `expect()`
rafal-ch Oct 22, 2024
1e24aaa
Add support for `direction` in balances query
rafal-ch Oct 22, 2024
eeea199
Remove safety check from the `balance` query
rafal-ch Oct 22, 2024
e77f33b
Fix balance logging
rafal-ch Oct 22, 2024
c9b7e29
Include message balance in `balances()` query
rafal-ch Oct 22, 2024
076cb42
Revert "Fix balance logging"
rafal-ch Oct 22, 2024
f5e2a6d
Revert a couple of unintentional changes
rafal-ch Oct 22, 2024
d1c6fcc
Rename database `Balances` to `CoinBalances`
rafal-ch Oct 22, 2024
8cc0280
Update comments
rafal-ch Oct 22, 2024
ca32195
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Oct 22, 2024
f082291
Fix formatting
rafal-ch Oct 23, 2024
f598395
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Oct 24, 2024
8ce4550
Add comment about potential discount on the balances query cost
rafal-ch Oct 24, 2024
8262c0c
Fix comment
rafal-ch Oct 24, 2024
4e84ac3
Update DB metadata with balances info
rafal-ch Oct 28, 2024
9577f30
Support both 'new' and 'old' way of querying balances
rafal-ch Oct 28, 2024
a16ef36
Support both 'new' and 'old' way of querying balance
rafal-ch Oct 28, 2024
80fb852
Do not touch the onchain DB metadata
rafal-ch Oct 28, 2024
c94a484
Write balances cache information do off-chain db on genesis
rafal-ch Oct 28, 2024
ddf0571
Use balances cache in GraphQL api
rafal-ch Oct 28, 2024
9078b05
Clean-up error handling
rafal-ch Oct 28, 2024
3b6b8c6
Satisfy clippy and fmt
rafal-ch Oct 28, 2024
5162936
generic update function
rafal-ch Oct 28, 2024
f736ecb
Extract processing of balance updates
rafal-ch Oct 28, 2024
d880e0a
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Oct 28, 2024
6927f03
Use instead of for balances key
rafal-ch Oct 29, 2024
66e26d9
Revert the supporsed-to-be temporary change that disabled warnings
rafal-ch Oct 29, 2024
a87698a
Remove unused lifetime from `HasIndexation` trait
rafal-ch Oct 29, 2024
ddadd80
Simplify trait bounds for `HasIndexation` trait
rafal-ch Oct 29, 2024
ccadf41
Further simplify trait bounds for `HasIndexation` trait
rafal-ch Oct 29, 2024
91e8abc
Split and rename the `HasIndexation` trait
rafal-ch Oct 30, 2024
ab7808f
WIP - bail when unable to update balance due to overflow
rafal-ch Oct 31, 2024
90fa259
Prefer `core::fmt::Display` over `std::fmt::Display`
rafal-ch Oct 31, 2024
0b39319
Use named const instead of plain `true` in genesis importer for clarity
rafal-ch Oct 31, 2024
4d6e17a
Remove reduntant write to `DatabaseMetadata::V2`
rafal-ch Oct 31, 2024
8f3e817
Ensure all indexations are enabled at genesis
rafal-ch Oct 31, 2024
895d9da
Fix `produce_block__raises_gas_price` after balance overflow check wa…
rafal-ch Oct 31, 2024
de11071
Fix more integration tests to work with the balance overflow checks
rafal-ch Nov 1, 2024
71226d4
Fix typo
rafal-ch Nov 1, 2024
474e207
Fix BLOB integration tests to work with the balance overflow checks
rafal-ch Nov 1, 2024
ca6057d
Revert "Fix BLOB integration tests to work with the balance overflow …
rafal-ch Nov 2, 2024
4d43038
Revert "Fix more integration tests to work with the balance overflow …
rafal-ch Nov 2, 2024
e3d898d
Revert "Fix `produce_block__raises_gas_price` after balance overflow …
rafal-ch Nov 2, 2024
9848f64
Do not bail when balances cannot be updated, log the error instead
rafal-ch Nov 2, 2024
dae0af5
Total balance of assets is now represented as `u128`
rafal-ch Nov 6, 2024
facbd2e
Infer types in `process_balances_update()`
rafal-ch Nov 6, 2024
9b8e491
Simplify trait bounds in `update_balances()`
rafal-ch Nov 6, 2024
9ea9c02
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Nov 6, 2024
54087fc
Fix formatting
rafal-ch Nov 6, 2024
20081fa
Satisfy Clippy
rafal-ch Nov 6, 2024
8b9f4e8
Update tests
rafal-ch Nov 6, 2024
e819e23
Asset balance queries now return U128 instead of U64.
rafal-ch Nov 7, 2024
de16099
Log errors when balance cannot be calculated in the legacy calculatio…
rafal-ch Nov 8, 2024
4f307e3
Mention an balance overflow follow-up issue in the comments
rafal-ch Nov 11, 2024
66d5948
Remove the `TODO` comment
rafal-ch Nov 11, 2024
7023227
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Nov 15, 2024
9a07cd2
Prevent the metadata from being overwritten with incorrect version
rafal-ch Nov 15, 2024
bcf543a
Extend `IndexationKind` enum with `CoinsToSpend`
rafal-ch Nov 15, 2024
d887e67
Introduce `coins_to_spend_indexation_enabled` and clean-up naming
rafal-ch Nov 15, 2024
75815f5
Wire coins to spend indexation into the offchain worker
rafal-ch Nov 15, 2024
01dd049
Upon creation, register coins in the index
rafal-ch Nov 15, 2024
b500f35
Access coins to spend index when querying GraphQL
rafal-ch Nov 18, 2024
41e87e1
Retrieve coins based on the 'coins to spend' index
rafal-ch Nov 18, 2024
2949172
Support many assets in a single request
rafal-ch Nov 18, 2024
af4a726
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Nov 19, 2024
35663ae
Move metadata tests to a dedicated module
rafal-ch Nov 19, 2024
179cf69
Keep the previous indexation availability when updating metadata
rafal-ch Nov 19, 2024
1d40056
Add tests for balance with (non)retryable messages
rafal-ch Nov 19, 2024
bf83346
Refactor the `balances()` off_chain function
rafal-ch Nov 19, 2024
4805aa2
Make balance updates less generic but more readable
rafal-ch Nov 19, 2024
be9fdda
Introduce `IndexationError`
rafal-ch Nov 19, 2024
623bb9f
Extract indexation to a separate module
rafal-ch Nov 19, 2024
18f37cc
Fix issue in `decrease_message_balance()`
rafal-ch Nov 19, 2024
610fd37
feat: add indexing for asset id metadata for gql endpoint
maschad Nov 19, 2024
b2fc999
Add UTs for the indexation module
rafal-ch Nov 20, 2024
b721103
Simplify implementation of balances indexation
rafal-ch Nov 20, 2024
bd16f6c
Satisfy Clippy
rafal-ch Nov 20, 2024
54375c3
feat: add gql endpoint to retrieve from off-chain db
maschad Nov 20, 2024
1dc6932
feat: updated GQL structs
maschad Nov 20, 2024
246eae3
lint: formatting
maschad Nov 20, 2024
684361d
docs: added changelog
maschad Nov 20, 2024
d750c73
Merge branch 'master' into mc/feat/index-asset-ids
maschad Nov 20, 2024
53631e7
Extract and reuse `BALANCES_INDEXATION_ENABLED` flag
rafal-ch Nov 21, 2024
a8b950b
Use saturating_add when calculatin balances (hard to overflow u128 wi…
rafal-ch Nov 21, 2024
2e6ade7
Use saturating_add when calculating balances (hard to overflow u128 w…
rafal-ch Nov 21, 2024
7a95506
Do not import `tracing` and remove some log messages
rafal-ch Nov 21, 2024
33f75af
Move the indexation initialization to combined databases
rafal-ch Nov 21, 2024
fc6c1fc
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 21, 2024
ab09b8d
fix: increase based on burn/mint amount
maschad Nov 21, 2024
6b8f18e
Return balances via iterator, not collection
rafal-ch Nov 22, 2024
2408e56
Remove dbg print
rafal-ch Nov 22, 2024
67d17d5
Make the `balances()` implementation more readable
rafal-ch Nov 22, 2024
48a363c
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 22, 2024
d2c3abe
Turn indexation into a proper module
rafal-ch Nov 22, 2024
f73140f
Introduce `coins_to_spend` indexation module
rafal-ch Nov 22, 2024
bb2537e
Update comment to mention follow-up issue
rafal-ch Nov 22, 2024
02dcc73
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 22, 2024
53bbc7b
Revert the stray change in `balance.rs`
rafal-ch Nov 22, 2024
342b2ff
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 22, 2024
cca1891
Add basic storage tests for `CoinBalances` and `MessageBalances`
rafal-ch Nov 22, 2024
f1fc124
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 22, 2024
f189494
Update index upon the `CoinCreated` event
rafal-ch Nov 22, 2024
0006312
Add test for coins to spend index key
rafal-ch Nov 22, 2024
07fa5e5
test: add test for checking totals
maschad Nov 22, 2024
b2abf4d
fix: remove unused method
maschad Nov 22, 2024
18822c3
Register spent coins in the index
rafal-ch Nov 24, 2024
3c4192a
Coins to spend index key now supports both coins and messages
rafal-ch Nov 24, 2024
dae66a8
Add/remove messages from coins to spend index
rafal-ch Nov 24, 2024
d543f3e
Move indexation error to dedicated file
rafal-ch Nov 24, 2024
9d4fb43
Store indexed coin type in the index
rafal-ch Nov 24, 2024
2c1c0ea
Add support for (non)retryable flag in coins to spend indexation key
rafal-ch Nov 25, 2024
07caa6d
Add `owner()` and `asset_id()` getters to the `CoinsToSpendIndexKey`
rafal-ch Nov 25, 2024
07d5ce1
Messages are indexed with the correct base asset id
rafal-ch Nov 25, 2024
8eb3f27
Assert on asset id in the coins to spend index key
rafal-ch Nov 25, 2024
dd698d8
Update tests to use base asset id
rafal-ch Nov 25, 2024
c5b6288
Add tests for every part of the `CoinsToSpendIndexKey`
rafal-ch Nov 25, 2024
7f92aeb
Remove unused function
rafal-ch Nov 25, 2024
3b56332
Merge branch 'master' into mc/feat/index-asset-ids
maschad Nov 25, 2024
33a53da
Add initial unit tests for coins to spend indexation
rafal-ch Nov 26, 2024
a38ab07
Add more explanatory comment
rafal-ch Nov 26, 2024
9db30db
Add more UTs for coins to spend index
rafal-ch Nov 26, 2024
255338e
Add UTs for failed cases in coins to spend indexation
rafal-ch Nov 26, 2024
4be30fa
Satisfy Clippy
rafal-ch Nov 26, 2024
b411ecd
Add info about missing clone()
rafal-ch Nov 26, 2024
8720576
Fix flaky `coins_with_retryable_and_non_retryable_messages_are_not_mi…
rafal-ch Nov 26, 2024
c95ea5b
Add `can_differentiate_between_coin_with_base_asset_id_and_message()`…
rafal-ch Nov 26, 2024
fc86a2b
Revert "Add `can_differentiate_between_coin_with_base_asset_id_and_me…
rafal-ch Nov 26, 2024
c0cb68d
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Nov 26, 2024
c1f88ce
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 26, 2024
370a196
Merge remote-tracking branch 'upstream/master' into 1965_balances_cache
rafal-ch Nov 28, 2024
d65fd6e
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 28, 2024
61b22ba
Wire up the coins to spend query
rafal-ch Nov 28, 2024
96d0987
Satisfy coins to spend request from the index
rafal-ch Nov 28, 2024
f179188
Use correct prefix to query for coin
rafal-ch Nov 28, 2024
0d545d9
Return the actual coins from on chain DB to the user
rafal-ch Nov 28, 2024
5d32aa0
Support for excluded ids in big coins
rafal-ch Nov 28, 2024
682ac92
Support for excluded ids in dust coins
rafal-ch Nov 28, 2024
ece6e7e
Introduce the concept of named foreign key to more efficiently compar…
rafal-ch Nov 28, 2024
05e5a76
Use variable key size for coins and messages to save some space in DB
rafal-ch Nov 29, 2024
cfcc13b
Simplify creation of `CoinsToSpendIndexKey`
rafal-ch Nov 29, 2024
7ba4cb5
Update integration tests for coins to spend
rafal-ch Nov 29, 2024
add20df
Satisfy Clippy
rafal-ch Nov 29, 2024
577b71f
Satisfy Clippy
rafal-ch Nov 29, 2024
be9b742
Small suggestions and simplification to the balances indexation PR (#…
xgreenx Nov 29, 2024
8af7dea
Merge remote-tracking branch 'upstream/1965_balances_cache' into rafa…
rafal-ch Nov 29, 2024
7614bf7
Fixes after the merge
rafal-ch Nov 29, 2024
ace08de
Merge remote-tracking branch 'upstream/rafal_2391_coins_to_spend_cach…
rafal-ch Nov 29, 2024
0cb04fd
Merge branch 'master' into mc/feat/index-asset-ids
maschad Nov 30, 2024
6ae2051
chore: handle unindexed asset events
maschad Nov 30, 2024
56b5f29
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Dec 2, 2024
69010c4
Merge remote-tracking branch 'upstream/2391_optimize_coins_to_spend' …
rafal-ch Dec 2, 2024
2b76a88
Remove the `InsufficientCoins` error variant and update tests
rafal-ch Dec 2, 2024
ebe0294
coins_to_spend() directly returns `CoinId`
rafal-ch Dec 2, 2024
bb4985e
Remove `unwrap()`
rafal-ch Dec 2, 2024
4b1f788
Remove unwraps
rafal-ch Dec 2, 2024
b2e5bf7
Remove more temporary unwraps in implementation
rafal-ch Dec 2, 2024
098b031
Fix the indexation and rework the tests
AurelienFT Dec 2, 2024
630da0d
Add GWT in test
AurelienFT Dec 2, 2024
ef2e9ce
Merge branch 'master' into mc/feat/index-asset-ids
AurelienFT Dec 2, 2024
274441a
Code cleanup
rafal-ch Dec 2, 2024
f490088
Updates to selection algo
rafal-ch Dec 2, 2024
4a8a11d
Bail on first error in coins to spend selection algorithm
rafal-ch Dec 2, 2024
1e4311b
Unify `big_coins` and `dust_coins`
rafal-ch Dec 2, 2024
5ae7e63
Merge branch 'master' into mc/feat/index-asset-ids
AurelienFT Dec 3, 2024
0eef0b5
Merge branch 'master' into rafal_2391_coins_to_spend_cache
xgreenx Dec 3, 2024
5a34b33
Merge remote-tracking branch 'upstream/rafal_2391_coins_to_spend_cach…
rafal-ch Dec 3, 2024
6cbcc29
More unit tests for the coins to spend selection algorithm
rafal-ch Dec 3, 2024
ac6dd40
Cleanup
rafal-ch Dec 3, 2024
da344b4
Update comment for default query costs
rafal-ch Dec 3, 2024
08dcc65
Add an update that got lost when moving the files around
rafal-ch Dec 3, 2024
a915976
Get base asset from already available `chain_config`
rafal-ch Dec 3, 2024
d720d1d
Use better way of type sizing
rafal-ch Dec 3, 2024
4c55857
Simplify `IndexationError` comparison
rafal-ch Dec 3, 2024
dd03f92
Reduce number of parameters of `worker_service::new_service()`
rafal-ch Dec 3, 2024
7ad10f7
Update changelog
rafal-ch Dec 3, 2024
8df7d6b
'retryable flag' part is moved to the beginning of the key
rafal-ch Dec 3, 2024
5e6e6d3
Use `IndexedCoinType` enum directly in the database
rafal-ch Dec 4, 2024
202dcdf
Use consts in `CoinsToSpendIndexKey` implementation
rafal-ch Dec 4, 2024
3ee2a1a
More clean implementation of `CoinOrMessageIdBytes::from_nonce()`
rafal-ch Dec 4, 2024
8319abd
Split coins to spend function into indexed and non-indexed one
rafal-ch Dec 4, 2024
77f8caf
Move the coins to spend logic out of off-chain DB adapter
rafal-ch Dec 4, 2024
a5c80e1
Limit the number of allowed `excludedIds` in the `coinsToSpend` Graph…
rafal-ch Dec 4, 2024
c1fe4fd
Change the ordering of fields
rafal-ch Dec 4, 2024
6c37209
Add 'G/W/T' to new tests
rafal-ch Dec 4, 2024
9786f3e
Update changelog
rafal-ch Dec 4, 2024
2cfafc2
Update changelog (mention Balances cache)
rafal-ch Dec 4, 2024
604675c
Do not box all iterators
rafal-ch Dec 4, 2024
fd95f9f
`coins_to_spend_with_cache()` is now and uses `yield_each()`
rafal-ch Dec 4, 2024
4ca5e45
`into_coin_id()` is now `async`
rafal-ch Dec 4, 2024
b159e1c
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Dec 6, 2024
88471ea
Coins to spend selects twice as much value of coins to reduce chances…
rafal-ch Dec 6, 2024
713d4a2
Clean up UTs for coins to spend
rafal-ch Dec 6, 2024
e40a974
Coins to spend algorithm returns `CoinsQueryError`, not `StorageError`
rafal-ch Dec 6, 2024
7459c3c
Move code pieces to correct places
rafal-ch Dec 6, 2024
3cf743a
Use `ExcludedKeysAsBytes` instead of `Vec` in `ExcludedKeysAsBytes`
rafal-ch Dec 9, 2024
2e0b7fd
Remove `CoinOrMessageIdBytes` type and avoid some allocations
rafal-ch Dec 9, 2024
ce637a8
Simplify asserts in some coin tests
rafal-ch Dec 9, 2024
7b54abc
Remove superfluous space
rafal-ch Dec 9, 2024
ad83e78
Make implementation of `select_coins_until_respects_excluded_ids()` m…
rafal-ch Dec 10, 2024
4c6cf85
Merge branch 'master' into rafal_2391_coins_to_spend_cache_part_2
xgreenx Dec 12, 2024
c001fd3
Make the `skip_big_coins_up_to_amount()` implementation more explicit…
rafal-ch Dec 12, 2024
a30c1da
Use more clear names in `skip_big_coins_up_to_amount()`
rafal-ch Dec 12, 2024
0175e41
Prefer `unwrap_or(false)` instead of `.unwrap_or_default()` for `bool…
rafal-ch Dec 12, 2024
87245d4
Add `CoinsQueryError::[FUnexpectedInternalState` error
rafal-ch Dec 12, 2024
2c40069
Clean up error handling in coins to spend
rafal-ch Dec 12, 2024
bef1548
Improve error handling in coins to spend query
rafal-ch Dec 12, 2024
ba883d2
Add test cases for errors in `indexed_coins_to_spend`
rafal-ch Dec 12, 2024
0602da1
Remove unnecessary variable
rafal-ch Dec 12, 2024
9d52683
Swap functions to reduce diff size
rafal-ch Dec 13, 2024
385aea7
`into_coin_id()` does not have to be async
rafal-ch Dec 13, 2024
1645c14
`setup()` function in tests now accepts consensus parameters
rafal-ch Dec 13, 2024
f1420e3
Simplify vec initialization in `into_coin_id()`
rafal-ch Dec 13, 2024
db1e97f
Update comment
rafal-ch Dec 13, 2024
bdc8ce2
Move the byte conversion from `into_coin_id()` to the key itself
rafal-ch Dec 13, 2024
8e42b87
Move the byte conversion from `is_excluded()` to the key itself
rafal-ch Dec 13, 2024
e841d66
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Dec 13, 2024
2533060
Make fields of `CoinsToSpendIndexIter` pub
rafal-ch Dec 13, 2024
6740e7d
Return proper error from `select_coins_to_spend()`
rafal-ch Dec 13, 2024
03a0662
Mention follow-up issue
rafal-ch Dec 13, 2024
1049fea
Mention follow-up issue
rafal-ch Dec 13, 2024
9c87c8d
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Dec 16, 2024
65f701d
Mention follow-up issue in the comment
rafal-ch Dec 17, 2024
5eb9bb0
Replace `as u128` with `u128::from()` where applicable
rafal-ch Dec 17, 2024
792dc33
Getters on `CoinsToSpendIndexKey` will no longer panic
rafal-ch Dec 18, 2024
4cc75bf
Remove comment which is no longer relevant
rafal-ch Dec 18, 2024
f776cb4
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Dec 30, 2024
1bc7ddd
Merge remote-tracking branch 'refs/remotes/origin/master' into mc/fea…
xgreenx Jan 7, 2025
319d32d
Applied comments from the PR.
xgreenx Jan 7, 2025
8b4f86c
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Jan 8, 2025
3ae1806
Fixes after the merge
rafal-ch Jan 8, 2025
d9d024b
Add explanatory comment in coin selection algorithm
rafal-ch Jan 8, 2025
2b3c4de
Remove outdated 'TODO' for `fn random_improve()`
rafal-ch Jan 8, 2025
ed276cb
Enumerate all variants explicitly
rafal-ch Jan 8, 2025
b8f505f
Merge remote-tracking branch 'upstream/rafal_2391_coins_to_spend_cach…
rafal-ch Jan 8, 2025
6435e75
Move asset metadata indexation to a dedicated module and index only i…
rafal-ch Jan 8, 2025
a88e9ef
Support more indexation errors
rafal-ch Jan 8, 2025
d2e3257
Add UTs for asset metadata indexation
rafal-ch Jan 9, 2025
8a1324c
Query returns error when asset metadata indexation is not available
rafal-ch Jan 9, 2025
3b0f018
Merge remote-tracking branch 'upstream/master' into mc/feat/index-ass…
rafal-ch Jan 9, 2025
56dbb69
Merge remote-tracking branch 'upstream/master' into rafal_2391_coins_…
rafal-ch Jan 9, 2025
905d91d
Update message assert in tests
rafal-ch Jan 9, 2025
5cb246d
Satisfy Clippy
rafal-ch Jan 9, 2025
1a2ffa6
Fix typo
rafal-ch Jan 9, 2025
5f6d97b
Merge remote-tracking branch 'upstream/rafal_2391_coins_to_spend_cach…
rafal-ch Jan 9, 2025
8556672
Use own codec for `CoinsToSpendIndexKey` (#2529)
xgreenx Jan 13, 2025
2691437
Minor updates to key codec
rafal-ch Jan 13, 2025
53f453c
Merge remote-tracking branch 'upstream/rafal_2391_coins_to_spend_cach…
rafal-ch Jan 13, 2025
dc6325b
Merge remote-tracking branch 'upstream/master' into mc/feat/index-ass…
rafal-ch Jan 13, 2025
5580f22
Merge branch 'master' into mc/feat/index-asset-ids
xgreenx Jan 13, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [2445](https://github.com/FuelLabs/fuel-core/pull/2445): Added GQL endpoint for querying asset details.
- [2442](https://github.com/FuelLabs/fuel-core/pull/2442): Add uninitialized task for V1 gas price service
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Added `Unknown` variant to `ConsensusParameters` graphql queries
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Added `Unknown` variant to `Block` graphql queries
Expand Down
14 changes: 14 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ scalar Address

scalar AssetId

type AssetInfoDetails {
contractId: ContractId!
subId: SubId!
totalSupply: U128!
}

type Balance {
owner: Address!
amount: U64!
Expand Down Expand Up @@ -853,6 +859,12 @@ type ProgramState {
}

type Query {
assetDetails(
"""
ID of the Asset
"""
id: AssetId!
): AssetInfoDetails!
"""
Read register value by index.
"""
Expand Down Expand Up @@ -1121,6 +1133,8 @@ type StateTransitionPurpose {
}


scalar SubId

type SubmittedStatus {
time: Tai64Timestamp!
}
Expand Down
10 changes: 10 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::client::{
TransactionId,
},
types::{
asset::AssetDetail,
gas_price::LatestGasPrice,
message::MessageStatus,
primitives::{
Expand Down Expand Up @@ -78,6 +79,7 @@ use pagination::{
PaginationRequest,
};
use schema::{
assets::AssetInfoArg,
balance::BalanceArgs,
blob::BlobByIdArgs,
block::BlockByIdArgs,
Expand Down Expand Up @@ -1191,6 +1193,14 @@ impl FuelClient {
.transpose()?;
Ok(status)
}

pub async fn asset_info(&self, asset_id: &AssetId) -> io::Result<AssetDetail> {
let query = schema::assets::AssetInfoQuery::build(AssetInfoArg {
id: (*asset_id).into(),
});
let asset_info = self.query(query).await?.asset_details.into();
Ok(asset_info)
}
}

#[cfg(any(test, feature = "test-helpers"))]
Expand Down
1 change: 1 addition & 0 deletions crates/client/src/client/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::client::pagination::{
};
pub use primitives::*;

pub mod assets;
pub mod balance;
pub mod blob;
pub mod block;
Expand Down
31 changes: 31 additions & 0 deletions crates/client/src/client/schema/assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::client::schema::{
schema,
AssetId,
ContractId,
SubId,
U128,
};

#[derive(cynic::QueryVariables, Debug)]
pub struct AssetInfoArg {
pub id: AssetId,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "AssetInfoArg"
)]
pub struct AssetInfoQuery {
#[arguments(id: $id)]
pub asset_details: AssetInfoDetails,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct AssetInfoDetails {
pub sub_id: SubId,
pub contract_id: ContractId,
pub total_supply: U128,
}
1 change: 1 addition & 0 deletions crates/client/src/client/schema/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fuel_type_scalar!(BlockId, Bytes32);
fuel_type_scalar!(AssetId, AssetId);
fuel_type_scalar!(BlobId, BlobId);
fuel_type_scalar!(ContractId, ContractId);
fuel_type_scalar!(SubId, Bytes32);
fuel_type_scalar!(Salt, Salt);
fuel_type_scalar!(TransactionId, Bytes32);
fuel_type_scalar!(RelayedTransactionId, Bytes32);
Expand Down
1 change: 1 addition & 0 deletions crates/client/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod contract;
pub mod gas_costs;
pub mod upgrades;

pub mod asset;
pub mod gas_price;
pub mod merkle_proof;
pub mod message;
Expand Down
24 changes: 24 additions & 0 deletions crates/client/src/client/types/asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::client::schema;
use fuel_core_types::{
fuel_tx::Bytes32,
fuel_types::ContractId,
};

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AssetDetail {
pub contract_id: ContractId,
pub sub_id: Bytes32,
pub total_supply: u128,
}

// GraphQL Translation

impl From<schema::assets::AssetInfoDetails> for AssetDetail {
fn from(value: schema::assets::AssetInfoDetails) -> Self {
AssetDetail {
contract_id: value.contract_id.into(),
sub_id: value.sub_id.into(),
total_supply: value.total_supply.into(),
}
}
}
1 change: 1 addition & 0 deletions crates/fuel-core/src/database/database_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub trait DatabaseDescription: 'static + Copy + Debug + Send + Sync {
pub enum IndexationKind {
Balances,
CoinsToSpend,
AssetMetadata,
}

impl IndexationKind {
Expand Down
7 changes: 7 additions & 0 deletions crates/fuel-core/src/graphql_api/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub struct ReadDatabase {
balances_indexation_enabled: bool,
/// The flag that indicates whether the CoinsToSpend indexation is enabled.
coins_to_spend_indexation_enabled: bool,
/// The flag that indicates whether the AssetMetadata indexation is enabled.
asset_metadata_indexation_enabled: bool,
}

impl ReadDatabase {
Expand All @@ -111,6 +113,8 @@ impl ReadDatabase {
let balances_indexation_enabled = off_chain.balances_indexation_enabled()?;
let coins_to_spend_indexation_enabled =
off_chain.coins_to_spend_indexation_enabled()?;
let asset_metadata_indexation_enabled =
off_chain.asset_metadata_indexation_enabled()?;

Ok(Self {
batch_size,
Expand All @@ -119,6 +123,7 @@ impl ReadDatabase {
off_chain: Box::new(ArcWrapper::new(off_chain)),
balances_indexation_enabled,
coins_to_spend_indexation_enabled,
asset_metadata_indexation_enabled,
})
}

Expand All @@ -134,6 +139,7 @@ impl ReadDatabase {
off_chain: self.off_chain.latest_view()?,
balances_indexation_enabled: self.balances_indexation_enabled,
coins_to_spend_indexation_enabled: self.coins_to_spend_indexation_enabled,
asset_metadata_indexation_enabled: self.asset_metadata_indexation_enabled,
})
}

Expand All @@ -151,6 +157,7 @@ pub struct ReadView {
pub(crate) off_chain: OffChainView,
pub(crate) balances_indexation_enabled: bool,
pub(crate) coins_to_spend_indexation_enabled: bool,
pub(crate) asset_metadata_indexation_enabled: bool,
}

impl ReadView {
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/src/graphql_api/indexation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub(crate) mod asset_metadata;
pub(crate) mod balances;
pub(crate) mod coins_to_spend;
pub(crate) mod error;
Expand Down
Loading
Loading