Skip to content

Commit 235067c

Browse files
bamrithmichael-yxchen
authored andcommitted
Update logging for block policy errors
1 parent db4d470 commit 235067c

File tree

14 files changed

+408
-394
lines changed

14 files changed

+408
-394
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

monad-blocktree/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ monad-state-backend = { workspace = true }
1616
monad-types = { workspace = true }
1717
monad-validator = { workspace = true }
1818

19+
tracing = { workspace = true }
20+
1921
[dev-dependencies]
2022
monad-crypto = { workspace = true }
2123
monad-eth-types = { workspace = true }

monad-blocktree/src/blocktree.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{
2020

2121
use monad_chain_config::{revision::ChainRevision, ChainConfig};
2222
use monad_consensus_types::{
23-
block::{BlockPolicy, BlockPolicyError, BlockRange, ConsensusBlockHeader},
23+
block::{BlockPolicy, BlockRange, ConsensusBlockHeader},
2424
checkpoint::RootInfo,
2525
metrics::Metrics,
2626
payload::{ConsensusBlockBody, ConsensusBlockBodyId},
@@ -29,9 +29,10 @@ use monad_consensus_types::{
2929
use monad_crypto::certificate_signature::{
3030
CertificateSignaturePubKey, CertificateSignatureRecoverable,
3131
};
32-
use monad_state_backend::{StateBackend, StateBackendError};
32+
use monad_state_backend::StateBackend;
3333
use monad_types::{BlockId, ExecutionProtocol, Round, SeqNum};
3434
use monad_validator::signature_collection::SignatureCollection;
35+
use tracing::debug;
3536

3637
use crate::tree::{BlockTreeEntry, Tree};
3738

@@ -279,6 +280,7 @@ where
279280
self.root.info,
280281
state_backend,
281282
chain_config,
283+
metrics,
282284
) {
283285
Ok(()) => {
284286
let next_block = next_block.clone();
@@ -298,24 +300,8 @@ where
298300
.cloned(),
299301
);
300302
}
301-
Err(BlockPolicyError::StateBackendError(StateBackendError::NotAvailableYet)) => {
302-
metrics.consensus_events.rx_execution_lagging += 1;
303-
}
304-
Err(BlockPolicyError::ExecutionResultMismatch) => {
305-
metrics.consensus_events.rx_bad_state_root += 1;
306-
}
307-
Err(BlockPolicyError::BaseFeeError) => {
308-
metrics.consensus_events.rx_base_fee_error += 1;
309-
}
310-
Err(
311-
BlockPolicyError::BlockPolicyBlockValidatorError(_)
312-
| BlockPolicyError::BlockNotCoherent
313-
| BlockPolicyError::Eip7702Error
314-
| BlockPolicyError::TimestampError
315-
| BlockPolicyError::StateBackendError(StateBackendError::NeverAvailable)
316-
| BlockPolicyError::SystemTransactionError,
317-
) => {
318-
// TODO add metrics
303+
Err(err) => {
304+
debug!(?err, block_id =? next_block.get_id(), block_seq_num =? next_block.get_seq_num(), "block failed coherency check");
319305
}
320306
}
321307
}

monad-consensus-state/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,7 @@ where
13071307
// when epoch boundary block is committed, this updates
13081308
// epoch manager records
13091309
self.metrics.consensus_events.commit_block += 1;
1310-
self.block_policy
1311-
.update_committed_block(block, &self.config.chain_config);
1310+
self.block_policy.update_committed_block(block);
13121311
self.epoch_manager
13131312
.schedule_epoch_start(block.header().seq_num, block.get_block_round());
13141313

monad-consensus-types/src/block.rs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use serde::Serialize;
3737

3838
use crate::{
3939
checkpoint::RootInfo,
40+
metrics::Metrics,
4041
payload::{ConsensusBlockBody, ConsensusBlockBodyId, RoundSignature},
4142
quorum_certificate::QuorumCertificate,
4243
};
@@ -300,24 +301,6 @@ where
300301
}
301302
}
302303

