Skip to content

Commit

Permalink
feat: update main
Browse files Browse the repository at this point in the history
  • Loading branch information
karlem committed Jul 19, 2024
1 parent 0794939 commit 8b938d4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 170 deletions.
39 changes: 9 additions & 30 deletions fendermint/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,7 @@ where
let mut mpool_received_trace = MpoolReceived::default();

let response = match result {
Err(e) => {
emit(MpoolReceivedInvalidMessage {
reason: "InvalidEncoding",
description: e.description.as_ref(),
});
invalid_check_tx(AppError::InvalidEncoding, e.description)
}
Err(e) => invalid_check_tx(AppError::InvalidEncoding, e.description),
Ok(result) => match result {
Err(IllegalMessage) => invalid_check_tx(AppError::IllegalMessage, "".to_owned()),
Ok(Err(InvalidSignature(d))) => invalid_check_tx(AppError::InvalidSignature, d),
Expand Down Expand Up @@ -697,10 +691,11 @@ where
let size_txs = txs.iter().map(|tx| tx.len()).sum::<usize>();
let num_txs = txs.len();

let process_result = self
let accept = self
.interpreter
.process(self.chain_env.clone(), txs)
.await?;
.await
.context("failed to process proposal")?;

emit(BlockProposalReceived {
height: request.height.value(),
Expand All @@ -720,27 +715,11 @@ where
reason: None,
});

let mut proposal_evaluated = BlockProposalEvaluated {
height: request.height.value(),
hash: HexEncodableBlockHash(request.hash.into()),
size: size_txs,
tx_count: num_txs,
validator: &request.proposer_address,
accept: true,
reason: None,
};

let process_proposal = match process_result {
ProcessResult::Accepted => response::ProcessProposal::Accept,
ProcessResult::Rejected(reason) => {
proposal_evaluated.accept = false;
proposal_evaluated.reason = Some(reason);
response::ProcessProposal::Reject
}
};

emit(proposal_evaluated);
Ok(process_proposal)
if accept {
Ok(response::ProcessProposal::Accept)
} else {
Ok(response::ProcessProposal::Reject)
}
}

/// Signals the beginning of a new block, prior to any `DeliverTx` calls.
Expand Down
8 changes: 0 additions & 8 deletions fendermint/app/src/observe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;

<<<<<<< HEAD
=======
use fendermint_vm_interpreter::errors::ProcessError;
>>>>>>> e7e7cb5c (feat: address comments)
use fendermint_vm_interpreter::fvm::FvmMessage;
use tendermint::account::Id;

Expand Down Expand Up @@ -158,11 +154,7 @@ impl Recordable for MpoolReceived {
.unwrap_or("".to_string());

MPOOL_RECEIVED
<<<<<<< HEAD
.with_label_values(&[&self.accept.to_string()])
=======
.with_label_values(&[&self.accept.to_string(), &from])
>>>>>>> e7e7cb5c (feat: address comments)
.inc();
}
}
Expand Down
18 changes: 4 additions & 14 deletions fendermint/vm/interpreter/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use fvm_ipld_encoding::Error as IpldError;

use crate::{
chain::{ChainMessageApplyRet, ChainMessageCheckRes},
errors::ProcessError,
fvm::{FvmQuery, FvmQueryRet},
CheckInterpreter, ExecInterpreter, GenesisInterpreter, ProcessResult, ProposalInterpreter,
QueryInterpreter,
CheckInterpreter, ExecInterpreter, GenesisInterpreter, ProposalInterpreter, QueryInterpreter,
};

pub type BytesMessageApplyRes = Result<ChainMessageApplyRet, IpldError>;
Expand Down Expand Up @@ -127,19 +125,13 @@ where
}

/// Parse messages in the block, reject if unknown format. Pass the rest to the inner `ChainMessage` interpreter.
async fn process(
&self,
state: Self::State,
msgs: Vec<Self::Message>,
) -> anyhow::Result<ProcessResult> {
async fn process(&self, state: Self::State, msgs: Vec<Self::Message>) -> anyhow::Result<bool> {
if msgs.len() > self.max_msgs {
tracing::warn!(
block_msgs = msgs.len(),
"rejecting block: too many messages"
);
return Ok(ProcessResult::Rejected(ProcessError::TooManyMessages(
msgs.len(),
)));
return Ok(false);
}

let mut chain_msgs = Vec::new();
Expand All @@ -160,9 +152,7 @@ where
"failed to decode message in proposal as ChainMessage"
);
if self.reject_malformed_proposal {
return Ok(ProcessResult::Rejected(
ProcessError::FailedToDecodeMessage(e.to_string()),
));
return Ok(false);
}
}
Ok(msg) => chain_msgs.push(msg),
Expand Down
18 changes: 5 additions & 13 deletions fendermint/vm/interpreter/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use crate::errors::ProcessError;
use crate::fvm::state::ipc::GatewayCaller;
use crate::fvm::{topdown, FvmApplyRet, PowerUpdates};
use crate::{
fvm::state::FvmExecState,
fvm::FvmMessage,
signed::{SignedMessageApplyRes, SignedMessageCheckRes, SyntheticMessage, VerifiableMessage},
CheckInterpreter, ExecInterpreter, GenesisInterpreter, ProcessResult, ProposalInterpreter,
QueryInterpreter,
CheckInterpreter, ExecInterpreter, GenesisInterpreter, ProposalInterpreter, QueryInterpreter,
};
use anyhow::{bail, Context};
use async_stm::atomically;
Expand Down Expand Up @@ -177,11 +175,7 @@ where
}

