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

Support dynamically specified networks #187

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 6 additions & 4 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ strip = true

[dependencies]
# [core]
dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }
dcspark-blockchain-source = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }
multiverse = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }

dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "98c21b8d6c4f72a1c1813eaec3b9ccf1ff67106e" }
dcspark-blockchain-source = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "98c21b8d6c4f72a1c1813eaec3b9ccf1ff67106e" }
#dcspark-core = { path = "../../dcspark-core/core" }
#dcspark-blockchain-source = { path = "../../dcspark-core/blockchain-source" }
#multiverse = { path = "../../dcspark-core/multiverse" }
multiverse = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "98c21b8d6c4f72a1c1813eaec3b9ccf1ff67106e" }
# [local]
entity = { path = "entity" }
migration = { path = "migration" }
Expand Down
38 changes: 38 additions & 0 deletions indexer/configs/custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
source:
type: cardano_net
relay:
- localhost
- 3001

sink:
type: cardano
db:
type: postgres
database_url: postgresql://carp:1234@localhost:5432/carp_custom5
network: custom # preview / preprod / testnet / custom
genesis_folder: /home/user/Cardano/carp/indexer/genesis/
custom_config:
chain_info:
network_id: 1
protocol_magic: 42
relay:
- "localhost"
- 3001
from:
BlockHeader:
slot_nb: 1
hash: "ba8066f73eb9cf4ad9adf38051c54d3a51d92cb98561cffc1f202b1b97739cd5"
genesis_parent: "0ded594a3411f6d3236228abc1e2ef8c2a21e09d859ea23bfc2182f92853cba8"
genesis:
BlockHeader:
slot_nb: 0
hash: "7a32184d9e0068b0fa75fd0ecaad798f9bc573d4921c519b12968e26ff0747a3"
shelley_era_config:
first_slot: 0
start_epoch: 0
known_time: 1722355346
slot_length: 1
epoch_length_seconds: 500
Copy link
Contributor Author

@SebastienGllmt SebastienGllmt Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced about this approach. How would you convert the yaci-devkit to this data type dynamically?

Especially because the genesis config can contain stuff that we actually have to insert into the database (ex: for Shelley, the Shelley config can contain some default pools and registrations for the Shelley era that Carp would have to know about)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do the config file dynamically with the env variable, wouldn't that be enough?


start_block:

52 changes: 15 additions & 37 deletions indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub enum SinkConfig {
Cardano {
db: DbConfig,
network: String,
/// Custom configuration. If not present it will be inferred from the network name
custom_config: Option<dcspark_blockchain_source::cardano::NetworkConfiguration>,
genesis_folder: Option<String>,
},
}
Expand Down Expand Up @@ -158,10 +160,20 @@ async fn main() -> anyhow::Result<()> {
config
};

let (network, mut sink) = match config.sink {
SinkConfig::Cardano { ref network, .. } => (
let (network, base_config, mut sink) = match &config.sink {
SinkConfig::Cardano { network, custom_config, .. } => (
network.clone(),
CardanoSink::new(config.sink, exec_plan)
match custom_config {
Some(custom_config) => custom_config.clone(),
None => match network.as_ref() {
"mainnet" => dcspark_blockchain_source::cardano::NetworkConfiguration::mainnet(),
"preprod" => dcspark_blockchain_source::cardano::NetworkConfiguration::preprod(),
"preview" => dcspark_blockchain_source::cardano::NetworkConfiguration::preview(),
"custom" => panic!("sink.custom_config is mandatory when setting network to custom"),
unknown_network => return Err(anyhow::anyhow!("network {unknown_network} not supported by source")),
}
},
CardanoSink::new(config.sink.clone(), exec_plan)
.await
.context("Can't create cardano sink")?,
),
Expand All @@ -184,40 +196,6 @@ async fn main() -> anyhow::Result<()> {
main_loop(source, sink, start_from, running, processing_finished).await
}
SourceConfig::CardanoNet { relay } => {
let base_config = match network.as_ref() {
"mainnet" => dcspark_blockchain_source::cardano::NetworkConfiguration::mainnet(),
"preprod" => dcspark_blockchain_source::cardano::NetworkConfiguration::preprod(),
"preview" => dcspark_blockchain_source::cardano::NetworkConfiguration::preview(),
"custom" => dcspark_blockchain_source::cardano::NetworkConfiguration {
// TODO: dynamically fill in all of this
chain_info: dcspark_blockchain_source::cardano::ChainInfo::Custom {
protocol_magic: 0,
network_id: 0,
},
relay: (Cow::Borrowed("preprod-node.world.dev.cardano.org."), 30000),
from: dcspark_blockchain_source::cardano::Point::BlockHeader {
slot_nb: dcspark_core::SlotNumber::new(86400),
hash: dcspark_core::BlockId::new(
"c4a1595c5cc7a31eda9e544986fe9387af4e3491afe0ca9a80714f01951bbd5c",
),
},
genesis_parent: dcspark_core::BlockId::new(
"d4b8de7a11d929a323373cbab6c1a9bdc931beffff11db111cf9d57356ee1937",
),
genesis: dcspark_core::BlockId::new(
"9ad7ff320c9cf74e0f5ee78d22a85ce42bb0a487d0506bf60cfb5a91ea4497d2",
),
shelley_era_config: dcspark_blockchain_source::cardano::time::Era {
first_slot: 4492800,
start_epoch: 208,
known_time: 1596059091,
slot_length: 1,
epoch_length_seconds: 432000,
},
},
_ => return Err(anyhow::anyhow!("network not supported by source")),
};

// try to find a confirmed point.
//
// this way the multiverse can be temporary, which saves setting up the extra db
Expand Down
1 change: 1 addition & 0 deletions indexer/src/sinks/cardano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl CardanoSink {
SinkConfig::Cardano {
db,
network,
custom_config: _,
genesis_folder,
} => (db, network, genesis_folder),
_ => todo!("Invalid sink config provided"),
Expand Down
Loading