Skip to content

Commit

Permalink
Tmp fix commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gostkin committed Nov 8, 2023
1 parent 6071e28 commit 72ad950
Show file tree
Hide file tree
Showing 29 changed files with 107 additions and 56 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ base64 = { version = "0.21.0" }
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" }
clap = { version = "3.1", features = ["derive"] }
ctrlc = { version = "3.2.4", features = ["termination"] }
dotenv = { version = "0.15.0" }
Expand Down
17 changes: 3 additions & 14 deletions indexer/entity/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use pallas::ledger::traverse::Era;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -31,6 +30,7 @@ pub enum EraValue {
Mary,
Alonzo,
Babbage,
Conway,
}

impl From<EraValue> for i32 {
Expand All @@ -42,6 +42,7 @@ impl From<EraValue> for i32 {
EraValue::Mary => 3,
EraValue::Alonzo => 4,
EraValue::Babbage => 5,
EraValue::Conway => 6,
}
}
}
Expand All @@ -57,20 +58,8 @@ impl TryFrom<i32> for EraValue {
3 => Ok(EraValue::Mary),
4 => Ok(EraValue::Alonzo),
5 => Ok(EraValue::Babbage),
6 => Ok(EraValue::Conway),
_ => Err(()),
}
}
}

impl From<EraValue> for Era {
fn from(item: EraValue) -> Self {
match item {
EraValue::Byron => Era::Byron,
EraValue::Shelley => Era::Shelley,
EraValue::Allegra => Era::Allegra,
EraValue::Mary => Era::Mary,
EraValue::Alonzo => Era::Alonzo,
EraValue::Babbage => Era::Babbage,
}
}
}
23 changes: 12 additions & 11 deletions indexer/src/sinks/cardano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 @@ -254,14 +255,14 @@ impl StoppableService for CardanoSink {
}
}

