Skip to content

Commit

Permalink
feat!: update CML to newest version
Browse files Browse the repository at this point in the history
  • Loading branch information
gostkin committed Jan 29, 2024
1 parent 68aa177 commit 073d347
Show file tree
Hide file tree
Showing 43 changed files with 1,443 additions and 1,111 deletions.
943 changes: 582 additions & 361 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ tasks = { path = "tasks" }
# [indexer]
anyhow = { version = "1.0.69" }
async-trait = { version = "0.1.64" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
clap = { version = "3.1", features = ["derive"] }
ctrlc = { version = "3.2.4", features = ["termination"] }
dotenv = { version = "0.15.0" }
Expand Down
7 changes: 4 additions & 3 deletions indexer/reparse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ entity = { path = "../entity" }

# [reparse]
anyhow = { version = "1.0.69" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
dotenv = { version = "0.15.0" }
futures = { version = "0.3.21" }
hex = { version = "0.4.0" }
Expand Down
63 changes: 0 additions & 63 deletions indexer/src/benchmark.rs

This file was deleted.

8 changes: 4 additions & 4 deletions indexer/src/sinks/cardano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::sink::Sink;
use crate::types::{MultiEraBlock, StoppableService};
use crate::{genesis, DbConfig, SinkConfig};
use async_trait::async_trait;

use dcspark_blockchain_source::cardano::Point;
use dcspark_core::{BlockId, SlotNumber};
use entity::sea_orm::Database;
Expand All @@ -18,7 +19,6 @@ use entity::{
};
use std::sync::Arc;
use std::sync::Mutex;
use cml_core::serialization::FromBytes;
use tasks::byron::byron_executor::process_byron_block;
use tasks::dsl::database_task::BlockGlobalInfo;
use tasks::execution_plan::ExecutionPlan;
Expand Down Expand Up @@ -280,18 +280,18 @@ async fn insert_block(
let block_parse_counter = std::time::Instant::now();

let block_payload = hex::decode(cbor_hex.clone()).unwrap();
let multi_block = MultiEraBlock::from_bytes(block_payload).unwrap();
let multi_block = MultiEraBlock::from_explicit_network_cbor_bytes(&block_payload).unwrap();

let block_global_info = BlockGlobalInfo {
era: to_era_value(multi_block),
era: to_era_value(&multi_block),
epoch,
epoch_slot,
};

perf_aggregator.block_parse += block_parse_counter.elapsed();

match &multi_block {
MultiEraBlock::Byron(byron) => {
MultiEraBlock::Byron(_byron) => {
process_byron_block(
txn,
(&cbor_hex, &multi_block, &block_global_info),
Expand Down
13 changes: 8 additions & 5 deletions indexer/tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ edition = "2021"
name = "tasks"

[dependencies]
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" }

# [local]
entity = { path = "../entity" }

# [tasks]
anyhow = { version = "1.0.69" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "e231f1eab743b3cb7c5464cd8ed9ffda29631b97" }
projected-nft-sdk = { git = "https://github.com/dcSpark/projected-nft-whirlpool.git", rev = "a350ccfcbdef22b73c93561c6816bd42b13f00ff" }
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-crypto = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "c5740393f10b7a68aa4719fbbef5a49170501ef6" }
cardano-projected-nft = { git = "https://github.com/dcSpark/projected-nft-whirlpool.git", rev = "7ba9a2f7a613f38bbce8f48a7d8575739e9caee0" }
cfg-if = { version = "0.1.10" }
cryptoxide = { version = "0.4.2" }
hex = { version = "0.4.3" }
Expand Down
31 changes: 14 additions & 17 deletions indexer/tasks/src/byron/byron_address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pallas::ledger::primitives::{
byron::{self},
Fragment,
};
use cml_core::serialization::ToBytes;
use cml_multi_era::byron::block::ByronBlock;
use cml_multi_era::MultiEraBlock;

use super::byron_txs::ByronTransactionTask;
use crate::config::EmptyConfig::EmptyConfig;
Expand All @@ -18,14 +17,7 @@ carp_task! {
write [byron_addresses];
should_add_task |block, _properties| {
// recall: txs may have no outputs if they just burn all inputs as fee
match block.1 {
MultiEraBlock::Byron(main_block) => {
main_block
.body
.tx_payload.iter().any(|payload| payload.transaction.outputs.len() > 0)
}
_ => false,
}
block.1.transaction_bodies().iter().any(|tx| !tx.outputs().is_empty())
};
execute |previous_data, task| handle_addresses(
task.db_tx,
Expand All @@ -44,11 +36,16 @@ async fn handle_addresses(
) -> Result<BTreeMap<Vec<u8>, AddressInBlock>, DbErr> {
match &block.1 {
MultiEraBlock::Byron(main_block) => {
let tx_outputs: Vec<_> = main_block
.body
.tx_payload
let payload = match main_block {
ByronBlock::Main(main) => main.body.tx_payload.clone(),
ByronBlock::EpochBoundary(_) => {
return Ok(BTreeMap::<Vec<u8>, AddressInBlock>::default());
}
};

let tx_outputs: Vec<_> = payload
.iter()
.map(|payload| &payload.transaction.outputs)
.map(|payload| &payload.byron_tx.outputs)
.zip(byron_txs)
.collect();

Expand All @@ -60,7 +57,7 @@ async fn handle_addresses(
for (address, tx_id) in tx_outputs
.iter()
.flat_map(|pair| pair.0.iter().zip(std::iter::repeat(pair.1.id)))
.map(|(output, tx_id)| (output.address.encode_fragment().unwrap(), tx_id))
.map(|(output, tx_id)| (output.address.to_bytes(), tx_id))
{
// we want to keep track of the first tx for each address
queued_address.entry(address).or_insert(tx_id);
Expand Down
27 changes: 21 additions & 6 deletions indexer/tasks/src/byron/byron_block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::config::PayloadAndReadonlyConfig::PayloadAndReadonlyConfig;
use crate::dsl::task_macro::*;
use crate::era_common::block_from_hash;
use cml_core::serialization::ToBytes;
use cml_crypto::{blake2b256, RawBytesEncoding};
use cml_multi_era::byron::block::ByronBlock;
use cml_multi_era::MultiEraBlock;
use entity::{block::EraValue, sea_orm::Set};
use hex::ToHex;
use pallas::ledger::primitives::{byron, Fragment};
use sea_orm::sea_query::all;

carp_task! {
name ByronBlockTask;
Expand Down Expand Up @@ -33,22 +37,33 @@ async fn handle_block(
readonly: bool,
include_payload: bool,
) -> Result<BlockModel, DbErr> {
let hash = block.1.hash().to_vec();
let hash = block.1.hash();

if readonly {
return block_from_hash(db_tx, &hash).await;
}

let block_epoch = match block.1 {
MultiEraBlock::Byron(byron) => match byron {
ByronBlock::EpochBoundary(byron) => byron.header.consensus_data.epoch_id,
ByronBlock::Main(byron) => byron.header.consensus_data.byron_slot_id.epoch,
},
_ => {
return Err(DbErr::Custom("Non-byron block in byron task".to_string()));
}
};

let block_payload = if include_payload {
hex::decode(block.0).unwrap()
} else {
vec![]
};
let block = BlockActiveModel {
era: Set(EraValue::Byron.into()),
hash: Set(hash),
height: Set(block.1.number() as i32),
epoch: Set(block.1.header().as_byron().unwrap().consensus_data.0.epoch as i32),
slot: Set(block.1.slot() as i32),
hash: Set(hash.to_vec()),
height: Set(block.1.header().block_number() as i32),
epoch: Set(block_epoch as i32),
slot: Set(block.1.header().slot() as i32),
payload: Set(Some(block_payload)),
..Default::default()
};
Expand Down
1 change: 0 additions & 1 deletion indexer/tasks/src/byron/byron_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::execution_plan::ExecutionPlan;
use crate::utils::find_task_registry_entry;
use crate::utils::TaskPerfAggregator;
use entity::sea_orm::{prelude::*, DatabaseTransaction};
use pallas::ledger::primitives::byron::{self};
use shred::{DispatcherBuilder, World};
use tokio::runtime::Handle;

Expand Down
64 changes: 15 additions & 49 deletions indexer/tasks/src/byron/byron_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::dsl::task_macro::*;
use cml_multi_era::byron::block::ByronBlock;
use cml_multi_era::byron::transaction::{ByronTx, ByronTxIn};
use cml_multi_era::utils::MultiEraTransactionInput;
use cml_multi_era::MultiEraBlock;
use crate::dsl::task_macro::*;
use pallas::ledger::primitives::byron::{self, TxIn};

use super::byron_outputs::ByronOutputTask;
use crate::config::EmptyConfig::EmptyConfig;
Expand Down Expand Up @@ -35,56 +35,22 @@ async fn handle_inputs(
block: BlockInfo<'_, MultiEraBlock, BlockGlobalInfo>,
byron_txs: &[TransactionModel],
) -> Result<Vec<TransactionInputModel>, DbErr> {
match block.1 {
MultiEraBlock::Byron(ByronBlock::Main(block)) => {
block
.body
.tx_payload
.iter()
.map(|tx| {
tx
.byron_tx
.inputs
.iter()
.map(|input| {
match input {
ByronTxIn::ByronTxInRegular(regular) => {
(regular.index_1.byron_tx_id, regular.index_1.u32)
}
ByronTxIn::ByronTxInGenesis(genesis) => {
genesis.
}
}
})
})
}
MultiEraBlock::Shelley(block) => {
block.transaction_bodies
let txs = match block.1 {
MultiEraBlock::Byron(ByronBlock::Main(block)) => block.body.tx_payload.iter().map(|tx| {
tx.byron_tx
.inputs
.iter()
.flat_map(|tx| tx.inputs
.iter()
.map(|input|
(input.transaction_id, input.index)
)
)
.cloned()
.map(MultiEraTransactionInput::Byron)
}),
_ => {
return Ok(vec![]);
}
MultiEraBlock::Allegra(_) => {}
MultiEraBlock::Mary(_) => {}
MultiEraBlock::Alonzo(_) => {}
MultiEraBlock::Babbage(_) => {}
MultiEraBlock::Conway(_) => {}
}
let flattened_inputs: Vec<(Vec<pallas::ledger::traverse::OutputRef>, i64)> = block
.1
.txs()
.iter()
.zip(byron_txs)
.map(|(tx, cardano_tx_in_db)| {
let inputs: Vec<pallas::ledger::traverse::OutputRef> =
tx.inputs().iter().map(|x| x.output_ref()).collect();
};

(inputs, cardano_tx_in_db.id)
})
let flattened_inputs: Vec<(Vec<_>, i64)> = txs
.zip(byron_txs)
.map(|(inputs, cardano_tx_in_db)| (inputs.collect::<Vec<_>>(), cardano_tx_in_db.id))
.collect();

let outputs_for_inputs =
Expand Down
Loading

0 comments on commit 073d347

Please sign in to comment.