Skip to content

Commit

Permalink
Dynamically load custom network configs
Browse files Browse the repository at this point in the history
  • Loading branch information
rooooooooob committed Aug 7, 2024
1 parent 20ae27d commit 59dddc4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
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

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

0 comments on commit 59dddc4

Please sign in to comment.