-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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 ConsensusV2 object support to sui-indexer{,alt}
#20486
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
363a126
Add ConsensusV2 object support to `sui-indexer{,alt}`
aschran 2e3e7b7
map consensusv2 objects onto existing address owner_kind
aschran 5d242dd
Merge branch 'main' into aschran/cov2-indexers
aschran 1fe567a
add clarifying comment to obj_info table
aschran 030b6c4
typo fix
aschran c777f43
separate index changes into a different migration
aschran e0a5944
separate migrations even further
aschran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
map consensusv2 objects onto existing address owner_kind
- Loading branch information
commit 2e3e7b79ffeaafb7d8326b3317971c51b9076c4c
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
crates/sui-indexer-alt/migrations/2024-12-02-185822_add_coin_balance_owner_kind/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
ALTER TABLE sum_coin_balances | ||
ADD COLUMN owner_kind SMALLINT NOT NULL DEFAULT 1; | ||
ADD COLUMN coin_owner_kind SMALLINT NOT NULL DEFAULT 1; | ||
|
||
DROP INDEX sum_coin_balances_owner_type; | ||
CREATE INDEX sum_coin_balances_owner_type | ||
ON sum_coin_balances (coin_owner_kind, owner_id, coin_type, coin_balance, object_id, object_version); | ||
|
||
ALTER TABLE wal_coin_balances | ||
ADD COLUMN owner_kind SMALLINT; | ||
ADD COLUMN coin_owner_kind SMALLINT; | ||
UPDATE wal_coin_balances SET owner_kind = 1 WHERE owner_id IS NOT NULL; | ||
|
||
DROP INDEX wal_coin_balances_owner_type; | ||
CREATE INDEX wal_coin_balances_owner_type | ||
ON wal_coin_balances (coin_owner_kind, owner_id, coin_type, coin_balance, object_id, object_version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ use sui_types::{ | |
|
||
use crate::{ | ||
db, | ||
models::objects::{StoredObjectUpdate, StoredOwnerKind, StoredSumCoinBalance}, | ||
models::objects::{StoredCoinOwnerKind, StoredObjectUpdate, StoredSumCoinBalance}, | ||
pipeline::{sequential::Handler, Processor}, | ||
schema::sum_coin_balances, | ||
}; | ||
|
@@ -100,12 +100,12 @@ impl Processor for SumCoinBalances { | |
}; | ||
|
||
// Coin balance only tracks address-owned or ConsensusV2 objects | ||
let (owner_kind, owner_id) = match object.owner() { | ||
Owner::AddressOwner(owner_id) => (StoredOwnerKind::Address, owner_id), | ||
let (coin_owner_kind, owner_id) = match object.owner() { | ||
Owner::AddressOwner(owner_id) => (StoredCoinOwnerKind::Fastpath, owner_id), | ||
// ConsensusV2 objects are treated as address-owned for now in indexers. | ||
// This will need to be updated if additional Authenticators are added. | ||
Owner::ConsensusV2 { authenticator, .. } => ( | ||
StoredOwnerKind::ConsensusV2, | ||
StoredCoinOwnerKind::Consensus, | ||
authenticator.as_single_owner(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting my momentary confusion that this doesn't return an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, i put a comment on the function to clarify in another PR |
||
), | ||
|
||
|
@@ -132,7 +132,7 @@ impl Processor for SumCoinBalances { | |
owner_id: owner_id.to_vec(), | ||
coin_type: coin_type.clone(), | ||
coin_balance: coin.balance.value() as i64, | ||
owner_kind, | ||
coin_owner_kind, | ||
}), | ||
}); | ||
} | ||
|
@@ -183,6 +183,8 @@ impl Handler for SumCoinBalances { | |
sum_coin_balances::owner_id.eq(excluded(sum_coin_balances::owner_id)), | ||
sum_coin_balances::coin_balance | ||
.eq(excluded(sum_coin_balances::coin_balance)), | ||
sum_coin_balances::coin_owner_kind | ||
.eq(excluded(sum_coin_balances::coin_owner_kind)), | ||
)) | ||
.execute(conn), | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thinking of some ways to make this easier to land without causing the indexer to hang when it starts, and I think I have an idea:
IF EXISTS
/IF NOT EXISTS
style statements so that they become idempotent, (which means after we've run it proactively, when the migration runs, it knows not to drop and regenerate the indices),IF EXISTS
/IF NOT EXISTS
would recognise it as different from the old index.The statements for creating and dropping the indices would look like this then:
But you will also need to split it up over separate migration scripts (because each script is its own transaction and postgres won't like it if you combine non-blocking concurrent operations with other work in a transaction). I've had to do this once before in #19543 so that can serve as a template (there's an extra TOML file that needs to go in each migration folder to tell diesel to not batch up migrations into a transaction as well).
(ditto for the wal tables below).
EDIT: tweaked index name.
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 did this, let me know if it looks correct. when I run
generate_schema.sh
locally it fails with an errorBut I have the
metadata.toml
files there as you suggested - is anything else missing?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.
The issue is that the migrations need to be split up even further -- each
DROP INDEX
andCREATE INDEX
needs to be in their own script (because they can't mingle with each other either).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, done