Skip to content

Commit 5d78e39

Browse files
authored
change: ETCM-12220 Support tx-out.value = "consumed" Db-Sync option (#949)
1 parent b6c9f33 commit 5d78e39

File tree

29 files changed

+1646
-348
lines changed

29 files changed

+1646
-348
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ sqlx = { version = "0.8.6", default-features = false, features = [
187187
] }
188188
derive-where = { version = "1.2.7", default-features = false }
189189
once_cell = { version = "1.21.3", default-features = false }
190+
paste = { version = "1.0.15" }
190191

191192
# substrate dependencies
192193
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2506" }

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ block producer rewards on-chain. Handling of the transfers is left to the chain
5959
* `delete_metadata` extrinsic in `pallet-block-producer-metadata`
6060
* Added litep2p networking stack support to pc demo node as default. libp2p can be set with explicitly `--network-backend` parameter
6161
* Added `CARDANO_DATA_SOURCE` env variable to determine data source for partner-chains. `db-sync` value is used by default
62+
* Added support for querying Db-Sync database when `tx-in.value` configuration field is set to `"consumed"`.
63+
The data sources will automatically detect this option on startup and adjust their queries accordingly.
6264

6365
## Fixed
6466

dev/local-environment/configurations/db-sync/config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"insert_options": {
3+
"tx_output": {
4+
"value": "consumed"
5+
}
6+
},
27
"EnableLogMetrics": false,
38
"EnableLogging": true,
49
"NetworkName": "Testnet",
@@ -176,4 +181,4 @@
176181
"scRotation": null
177182
}
178183
]
179-
}
184+
}

toolkit/data-sources/db-sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tokio-test = "0.4.3"
5656
ctor = "0.4.1"
5757
testcontainers-modules = { version = "0.1.3", features = ["postgres"] }
5858
pretty_assertions = { workspace = true }
59+
paste = { workspace = true }
5960

6061
[features]
6162
default = []

toolkit/data-sources/db-sync/src/block/tests.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::str::FromStr;
99
const BLOCK_4_TS_MILLIS: u64 = 1650561570000;
1010
const BLOCK_5_TS_MILLIS: u64 = 1650562570000;
1111

