nautechsystems/nautilus_trader · error · anyhow::Error
Invalid fee_protocol1_new '{}': {e}
Error message
Invalid fee_protocol1_new '{}': {e} What it means
Same conversion failure as its sibling error, but for `fee_protocol1_new` (token1's new fee-protocol value): `i32::try_from` rejects the value because it does not fit in i32. The raw value is included in the message for diagnosis. The fee-protocol-update batch insert aborts before SQL execution.
Source
Thrown at crates/adapters/blockchain/src/cache/database.rs:1906
let mut fee_protocol1s: Vec<i32> = Vec::with_capacity(len);
// Fill vectors from updates
for update in updates {
chain_ids.push(chain_id as i32);
dex_names.push(update.dex.name.to_string());
pool_identifiers.push(update.pool_identifier.to_string());
blocks.push(update.block as i64);
transaction_hashes.push(update.transaction_hash.clone());
transaction_indices.push(update.transaction_index as i32);
log_indices.push(update.log_index as i32);
fee_protocol0s.push(i32::try_from(update.fee_protocol0_new).map_err(|e| {
anyhow::anyhow!(
"Invalid fee_protocol0_new '{}': {e}",
update.fee_protocol0_new
)
})?);
fee_protocol1s.push(i32::try_from(update.fee_protocol1_new).map_err(|e| {
anyhow::anyhow!(
"Invalid fee_protocol1_new '{}': {e}",
update.fee_protocol1_new
)
})?);
}
// Execute batch insert with UNNEST
sqlx::query(
"
INSERT INTO pool_fee_protocol_update_event (
chain_id, dex_name, pool_identifier, block, transaction_hash, transaction_index,
log_index, fee_protocol0_new, fee_protocol1_new
)
SELECT
chain_id, dex_name, pool_identifier, block, transaction_hash, transaction_index,
log_index, fee_protocol0_new, fee_protocol1_new
FROM UNNEST(
$1::INT[], $2::TEXT[], $3::TEXT[], $4::INT[], $5::TEXT[], $6::INT[],View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the logged `fee_protocol1_new` value and trace its decoding origin
- Validate the value fits the fee-protocol domain (0..=255) before inserting
- Fix the event decoder/ABI offset for fee_protocol1_new if the value is systematically wrong
- Reject or skip malformed events upstream rather than failing the batch
Example fix
// before
fee_protocol1s.push(i32::try_from(update.fee_protocol1_new).map_err(|e| {
anyhow::anyhow!("Invalid fee_protocol1_new '{}': {e}", update.fee_protocol1_new)
})?);
// after: domain-range validation before conversion
if update.fee_protocol1_new > 255 {
anyhow::bail!("fee_protocol1_new {} outside valid fee-protocol range", update.fee_protocol1_new);
}
fee_protocol1s.push(i32::try_from(update.fee_protocol1_new)?); Defensive patterns
Strategy: validation
Validate before calling
fn validate_fee_protocol1(v: u64) -> anyhow::Result<()> {
anyhow::ensure!(v <= 255, "fee_protocol1_new {v} outside fee-protocol range 0..=255");
Ok(())
} Type guard
fn fits_i32(v: u64) -> bool { v <= i32::MAX as u64 } Try / catch
if let Err(e) = validate_fee_protocol1(update.fee_protocol1_new) {
tracing::error!("dropping fee-protocol update: {e}");
return Ok(()); // or skip this update
} Prevention
- Use narrow types (u8) for fee-protocol values at decode time
- Check ABI offsets when upgrading contract bindings
- Reject sentinel values (u64::MAX) upstream
- Test decoders against known-good on-chain events
When it happens
Trigger: A `FeeProtocolUpdate` whose `fee_protocol1_new` (u64/usize) exceeds i32::MAX or is below i32::MIN is passed to the batch insert of pool fee-protocol update events.
Common situations: Corrupt or misparsed on-chain data; sentinel values (e.g. u64::MAX) from a decoder bug; ABI layout drift between contract versions changing where fee_protocol1 is read from.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Invalid fee_protocol0_new '{}': {e}
- Deployment manifest pool fee is invalid
- invalid bar step: {e}
- Unsupported `OrderSide` for Binance: {value:?}
- invalid OrderSide: must be Buy or Sell, was {side}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/371a4c885c040a3b.
Report an issue: GitHub.