/// Perform finality checks on top-down transactions and availability checks on bottom-up transactions.
async fn process(
&self,
env: Self::State,
msgs: Vec<Self::Message>,
) -> anyhow::Result<ProcessResult> {
async fn process(&self, env: Self::State, msgs: Vec<Self::Message>) -> anyhow::Result<bool> {
for msg in msgs {
match msg {
ChainMessage::Ipc(IpcMessage::BottomUpExec(msg)) => {
Expand All @@ -200,7 +194,7 @@ where
.await;

if !is_resolved {
return Ok(ProcessResult::Rejected(ProcessError::CheckpointNotResolved));
return Ok(false);
}
}
ChainMessage::Ipc(IpcMessage::TopDownExec(ParentFinality {
Expand All @@ -214,15 +208,13 @@ where
let is_final =
atomically(|| env.parent_finality_provider.check_proposal(&prop)).await;
if !is_final {
return Ok(ProcessResult::Rejected(
ProcessError::ParentFinalityNotAvailable,
));
return Ok(false);
}
}
_ => {}
};
}
Ok(ProcessResult::Accepted)
Ok(true)
}
}

Expand Down
18 changes: 0 additions & 18 deletions fendermint/vm/interpreter/src/errors.rs

This file was deleted.

18 changes: 1 addition & 17 deletions fendermint/vm/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use async_trait::async_trait;

pub mod bytes;
pub mod chain;
pub mod errors;
pub mod fvm;
pub mod signed;

Expand All @@ -28,17 +27,6 @@ pub trait GenesisInterpreter: Sync + Send {
) -> anyhow::Result<(Self::State, Self::Output)>;
}

pub enum ProcessResult {
Accepted,
Rejected(errors::ProcessError),
}

impl ProcessResult {
pub fn is_accepted(&self) -> bool {
matches!(self, ProcessResult::Accepted)
}
}

/// Prepare and process transaction proposals.
#[async_trait]
pub trait ProposalInterpreter: Sync + Send {
Expand Down Expand Up @@ -66,11 +54,7 @@ pub trait ProposalInterpreter: Sync + Send {
/// This is our chance check whether CIDs proposed for execution are available.
///
/// Return `true` if we can accept this block, `false` to reject it.
async fn process(
&self,
state: Self::State,
msgs: Vec<Self::Message>,
) -> anyhow::Result<ProcessResult>;
async fn process(&self, state: Self::State, msgs: Vec<Self::Message>) -> anyhow::Result<bool>;
}

/// The `ExecInterpreter` applies messages on some state, which is
Expand Down
70 changes: 0 additions & 70 deletions fendermint/vm/topdown/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,76 +129,6 @@ impl IPCProviderProxyWithLatency {
}
}

#[async_trait]
impl ParentQueryProxy for IPCProviderProxyWithLatency {
#[instrument(skip(self))]
async fn get_chain_head_height(&self) -> anyhow::Result<BlockHeight> {
emit_event_with_latency(
&self.inner.parent_subnet.to_string(),
"chain_head",
|| async { self.inner.get_chain_head_height().await },
)
.await
}

#[instrument(skip(self))]
async fn get_genesis_epoch(&self) -> anyhow::Result<BlockHeight> {
emit_event_with_latency(
&self.inner.parent_subnet.to_string(),
"genesis_epoch",
|| async { self.inner.get_genesis_epoch().await },
)
.await
}

#[instrument(skip(self))]
async fn get_block_hash(&self, height: BlockHeight) -> anyhow::Result<GetBlockHashResult> {
emit_event_with_latency(
&self.inner.parent_subnet.to_string(),
"get_block_hash",
|| async { self.inner.get_block_hash(height).await },
)
.await
}

/// Get the top down messages from the starting to the ending height.
async fn get_top_down_msgs(
&self,
height: BlockHeight,
) -> anyhow::Result<TopDownQueryPayload<Vec<IpcEnvelope>>> {
emit_event_with_latency(
&self.inner.parent_subnet.to_string(),
"get_top_down_msgs",
|| async { self.inner.get_top_down_msgs(height).await },
)
.await
}

/// Get the validator set at the specified height.
async fn get_validator_changes(
&self,
height: BlockHeight,
) -> anyhow::Result<TopDownQueryPayload<Vec<StakingChangeRequest>>> {
emit_event_with_latency(
&self.inner.parent_subnet.to_string(),
"get_validator_changeset",
|| async { self.inner.get_validator_changes(height).await },
)
.await
}
}

// TODO - create a macro for this
pub struct IPCProviderProxyWithLatency {
inner: IPCProviderProxy,
}

impl IPCProviderProxyWithLatency {
pub fn new(inner: IPCProviderProxy) -> Self {
Self { inner }
}
}

#[async_trait]
impl ParentQueryProxy for IPCProviderProxyWithLatency {
#[instrument(skip(self))]
Expand Down

0 comments on commit 8b938d4

Please sign in to comment.