Skip to content

Commit

Permalink
Merge pull request #2582 from dusk-network/neotamandua/txhash_hex_ser…
Browse files Browse the repository at this point in the history
…ialize

Change TxHash Serialization to Hex
  • Loading branch information
Neotamandua authored Oct 3, 2024
2 parents d252836 + 65eb283 commit 2c0000b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion node-data/src/events/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ pub const TX_HASH_BYTES: usize = 32;
pub type TxHash = [u8; TX_HASH_BYTES];

/// Contract event with optional origin (tx hash).
#[serde_with::serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ContractTxEvent {
pub event: ContractEvent,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<serde_with::hex::Hex>")]
pub origin: Option<TxHash>,
}

Expand Down
3 changes: 2 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ memory-stats = { workspace = true }
# archive feature dependencies
sqlx = { version = "=0.7.4", features = [ "runtime-tokio", "tls-native-tls", "sqlite", "migrate"], optional = true }
serde_json = { workspace = true, optional = true }
serde_with = { workspace = true, features = ["hex"], optional = true }

[dev-dependencies]
fake = { workspace = true, features = ['derive'] }
Expand All @@ -46,7 +47,7 @@ criterion = { workspace = true, features = ["async_futures"] }

[features]
with_telemetry = []
archive = ["dep:sqlx", "dep:serde_json"]
archive = ["dep:sqlx", "dep:serde_json", "dep:serde_with"]

[[bench]]
name = "accept"
Expand Down
6 changes: 5 additions & 1 deletion node/src/archive/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rocksdb::{
BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, LogLevel,
OptimisticTransactionDB, Options,
};
use tracing::{info, warn};
use tracing::{debug, info, warn};

use crate::archive::transformer::{self, MoonlightTxEvents};
use crate::archive::{Archive, ArchiveOptions};
Expand Down Expand Up @@ -106,9 +106,13 @@ impl Archive {
&self,
block_events: Vec<ContractTxEvent>,
) -> Result<()> {
debug!("Loading moonlight transaction events into the moonlight db");

let (address_mappings, _, moonlight_groups) =
transformer::group_by_origins_filter_and_convert(block_events);

debug!("Found {} moonlight transactions", moonlight_groups.len());

let address_mappings = util::check_duplicates(address_mappings);

for mapping in address_mappings {
Expand Down
2 changes: 2 additions & 0 deletions node/src/archive/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ use serde::{Deserialize, Serialize};

/// More efficient format for events that belong to the same tx to not duplicate
/// TxHash
#[serde_with::serde_as]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MoonlightTxEvents {
events: Vec<ContractEvent>,
#[serde_as(as = "serde_with::hex::Hex")]
origin: TxHash,
}

Expand Down

0 comments on commit 2c0000b

Please sign in to comment.