Skip to content

Commit

Permalink
[Metrics] Support Tx metrics (#2343)
Browse files Browse the repository at this point in the history
* support processor metrics

* draft support tx metrics

* support executor metrics

* support sequencer metrics

* finish tx metrics
  • Loading branch information
baichuan3 authored Aug 2, 2024
1 parent f6bae53 commit 6e6a154
Show file tree
Hide file tree
Showing 25 changed files with 526 additions and 32 deletions.
14 changes: 14 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 crates/rooch-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ move-bytecode-utils = { workspace = true }
raw-store = { workspace = true }
moveos-config = { workspace = true }
smt = { workspace = true }
metrics = { workspace = true }

rooch-config = { workspace = true }
rooch-types = { workspace = true }
Expand Down
8 changes: 6 additions & 2 deletions crates/rooch-benchmarks/benches/bench_tx_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ pub fn tx_sequence_benchmark(c: &mut Criterion) {
let rooch_key_pair = binding_test.sequencer_kp().copy();

let sequencer_keypair = rooch_key_pair.copy();
let mut sequencer =
gen_sequencer(sequencer_keypair, binding_test.executor().get_rooch_store()).unwrap();
let mut sequencer = gen_sequencer(
sequencer_keypair,
binding_test.executor().get_rooch_store(),
&binding_test.registry_service.default_registry(),
)
.unwrap();

let tx_type = config.tx_type.unwrap().clone();

Expand Down
14 changes: 12 additions & 2 deletions crates/rooch-benchmarks/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bitcoin::hex::FromHex;
use bitcoincore_rpc::RpcApi;
use bitcoincore_rpc_json::bitcoin;
use bitcoincore_rpc_json::bitcoin::Block;
use prometheus::Registry;
use rooch_sequencer::actor::sequencer::SequencerActor;
use rooch_store::RoochStore;
use rooch_test_transaction_builder::TestTransactionBuilder;
Expand All @@ -25,8 +26,17 @@ use tracing::info;
pub const EXAMPLE_SIMPLE_BLOG_PACKAGE_NAME: &str = "simple_blog";
pub const EXAMPLE_SIMPLE_BLOG_NAMED_ADDRESS: &str = "simple_blog";

pub fn gen_sequencer(keypair: RoochKeyPair, rooch_store: RoochStore) -> Result<SequencerActor> {
SequencerActor::new(keypair, rooch_store.clone(), ServiceStatus::Active)
pub fn gen_sequencer(
keypair: RoochKeyPair,
rooch_store: RoochStore,
registry: &Registry,
) -> Result<SequencerActor> {
SequencerActor::new(
keypair,
rooch_store.clone(),
ServiceStatus::Active,
registry,
)
}

pub fn create_publish_transaction(
Expand Down
3 changes: 3 additions & 0 deletions crates/rooch-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ serde_with = { workspace = true }
log = { workspace = true }
itertools = { workspace = true }
parking_lot = { workspace = true }
prometheus = { workspace = true }
function_name = { workspace = true }

move-core-types = { workspace = true }
move-resource-viewer = { workspace = true }
Expand All @@ -44,6 +46,7 @@ moveos-store = { workspace = true }
moveos-types = { workspace = true }
moveos-common = { workspace = true }
moveos-verifier = { workspace = true }
metrics = { workspace = true }

rooch-types = { workspace = true }
rooch-framework = { workspace = true }
Expand Down
83 changes: 74 additions & 9 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use super::messages::{
ExecuteTransactionMessage, ExecuteTransactionResult, GetRootMessage, ValidateL1BlockMessage,
ValidateL1TxMessage, ValidateL2TxMessage,
};
use crate::metrics::ExecutorMetrics;
use anyhow::Result;
use async_trait::async_trait;
use coerce::actor::{context::ActorContext, message::Handler, Actor};
use function_name::named;
use move_core_types::vm_status::VMStatus;
use moveos::moveos::{MoveOS, MoveOSConfig};
use moveos::vm::vm_status_explainer::explain_vm_status;
Expand All @@ -20,6 +22,7 @@ use moveos_types::state::ObjectState;
use moveos_types::state_resolver::RootObjectResolver;
use moveos_types::transaction::VerifiedMoveOSTransaction;
use moveos_types::transaction::{FunctionCall, MoveOSTransaction, VerifiedMoveAction};
use prometheus::Registry;
use rooch_genesis::FrameworksGasParameters;
use rooch_store::RoochStore;
use rooch_types::bitcoin::BitcoinModule;
Expand All @@ -31,13 +34,15 @@ use rooch_types::multichain_id::RoochMultiChainID;
use rooch_types::transaction::{
AuthenticatorInfo, L1Block, L1BlockWithBody, L1Transaction, RoochTransaction,
};
use std::sync::Arc;
use tracing::{debug, warn};

pub struct ExecutorActor {
root: ObjectMeta,
moveos: MoveOS,
moveos_store: MoveOSStore,
rooch_store: RoochStore,
metrics: Arc<ExecutorMetrics>,
}

type ValidateAuthenticatorResult = Result<TxValidateResult, VMStatus>;
Expand All @@ -47,6 +52,7 @@ impl ExecutorActor {
root: ObjectMeta,
moveos_store: MoveOSStore,
rooch_store: RoochStore,
registry: &Registry,
) -> Result<Self> {
let resolver = RootObjectResolver::new(root.clone(), &moveos_store);
let gas_parameters = FrameworksGasParameters::load_from_chain(&resolver)?;
Expand All @@ -64,6 +70,7 @@ impl ExecutorActor {
moveos,
moveos_store,
rooch_store,
metrics: Arc::new(ExecutorMetrics::new(registry)),
})
}

Expand All @@ -79,24 +86,43 @@ impl ExecutorActor {
&self.moveos
}

#[named]
pub fn execute(&mut self, tx: VerifiedMoveOSTransaction) -> Result<ExecuteTransactionResult> {
let fn_name = function_name!();
let _timer = self
.metrics
.executor_execute_tx_latency_seconds
.with_label_values(&[fn_name])
.start_timer();
let tx_hash = tx.ctx.tx_hash();
let size = tx.ctx.tx_size;
let output = self.moveos.execute_and_apply(tx)?;
let execution_info = self
.moveos_store
.handle_tx_output(tx_hash, output.clone())?;

self.root = execution_info.root_metadata();
self.metrics
.executor_execute_tx_bytes
.with_label_values(&[fn_name])
.observe(size as f64);
Ok(ExecuteTransactionResult {
output,
transaction_info: execution_info,
})
}

#[named]
pub fn validate_l1_block(
&self,
l1_block: L1BlockWithBody,
) -> Result<VerifiedMoveOSTransaction> {
let fn_name = function_name!();
let _timer = self
.metrics
.executor_validate_tx_latency_seconds
.with_label_values(&[fn_name])
.start_timer();
let tx_hash = l1_block.block.tx_hash();
let tx_size = l1_block.block.tx_size();
let ctx = TxContext::new_system_call_ctx(tx_hash, tx_size);
Expand All @@ -111,7 +137,7 @@ impl ExecutorActor {
},
block_body,
} = l1_block;
match RoochMultiChainID::try_from(chain_id.id())? {
let result = match RoochMultiChainID::try_from(chain_id.id())? {
RoochMultiChainID::Bitcoin => {
let action = VerifiedMoveAction::Function {
call: BitcoinModule::create_execute_l1_block_call_bytes(
Expand Down Expand Up @@ -139,15 +165,28 @@ impl ExecutorActor {
))
}
id => Err(anyhow::anyhow!("Chain {} not supported yet", id)),
}
};

self.metrics
.executor_validate_tx_bytes
.with_label_values(&[fn_name])
.observe(tx_size as f64);
result
}

#[named]
pub fn validate_l1_tx(&self, l1_tx: L1Transaction) -> Result<VerifiedMoveOSTransaction> {
let fn_name = function_name!();
let _timer = self
.metrics
.executor_validate_tx_latency_seconds
.with_label_values(&[fn_name])
.start_timer();
let tx_hash = l1_tx.tx_hash();
let tx_size = l1_tx.tx_size();
let ctx = TxContext::new_system_call_ctx(tx_hash, tx_size);
//TODO we should call the contract to validate the l1 tx has been executed
match RoochMultiChainID::try_from(l1_tx.chain_id.id())? {
let result = match RoochMultiChainID::try_from(l1_tx.chain_id.id())? {
RoochMultiChainID::Bitcoin => {
let action = VerifiedMoveAction::Function {
call: BitcoinModule::create_execute_l1_tx_call(l1_tx.block_hash, l1_tx.txid)?,
Expand All @@ -160,20 +199,32 @@ impl ExecutorActor {
))
}
id => Err(anyhow::anyhow!("Chain {} not supported yet", id)),
}
};

self.metrics
.executor_validate_tx_bytes
.with_label_values(&[fn_name])
.observe(tx_size as f64);
result
}

#[named]
pub fn validate_l2_tx(&self, mut tx: RoochTransaction) -> Result<VerifiedMoveOSTransaction> {
let fn_name = function_name!();
let _timer = self
.metrics
.executor_validate_tx_latency_seconds
.with_label_values(&[fn_name])
.start_timer();
let sender = tx.sender();
let tx_hash = tx.tx_hash();

debug!("executor validate_l2_tx: {:?}, sender: {}", tx_hash, sender);

let authenticator = tx.authenticator_info();

let mut moveos_tx: MoveOSTransaction = tx.into_moveos_transaction(self.root.clone());
let result = self.validate_authenticator(&moveos_tx.ctx, authenticator);
match result {
let tx_size = moveos_tx.ctx.tx_size;
let tx_result = self.validate_authenticator(&moveos_tx.ctx, authenticator);
let result = match tx_result {
Ok(vm_result) => match vm_result {
Ok(tx_validate_result) => {
// Add the tx_validate_result to the context
Expand Down Expand Up @@ -214,14 +265,27 @@ impl ExecutorActor {
);
Err(e)
}
}
};

self.metrics
.executor_validate_tx_bytes
.with_label_values(&[fn_name])
.observe(tx_size as f64);
result
}

#[named]
pub fn validate_authenticator(
&self,
ctx: &TxContext,
authenticator: AuthenticatorInfo,
) -> Result<ValidateAuthenticatorResult> {
let fn_name = function_name!();
let _timer = self
.metrics
.executor_validate_tx_latency_seconds
.with_label_values(&[fn_name])
.start_timer();
let tx_validator = self.as_module_binding::<TransactionValidator>();
let tx_validate_function_result = tx_validator
.validate(ctx, authenticator.clone())?
Expand All @@ -246,6 +310,7 @@ impl ExecutorActor {
}
Err(vm_status) => Err(vm_status),
};

Ok(vm_result)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

pub mod actor;
pub mod metrics;
pub mod proxy;
Loading

0 comments on commit 6e6a154

Please sign in to comment.