303-
#[derive(Debug, PartialEq)]
304-
pub enum BlockPolicyError {
305-
BlockNotCoherent,
306-
StateBackendError(StateBackendError),
307-
TimestampError,
308-
ExecutionResultMismatch,
309-
BaseFeeError,
310-
BlockPolicyBlockValidatorError(BlockPolicyBlockValidatorError),
311-
Eip7702Error,
312-
SystemTransactionError,
313-
}
314-
315-
impl From<StateBackendError> for BlockPolicyError {
316-
fn from(err: StateBackendError) -> Self {
317-
Self::StateBackendError(err)
318-
}
319-
}
320-
321304
#[derive(Debug, Clone)]
322305
pub struct AccountBalanceState {
323306
pub balance: Balance,
@@ -339,15 +322,6 @@ impl AccountBalanceState {
339322
}
340323
}
341324

342-
pub type AccountBalanceStates = BTreeMap<Address, AccountBalanceState>;
343-
344-
#[derive(Debug, PartialEq)]
345-
pub enum BlockPolicyBlockValidatorError {
346-
AccountBalanceMissing,
347-
InsufficientBalance,
348-
InsufficientReserveBalance,
349-
}
350-
351325
#[derive(Debug, Default, Clone)]
352326
pub struct TxnFee {
353327
pub first_txn_value: Balance,
@@ -378,15 +352,17 @@ where
378352
+ Debug
379353
+ Send
380354
+ Deref<Target = ConsensusFullBlock<ST, SCT, EPT>>;
355+
type BlockPolicyError: Debug;
381356

382357
fn check_coherency(
383358
&self,
384359
block: &Self::ValidatedBlock,
385360
extending_blocks: Vec<&Self::ValidatedBlock>,
386361
blocktree_root: RootInfo,
387362
state_backend: &SBT,
388-
chain_cnfig: &CCT,
389-
) -> Result<(), BlockPolicyError>;
363+
chain_config: &CCT,
364+
metrics: &mut Metrics,
365+
) -> Result<(), Self::BlockPolicyError>;
390366

391367
fn get_expected_execution_results(
392368
&self,
@@ -397,15 +373,11 @@ where
397373

398374
// TODO delete this function, pass recently committed blocks to check_coherency instead
399375
// This way, BlockPolicy doesn't need to be mutated
400-
fn update_committed_block(&mut self, block: &Self::ValidatedBlock, chain_config: &CCT);
376+
fn update_committed_block(&mut self, block: &Self::ValidatedBlock);
401377

402378
// TODO delete this function, pass recently committed blocks to check_coherency instead
403379
// This way, BlockPolicy doesn't need to be mutated
404-
fn reset(
405-
&mut self,
406-
last_delay_committed_blocks: Vec<&Self::ValidatedBlock>,
407-
chain_config: &CCT,
408-
);
380+
fn reset(&mut self, last_delay_committed_blocks: Vec<&Self::ValidatedBlock>);
409381
}
410382

411383
/// A block policy which does not validate the inner contents of the block
@@ -442,6 +414,20 @@ where
442414
}
443415
}
444416

