fix: update get_block_storage_changes to correctly emit previous value (#280)
Before this commit we were using the latest `ContractSlot` for both previous and new value. This is not correct because if the value changed twice we would have the middle value emitted as "previous". For example if a value was changed like this in a single transaction 1 -> 10 -> 2 we would have `new_value=2` and `previous_values=10` while the previous value was actually 1. Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
This commit is contained in:
34
substreams/Cargo.lock
generated
34
substreams/Cargo.lock
generated
@@ -250,7 +250,7 @@ dependencies = [
|
|||||||
"num-bigint",
|
"num-bigint",
|
||||||
"substreams",
|
"substreams",
|
||||||
"substreams-ethereum",
|
"substreams-ethereum",
|
||||||
"tycho-substreams 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tycho-substreams 0.5.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1758,22 +1758,6 @@ dependencies = [
|
|||||||
"substreams-ethereum",
|
"substreams-ethereum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tycho-substreams"
|
|
||||||
version = "0.5.0"
|
|
||||||
dependencies = [
|
|
||||||
"ethabi 18.0.0",
|
|
||||||
"hex",
|
|
||||||
"itertools 0.12.1",
|
|
||||||
"num-bigint",
|
|
||||||
"prost 0.11.9",
|
|
||||||
"rstest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"substreams",
|
|
||||||
"substreams-ethereum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tycho-substreams"
|
name = "tycho-substreams"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -1791,6 +1775,22 @@ dependencies = [
|
|||||||
"substreams-ethereum",
|
"substreams-ethereum",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tycho-substreams"
|
||||||
|
version = "0.5.1"
|
||||||
|
dependencies = [
|
||||||
|
"ethabi 18.0.0",
|
||||||
|
"hex",
|
||||||
|
"itertools 0.12.1",
|
||||||
|
"num-bigint",
|
||||||
|
"prost 0.11.9",
|
||||||
|
"rstest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"substreams",
|
||||||
|
"substreams-ethereum",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.17.0"
|
version = "1.17.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tycho-substreams"
|
name = "tycho-substreams"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Tycho substreams development kit, contains tycho-indexer block changes model and helper functions for common indexing tasks."
|
description = "Tycho substreams development kit, contains tycho-indexer block changes model and helper functions for common indexing tasks."
|
||||||
repository = "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/crates/tycho-substreams"
|
repository = "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/crates/tycho-substreams"
|
||||||
|
|||||||
@@ -54,14 +54,18 @@ pub fn get_block_storage_changes(block: ð::v2::Block) -> Vec<TransactionStora
|
|||||||
// Collect latest change per slot
|
// Collect latest change per slot
|
||||||
let mut latest_changes: HashMap<Vec<u8>, ContractSlot> = HashMap::new();
|
let mut latest_changes: HashMap<Vec<u8>, ContractSlot> = HashMap::new();
|
||||||
for change in changes {
|
for change in changes {
|
||||||
latest_changes.insert(
|
latest_changes
|
||||||
change.key.clone(),
|
.entry(change.key.clone())
|
||||||
ContractSlot {
|
.and_modify(|slot| {
|
||||||
|
// Only update the latest value, previous value stays the first seen
|
||||||
|
// one.
|
||||||
|
slot.value = change.new_value.clone();
|
||||||
|
})
|
||||||
|
.or_insert(ContractSlot {
|
||||||
slot: change.key,
|
slot: change.key,
|
||||||
value: change.new_value,
|
value: change.new_value,
|
||||||
previous_value: change.old_value,
|
previous_value: change.old_value,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageChanges { address, slots: latest_changes.into_values().collect() }
|
StorageChanges { address, slots: latest_changes.into_values().collect() }
|
||||||
|
|||||||
Reference in New Issue
Block a user