fn to_era_value(x: pallas::ledger::traverse::Era) -> EraValue {
fn to_era_value(x: &MultiEraBlock) -> EraValue {
match x {
pallas::ledger::traverse::Era::Byron => EraValue::Byron,
pallas::ledger::traverse::Era::Shelley => EraValue::Shelley,
pallas::ledger::traverse::Era::Allegra => EraValue::Allegra,
pallas::ledger::traverse::Era::Mary => EraValue::Mary,
pallas::ledger::traverse::Era::Alonzo => EraValue::Alonzo,
pallas::ledger::traverse::Era::Babbage => EraValue::Babbage,
MultiEraBlock::Byron(_) => EraValue::Byron,
MultiEraBlock::Shelley(_) => EraValue::Shelley,
MultiEraBlock::Allegra(_) => EraValue::Allegra,
MultiEraBlock::Mary(_) => EraValue::Mary,
MultiEraBlock::Alonzo(_) => EraValue::Alonzo,
MultiEraBlock::Babbage(_) => EraValue::Babbage,
_ => unreachable!("all known eras are handled"),
}
}
Expand All @@ -279,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::decode(&block_payload).unwrap();
let multi_block = MultiEraBlock::from_bytes(block_payload).unwrap();

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

perf_aggregator.block_parse += block_parse_counter.elapsed();

match &multi_block.era() {
pallas::ledger::traverse::Era::Byron => {
match &multi_block {
MultiEraBlock::Byron(byron) => {
process_byron_block(
txn,
(&cbor_hex, &multi_block, &block_global_info),
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;

pub type MultiEraBlock<'b> = pallas::ledger::traverse::MultiEraBlock<'b>;
pub type MultiEraBlock = cml_multi_era::MultiEraBlock;

#[async_trait]
pub trait StoppableService {
Expand Down
1 change: 1 addition & 0 deletions indexer/tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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" }
cfg-if = { version = "0.1.10" }
cryptoxide = { version = "0.4.2" }
hex = { version = "0.4.3" }
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/byron/byron_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ carp_task! {

async fn handle_addresses(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
byron_txs: &[TransactionModel],
) -> Result<BTreeMap<Vec<u8>, AddressInBlock>, DbErr> {
match &block.1 {
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/byron/byron_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ carp_task! {

async fn handle_block(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
readonly: bool,
include_payload: bool,
) -> Result<BlockModel, DbErr> {
Expand Down
3 changes: 1 addition & 2 deletions indexer/tasks/src/byron/byron_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use crate::utils::find_task_registry_entry;
use crate::utils::TaskPerfAggregator;
use entity::sea_orm::{prelude::*, DatabaseTransaction};
use pallas::ledger::primitives::byron::{self};
use pallas::ledger::traverse::MultiEraBlock;
use shred::{DispatcherBuilder, World};
use tokio::runtime::Handle;

pub async fn process_byron_block(
txn: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
exec_plan: &ExecutionPlan,
perf_aggregator: Arc<Mutex<TaskPerfAggregator>>,
) -> Result<(), DbErr> {
Expand Down
44 changes: 43 additions & 1 deletion indexer/tasks/src/byron/byron_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use cml_multi_era::byron::block::ByronBlock;
use cml_multi_era::byron::transaction::{ByronTx, ByronTxIn};
use cml_multi_era::MultiEraBlock;
use crate::dsl::task_macro::*;
use pallas::ledger::primitives::byron::{self, TxIn};

Expand Down Expand Up @@ -29,9 +32,48 @@ carp_task! {

async fn handle_inputs(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
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
.iter()
.flat_map(|tx| tx.inputs
.iter()
.map(|input|
(input.transaction_id, input.index)
)
)
}
MultiEraBlock::Allegra(_) => {}
MultiEraBlock::Mary(_) => {}
MultiEraBlock::Alonzo(_) => {}
MultiEraBlock::Babbage(_) => {}
MultiEraBlock::Conway(_) => {}
}
let flattened_inputs: Vec<(Vec<pallas::ledger::traverse::OutputRef>, i64)> = block
.1
.txs()
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/byron/byron_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ carp_task! {

async fn handle_outputs(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
byron_txs: &[TransactionModel],
byron_addresses: &BTreeMap<Vec<u8>, AddressInBlock>,
) -> Result<Vec<TransactionOutputModel>, DbErr> {
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/byron/byron_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ carp_task! {

async fn handle_tx(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
database_block: &BlockModel,
readonly: bool,
include_payload: bool,
Expand Down
5 changes: 2 additions & 3 deletions indexer/tasks/src/dsl/database_task.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::utils::TaskPerfAggregator;
use cml_chain::genesis::byron::config::GenesisData;
use entity::{block::EraValue, prelude::*, sea_orm::DatabaseTransaction};
use pallas::ledger::traverse::MultiEraBlock;
use shred::DispatcherBuilder;
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -67,12 +66,12 @@ pub struct GenesisTaskRegistryEntry {

#[derive(Copy, Clone)]
pub struct ByronTaskRegistryEntry {
pub builder: &'static (dyn for<'a> TaskBuilder<'a, MultiEraBlock<'a>, BlockGlobalInfo> + Sync),
pub builder: &'static (dyn for<'a> TaskBuilder<'a, cml_multi_era::MultiEraBlock, BlockGlobalInfo> + Sync),
}

#[derive(Copy, Clone)]
pub struct MultieraTaskRegistryEntry {
pub builder: &'static (dyn for<'a> TaskBuilder<'a, MultiEraBlock<'a>, BlockGlobalInfo> + Sync),
pub builder: &'static (dyn for<'a> TaskBuilder<'a, cml_multi_era::MultiEraBlock, BlockGlobalInfo> + Sync),
}

inventory::collect!(TaskRegistryEntry);
2 changes: 1 addition & 1 deletion indexer/tasks/src/dsl/example_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ carp_task! {

async fn handle_dummy(
_db_tx: &DatabaseTransaction,
_block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
_block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
) -> Result<(), DbErr> {
Ok(())
}
5 changes: 2 additions & 3 deletions indexer/tasks/src/dsl/task_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub use crate::{
utils::TaskPerfAggregator,
};
pub use cml_chain::genesis::byron::config::GenesisData;
pub use pallas::ledger::traverse::MultiEraBlock;
pub use paste::paste;
pub use shred::{DispatcherBuilder, Read, ResourceId, System, SystemData, World, Write};
pub use std::sync::{Arc, Mutex};
Expand All @@ -19,10 +18,10 @@ macro_rules! era_to_block {
GenesisData
};
(byron) => {
MultiEraBlock<'a>
cml_multi_era::MultiEraBlock
};
(multiera) => {
MultiEraBlock<'a>
cml_multi_era::MultiEraBlock
};
}

Expand Down
3 changes: 1 addition & 2 deletions indexer/tasks/src/era_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use entity::{
QueryOrder, QuerySelect, Set,
},
};
use pallas::ledger::traverse::Era;
use std::collections::BTreeMap;

static ADDRESS_TRUNCATE: usize = 500; // 1000 in hex
Expand Down Expand Up @@ -120,7 +119,7 @@ pub async fn insert_addresses(
pub struct OutputWithTxData {
pub model: TransactionOutputModel,
pub tx_hash: Vec<u8>,
pub era: Era,
pub era: EraValue,
}

pub async fn get_outputs_for_inputs(
Expand Down
4 changes: 2 additions & 2 deletions indexer/tasks/src/multiera/dex/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl DexType {

pub async fn handle_mean_price(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
multiera_addresses: &BTreeMap<Vec<u8>, AddressInBlock>,
pool_type: DexType,
Expand Down Expand Up @@ -260,7 +260,7 @@ pub fn reduce_ada_amount(pair: &AssetPair, amount: u64) -> u64 {

pub async fn handle_swap(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
multiera_addresses: &BTreeMap<Vec<u8>, AddressInBlock>,
multiera_used_inputs_to_outputs_map: &BTreeMap<Vec<u8>, BTreeMap<i64, OutputWithTxData>>,
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/multiera/multiera_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ carp_task! {

async fn handle_addresses(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
vkey_relation_map: &mut RelationMap,
) -> Result<
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/multiera/multiera_asset_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ carp_task! {

async fn handle_mints(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
readonly: bool,
) -> Result<Vec<NativeAssetModel>, DbErr> {
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/multiera/multiera_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ carp_task! {

async fn handle_block(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
readonly: bool,
include_payload: bool,
) -> Result<BlockModel, DbErr> {
Expand Down
2 changes: 1 addition & 1 deletion indexer/tasks/src/multiera/multiera_datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ merge_result |previous_data, _result| {

async fn handle_datum(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
block: BlockInfo<'_, cml_multi_era::MultiEraBlock, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
readonly: bool,
) -> Result<(), DbErr> {
Expand Down
Loading

0 comments on commit 72ad950

Please sign in to comment.