417+
#[derive(Debug)]
418+
pub enum PassthruBlockPolicyError {
419+
InvalidSeqNum,
420+
TimestampError,
421+
ExecutionResultMismatch,
422+
StateBackendError(StateBackendError),
423+
}
424+
425+
impl From<StateBackendError> for PassthruBlockPolicyError {
426+
fn from(err: StateBackendError) -> Self {
427+
Self::StateBackendError(err)
428+
}
429+
}
430+
445431
impl<ST, SCT, EPT>
446432
BlockPolicy<ST, SCT, EPT, InMemoryState<ST, SCT>, MockChainConfig, MockChainRevision>
447433
for PassthruBlockPolicy
@@ -451,15 +437,17 @@ where
451437
EPT: ExecutionProtocol,
452438
{
453439
type ValidatedBlock = PassthruWrappedBlock<ST, SCT, EPT>;
440+
type BlockPolicyError = PassthruBlockPolicyError;
454441

455442
fn check_coherency(
456443
&self,
457444
block: &Self::ValidatedBlock,
458445
extending_blocks: Vec<&Self::ValidatedBlock>,
459446
blocktree_root: RootInfo,
460447
state_backend: &InMemoryState<ST, SCT>,
461-
chain_config: &MockChainConfig,
462-
) -> Result<(), BlockPolicyError> {
448+
_: &MockChainConfig,
449+
_: &mut Metrics,
450+
) -> Result<(), PassthruBlockPolicyError> {
463451
// check coherency against the block being extended or against the root of the blocktree if
464452
// there is no extending branch
465453
let (extending_seq_num, extending_timestamp) =
@@ -470,12 +458,12 @@ where
470458
};
471459

472460
if block.get_seq_num() != extending_seq_num + SeqNum(1) {
473-
return Err(BlockPolicyError::BlockNotCoherent);
461+
return Err(PassthruBlockPolicyError::InvalidSeqNum);
474462
}
475463

476464
if block.get_timestamp() <= extending_timestamp {
477465
// timestamps must be monotonically increasing
478-
return Err(BlockPolicyError::TimestampError);
466+
return Err(PassthruBlockPolicyError::TimestampError);
479467
}
480468

481469
let expected_execution_results = self.get_expected_execution_results(
@@ -484,7 +472,7 @@ where
484472
state_backend,
485473
)?;
486474
if block.get_execution_results() != &expected_execution_results {
487-
return Err(BlockPolicyError::ExecutionResultMismatch);
475+
return Err(PassthruBlockPolicyError::ExecutionResultMismatch);
488476
}
489477

490478
Ok(())
@@ -499,8 +487,8 @@ where
499487
Ok(Vec::new())
500488
}
501489

502-
fn update_committed_block(&mut self, _: &Self::ValidatedBlock, _: &MockChainConfig) {}
503-
fn reset(&mut self, _: Vec<&Self::ValidatedBlock>, _: &MockChainConfig) {}
490+
fn update_committed_block(&mut self, _: &Self::ValidatedBlock) {}
491+
fn reset(&mut self, _: Vec<&Self::ValidatedBlock>) {}
504492
}
505493

506494
#[derive(Debug, Clone, RlpEncodable, RlpDecodable, Serialize)]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2025 Category Labs, Inc.
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
use monad_state_backend::StateBackendError;
17+
use monad_system_calls::validator::SystemTransactionValidationError;
18+
19+
#[derive(Debug, PartialEq)]
20+
pub enum EthBlockPolicyError {
21+
InvalidSeqNum,
22+
StateBackendError(StateBackendError),
23+
TimestampError,
24+
ExecutionResultMismatch,
25+
BaseFeeError,
26+
BlockPolicyBlockValidatorError(EthBlockPolicyBlockValidatorError),
27+
InvalidNonce,
28+
SystemTransactionError(SystemTransactionValidationError),
29+
}
30+
31+
#[derive(Debug, PartialEq)]
32+
pub enum EthBlockPolicyBlockValidatorError {
33+
AccountBalanceMissing,
34+
InsufficientBalance,
35+
InsufficientReserveBalance,
36+
}
37+
38+
impl From<EthBlockPolicyBlockValidatorError> for EthBlockPolicyError {
39+
fn from(err: EthBlockPolicyBlockValidatorError) -> Self {
40+
Self::BlockPolicyBlockValidatorError(err)
41+
}
42+
}
43+
44+
impl From<StateBackendError> for EthBlockPolicyError {
45+
fn from(err: StateBackendError) -> Self {
46+
Self::StateBackendError(err)
47+
}
48+
}
49+
50+
impl From<SystemTransactionValidationError> for EthBlockPolicyError {
51+
fn from(err: SystemTransactionValidationError) -> Self {
52+
Self::SystemTransactionError(err)
53+
}
54+
}

0 commit comments

Comments
 (0)