12-
#[sqlx::test(migrations = "./testdata/migrations")]
12+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
1313
async fn get_latest_block_info(pool: PgPool) {
1414
let irrelevant_security_parameter = 1000;
1515
let source = mk_datasource(pool, irrelevant_security_parameter);
@@ -29,7 +29,7 @@ async fn get_latest_block_info(pool: PgPool) {
2929
assert_eq!(block, expected)
3030
}
3131

32-
#[sqlx::test(migrations = "./testdata/migrations")]
32+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
3333
async fn test_get_latest_stable_block(pool: PgPool) {
3434
let security_parameter = 2;
3535
let source = mk_datasource(pool, security_parameter);
@@ -43,7 +43,7 @@ async fn test_get_latest_stable_block(pool: PgPool) {
4343
assert_eq!(block, Some(expected))
4444
}
4545

46-
#[sqlx::test(migrations = "./testdata/migrations")]
46+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
4747
async fn test_get_latest_stable_block_at_filters_out_by_max_slot_boundary(pool: PgPool) {
4848
let security_parameter = 2;
4949
let slots_distance_between_blocks = block_4().slot.0 - block_2().slot.0;
@@ -58,7 +58,7 @@ async fn test_get_latest_stable_block_at_filters_out_by_max_slot_boundary(pool:
5858
assert_eq!(block, None)
5959
}
6060

61-
#[sqlx::test(migrations = "./testdata/migrations")]
61+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
6262
async fn test_get_stable_block_at(pool: PgPool) {
6363
let security_parameter = 2;
6464
let source = mk_datasource(pool, security_parameter);
@@ -70,7 +70,7 @@ async fn test_get_stable_block_at(pool: PgPool) {
7070
assert_eq!(block, Some(block_2()));
7171
}
7272

73-
#[sqlx::test(migrations = "./testdata/migrations")]
73+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
7474
async fn test_get_stable_block_at_returns_block_that_dont_have_k_blocks_on_them_at_given_timestamp(
7575
pool: PgPool,
7676
) {
@@ -85,7 +85,7 @@ async fn test_get_stable_block_at_returns_block_that_dont_have_k_blocks_on_them_
8585
assert_eq!(block, Some(block_2()));
8686
}
8787

88-
#[sqlx::test(migrations = "./testdata/migrations")]
88+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
8989
async fn test_get_stable_block_at_filters_out_by_min_slots_boundary(pool: PgPool) {
9090
let security_parameter = 3;
9191
let slots_distance_between_blocks = block_4().slot.0 - block_2().slot.0;
@@ -104,7 +104,7 @@ async fn test_get_stable_block_at_filters_out_by_min_slots_boundary(pool: PgPool
104104
assert_eq!(block, None);
105105
}
106106

107-
#[sqlx::test(migrations = "./testdata/migrations")]
107+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
108108
async fn test_get_stable_block_at_filters_out_by_max_slots_boundary(pool: PgPool) {
109109
let security_parameter = 2;
110110
let slots_distance_between_blocks = block_4().slot.0 - block_2().slot.0;
@@ -123,7 +123,7 @@ async fn test_get_stable_block_at_filters_out_by_max_slots_boundary(pool: PgPool
123123
assert_eq!(block, None);
124124
}
125125

126-
#[sqlx::test(migrations = "./testdata/migrations")]
126+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
127127
async fn test_get_stable_block_info_by_hash_for_unknown_hash(pool: PgPool) {
128128
let source = mk_datasource(pool, 2);
129129
let unknown_hash =
@@ -135,7 +135,7 @@ async fn test_get_stable_block_info_by_hash_for_unknown_hash(pool: PgPool) {
135135
assert_eq!(result, None)
136136
}
137137

138-
#[sqlx::test(migrations = "./testdata/migrations")]
138+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
139139
async fn test_get_latest_stable_block_with_stability_margin(pool: PgPool) {
140140
let security_parameter = 2;
141141
let stability_margin = 1;
@@ -164,7 +164,7 @@ async fn test_get_latest_stable_block_with_stability_margin(pool: PgPool) {
164164
assert_eq!(block, None);
165165
}
166166

167-
#[sqlx::test(migrations = "./testdata/migrations")]
167+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
168168
async fn test_get_latest_stable_block_with_stability_margin_2(pool: PgPool) {
169169
let security_parameter = 2;
170170
let stability_margin = 0;
@@ -190,7 +190,7 @@ async fn test_get_latest_stable_block_with_stability_margin_2(pool: PgPool) {
190190
assert_eq!(block, Some(block_0()));
191191
}
192192

193-
#[sqlx::test(migrations = "./testdata/migrations")]
193+
#[sqlx::test(migrations = "./testdata/migrations-tx-in-consumed")]
194194
async fn test_get_stable_block_caching(pool: PgPool) {
195195
fn dummy_hash(n: u8) -> McBlockHash {
196196
McBlockHash([n; 32])

toolkit/data-sources/db-sync/src/candidates/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Db-Sync data source used by Partner Chain committee selection
22
use crate::DataSourceError::*;
33
use crate::db_model::{
4-
self, Address, Asset, BlockNumber, EpochNumber, MainchainTxOutput, StakePoolEntry,
4+
self, Address, Asset, BlockNumber, DbSyncConfigurationProvider, EpochNumber, MainchainTxOutput,
5+
StakePoolEntry,
56
};
67
use crate::metrics::McFollowerMetrics;
78
use crate::observed_async_trait;
@@ -49,6 +50,8 @@ pub struct CandidatesDataSourceImpl {
4950
pool: PgPool,
5051
/// Prometheus metrics client
5152
metrics_opt: Option<McFollowerMetrics>,
53+
/// Configuration used by Db-Sync
54+
db_sync_config: DbSyncConfigurationProvider,
5255
}
5356

5457
observed_async_trait!(
@@ -126,7 +129,11 @@ impl CandidatesDataSourceImpl {
126129
) -> Result<CandidatesDataSourceImpl, Box<dyn std::error::Error + Send + Sync>> {
127130
db_model::create_idx_ma_tx_out_ident(&pool).await?;
128131
db_model::create_idx_tx_out_address(&pool).await?;
129-
Ok(Self { pool, metrics_opt })
132+
Ok(Self {
133+
pool: pool.clone(),
134+
metrics_opt,
135+
db_sync_config: DbSyncConfigurationProvider::new(pool),
136+
})
130137
}
131138

132139
/// Creates a new caching instance of the data source
@@ -154,7 +161,15 @@ impl CandidatesDataSourceImpl {
154161
let registrations_block_for_epoch = self.get_last_block_for_epoch(epoch).await?;
155162
let address: Address = Address(committee_candidate_address.to_string());
156163
let active_utxos = match registrations_block_for_epoch {
157-
Some(block) => db_model::get_utxos_for_address(&self.pool, &address, block).await?,
164+
Some(block) => {
165+
db_model::get_utxos_for_address(
166+
&self.pool,
167+
&address,
168+
block,
169+
self.db_sync_config.get_tx_in_config().await?,
170+
)
171+
.await?
172+
},
158173
None => vec![],
159174
};
160175
self.convert_utxos_to_candidates(&active_utxos)

0 commit comments

Comments
 (0)