-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indexer-alt: kv_feature_flags pipeline
## Description Like `kv_protocol_configs`, but for feature flags. ## Test plan Run the indexer over the first 700K checkpoints -- this will include two protocol config upgrades, then check the database for feature flags. ``` sui$ cargo run -p sui-indexer-alt --release -- \ --database-url "postgres://postgres:postgrespw@localhost:5432/sui_indexer_alt" \ indexer --remote-store-url https://checkpoints.mainnet.sui.io \ --last-checkpoint 700000 ``` ``` sui_indexer_alt=# SELECT * FROM kv_feature_flags ORDER BY protocol_version DESC, flag_name; protocol_version | flag_name | flag_value ------------------+-------------------------------------------------------------+------------ 6 | accept_zklogin_in_multisig | f 6 | advance_epoch_start_time_in_safe_mode | t 6 | advance_to_highest_supported_protocol_version | f 6 | allow_receiving_object_id | f 6 | authority_capabilities_v2 | f [...] ```
- Loading branch information
Showing
7 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/sui-indexer-alt/migrations/2024-11-02-014903_kv_feature_flags/down.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS kv_feature_flags; |
7 changes: 7 additions & 0 deletions
7
crates/sui-indexer-alt/migrations/2024-11-02-014903_kv_feature_flags/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS kv_feature_flags | ||
( | ||
protocol_version BIGINT NOT NULL, | ||
flag_name TEXT NOT NULL, | ||
flag_value BOOLEAN NOT NULL, | ||
PRIMARY KEY (protocol_version, flag_name) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::Arc; | ||
|
||
use anyhow::{Context, Result}; | ||
use diesel_async::RunQueryDsl; | ||
use sui_protocol_config::ProtocolConfig; | ||
use sui_types::full_checkpoint_content::CheckpointData; | ||
|
||
use crate::{ | ||
db, | ||
models::{checkpoints::StoredGenesis, epochs::StoredFeatureFlag}, | ||
pipeline::{concurrent::Handler, Processor}, | ||
schema::kv_feature_flags, | ||
}; | ||
|
||
pub struct KvFeatureFlags(pub StoredGenesis); | ||
|
||
impl Processor for KvFeatureFlags { | ||
const NAME: &'static str = "kv_protocol_configs"; | ||
type Value = StoredFeatureFlag; | ||
|
||
fn process(&self, checkpoint: &Arc<CheckpointData>) -> Result<Vec<Self::Value>> { | ||
let CheckpointData { | ||
checkpoint_summary, .. | ||
} = checkpoint.as_ref(); | ||
|
||
let protocol_version = if checkpoint_summary.sequence_number == 0 { | ||
self.0.initial_protocol_version() | ||
} else if let Some(end_of_epoch) = checkpoint_summary.end_of_epoch_data.as_ref() { | ||
end_of_epoch.next_epoch_protocol_version | ||
} else { | ||
return Ok(vec![]); | ||
}; | ||
|
||
let protocol_config = ProtocolConfig::get_for_version( | ||
protocol_version, | ||
self.0.chain().context("Failed to identify chain")?, | ||
); | ||
|
||
let protocol_version = protocol_version.as_u64() as i64; | ||
Ok(protocol_config | ||
.feature_map() | ||
.into_iter() | ||
.map(|(flag_name, flag_value)| StoredFeatureFlag { | ||
protocol_version, | ||
flag_name, | ||
flag_value, | ||
}) | ||
.collect()) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Handler for KvFeatureFlags { | ||
const MIN_EAGER_ROWS: usize = 1; | ||
const MAX_CHUNK_ROWS: usize = i16::MAX as usize / 3; | ||
const MAX_PENDING_ROWS: usize = 10000; | ||
|
||
async fn commit(values: &[Self::Value], conn: &mut db::Connection<'_>) -> Result<usize> { | ||
Ok(diesel::insert_into(kv_feature_flags::table) | ||
.values(values) | ||
.on_conflict_do_nothing() | ||
.execute(conn) | ||
.await?) | ||
} | ||
} |
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