feat: Add entrypoint utils and define EntryPointParams (#211)

* feat: Add entrypoint utils and define EntryPointParams

#time 23m


#time 0m

* fix: Make TraceData mandatory

#time 2m

* fix: Make component_id in EntryPointParams optional

#time 1m
This commit is contained in:
dianacarvalho1
2025-05-20 17:47:25 +01:00
committed by GitHub
parent 7e73061f8e
commit a7841af383
6 changed files with 72 additions and 4 deletions

View File

@@ -168,7 +168,7 @@ message EntryPointParams {
// The entrypoint id.
string entrypoint_id = 1;
// [optional] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
string component_id = 2;
optional string component_id = 2;
// The strategy and its corresponding data
oneof trace_data {
RPCTraceData rpc = 3;

View File

@@ -5,7 +5,10 @@ plugins:
opt:
- file_descriptor_set=false
- type_attribute=.tycho.evm.v1.Transaction=#[derive(Eq\, Hash)]
- type_attribute=.tycho.evm.v1.TraceData=#[derive(Eq\, Hash)]
- type_attribute=.tycho.evm.v1.EntryPoint=#[derive(Eq\, Hash)]
- type_attribute=.tycho.evm.v1.EntryPointParams=#[derive(Eq\, Hash)]
- type_attribute=.tycho.evm.v1.RPCTraceData=#[derive(Eq\, Hash)]
- remote: buf.build/community/neoeinstein-prost-crate:v0.3.1
out: src/pb
opt: no_features

View File

@@ -0,0 +1,52 @@
use crate::models::{entry_point_params::TraceData, EntryPoint, EntryPointParams};
fn get_entrypoint_id(target: &[u8], signature: &str) -> String {
let target = hex::encode(target);
format!("{target}:{signature}")
}
/// Creates an entrypoint and its parameters.
pub fn create_entrypoint(
target: Vec<u8>,
signature: String,
component_id: String,
trace_data: TraceData,
) -> (EntryPoint, EntryPointParams) {
let entrypoint_id = get_entrypoint_id(&target, &signature);
let entrypoint = EntryPoint {
id: entrypoint_id.clone(),
target,
signature,
component_id: component_id.clone(),
};
let entrypoint_params = EntryPointParams {
entrypoint_id,
component_id: Some(component_id),
trace_data: Some(trace_data),
};
(entrypoint, entrypoint_params)
}
// Adds EntryPointParams associated with an already existing Entrypoint.
pub fn add_entrypoint_params(
target: Vec<u8>,
signature: String,
trace_data: TraceData,
component_id: Option<String>,
) -> EntryPointParams {
EntryPointParams {
entrypoint_id: get_entrypoint_id(&target, &signature),
component_id,
trace_data: Some(trace_data),
}
}
// Adds a component to an existing Entrypoint.
pub fn add_component_to_entrypoint(
target: Vec<u8>,
signature: String,
component_id: String,
) -> EntryPoint {
let entrypoint_id = get_entrypoint_id(&target, &signature);
EntryPoint { id: entrypoint_id, target, signature, component_id }
}

View File

@@ -3,6 +3,7 @@ pub mod attributes;
pub mod balances;
pub mod block_storage;
pub mod contract;
pub mod entrypoint;
mod mock_store;
pub mod models;
pub mod pb;

View File

@@ -29,6 +29,7 @@ pub struct TransactionChangesBuilder {
component_changes: HashMap<String, ProtocolComponent>,
balance_changes: HashMap<(Vec<u8>, Vec<u8>), BalanceChange>,
entrypoints: HashSet<EntryPoint>,
entrypoint_params: HashSet<EntryPointParams>,
}
impl TransactionChangesBuilder {
@@ -159,6 +160,11 @@ impl TransactionChangesBuilder {
.insert(entrypoint.clone());
}
pub fn add_entrypoint_params(&mut self, entrypoint: &EntryPointParams) {
self.entrypoint_params
.insert(entrypoint.clone());
}
pub fn build(self) -> Option<TransactionChanges> {
let tx_changes = TransactionChanges {
tx: self.tx,
@@ -184,7 +190,10 @@ impl TransactionChangesBuilder {
.entrypoints
.into_iter()
.collect::<Vec<_>>(),
entrypoint_params: Vec::new(), // TODO: Add entrypoint params to builder
entrypoint_params: self
.entrypoint_params
.into_iter()
.collect::<Vec<_>>(),
};
if tx_changes.is_empty() {
None

View File

@@ -194,6 +194,7 @@ pub struct EntryPoint {
pub component_id: ::prost::alloc::string::String,
}
/// Parameters to trace the entrypoint
#[derive(Eq, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EntryPointParams {
@@ -201,8 +202,8 @@ pub struct EntryPointParams {
#[prost(string, tag="1")]
pub entrypoint_id: ::prost::alloc::string::String,
/// \[optional\] The component that uses these entrypoint parameters. Currently used for debugging purposes only.
#[prost(string, tag="2")]
pub component_id: ::prost::alloc::string::String,
#[prost(string, optional, tag="2")]
pub component_id: ::core::option::Option<::prost::alloc::string::String>,
/// The strategy and its corresponding data
#[prost(oneof="entry_point_params::TraceData", tags="3")]
pub trace_data: ::core::option::Option<entry_point_params::TraceData>,
@@ -210,6 +211,7 @@ pub struct EntryPointParams {
/// Nested message and enum types in `EntryPointParams`.
pub mod entry_point_params {
/// The strategy and its corresponding data
#[derive(Eq, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum TraceData {
@@ -219,6 +221,7 @@ pub mod entry_point_params {
}
}
/// RPC tracing strategy with its data
#[derive(Eq, Hash)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RpcTraceData {