fix(multicall): resolve critical multicall parsing corruption issues
- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing - Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives - Added LRU caching system for address validation with 10-minute TTL - Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures - Fixed duplicate function declarations and import conflicts across multiple files - Added error recovery mechanisms with multiple fallback strategies - Updated tests to handle new validation behavior for suspicious addresses - Fixed parser test expectations for improved validation system - Applied gofmt formatting fixes to ensure code style compliance - Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot - Resolved critical security vulnerabilities in heuristic address extraction - Progress: Updated TODO audit from 10% to 35% complete 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,8 @@ type MetricsCollector struct {
|
||||
DEXInteractionsFound uint64
|
||||
SwapOpportunities uint64
|
||||
ArbitrageOpportunities uint64
|
||||
OpportunitiesDropped uint64
|
||||
OpportunityQueueLength uint64
|
||||
|
||||
// Performance Metrics
|
||||
ProcessingLatency time.Duration
|
||||
@@ -42,6 +44,8 @@ type MetricsCollector struct {
|
||||
AverageGasPrice uint64
|
||||
L1DataFeesSpent float64
|
||||
L2ComputeFeesSpent float64
|
||||
ProfitFactor float64
|
||||
UptimeSeries []float64
|
||||
|
||||
// Health Metrics
|
||||
UptimeSeconds uint64
|
||||
@@ -57,6 +61,7 @@ func NewMetricsCollector(logger *logger.Logger) *MetricsCollector {
|
||||
logger: logger,
|
||||
startTime: time.Now(),
|
||||
LastHealthCheck: time.Now(),
|
||||
UptimeSeries: make([]float64, 0, 1024),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +120,14 @@ func (m *MetricsCollector) RecordArbitrageOpportunity() {
|
||||
m.ArbitrageOpportunities++
|
||||
}
|
||||
|
||||
// RecordDroppedOpportunity increments the dropped opportunity counter.
|
||||
func (m *MetricsCollector) RecordDroppedOpportunity() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
m.OpportunitiesDropped++
|
||||
}
|
||||
|
||||
// RecordSuccessfulTrade records a successful trade
|
||||
func (m *MetricsCollector) RecordSuccessfulTrade(profit float64, gasCost float64) {
|
||||
m.mu.Lock()
|
||||
@@ -124,6 +137,7 @@ func (m *MetricsCollector) RecordSuccessfulTrade(profit float64, gasCost float64
|
||||
m.TotalProfit += profit
|
||||
m.GasCostsSpent += gasCost
|
||||
m.NetProfit = m.TotalProfit - m.TotalLoss - m.GasCostsSpent
|
||||
m.updateProfitFactor()
|
||||
|
||||
// Update error rate
|
||||
totalTrades := m.SuccessfulTrades + m.FailedTrades
|
||||
@@ -141,6 +155,7 @@ func (m *MetricsCollector) RecordFailedTrade(loss float64, gasCost float64) {
|
||||
m.TotalLoss += loss
|
||||
m.GasCostsSpent += gasCost
|
||||
m.NetProfit = m.TotalProfit - m.TotalLoss - m.GasCostsSpent
|
||||
m.updateProfitFactor()
|
||||
|
||||
// Update error rate
|
||||
totalTrades := m.SuccessfulTrades + m.FailedTrades
|
||||
@@ -149,6 +164,14 @@ func (m *MetricsCollector) RecordFailedTrade(loss float64, gasCost float64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MetricsCollector) updateProfitFactor() {
|
||||
if m.GasCostsSpent <= 0 {
|
||||
m.ProfitFactor = 0
|
||||
return
|
||||
}
|
||||
m.ProfitFactor = (m.TotalProfit - m.TotalLoss) / m.GasCostsSpent
|
||||
}
|
||||
|
||||
// RecordGasMetrics records gas-related metrics
|
||||
func (m *MetricsCollector) RecordGasMetrics(gasPrice uint64, l1DataFee, l2ComputeFee float64) {
|
||||
m.mu.Lock()
|
||||
@@ -166,6 +189,7 @@ func (m *MetricsCollector) UpdateHealthCheck() {
|
||||
|
||||
m.LastHealthCheck = time.Now()
|
||||
m.UptimeSeconds = uint64(time.Since(m.startTime).Seconds())
|
||||
m.UptimeSeries = append(m.UptimeSeries, float64(m.UptimeSeconds))
|
||||
}
|
||||
|
||||
// GetSnapshot returns a snapshot of current metrics
|
||||
@@ -189,6 +213,7 @@ func (m *MetricsCollector) GetSnapshot() MetricsSnapshot {
|
||||
TotalLoss: m.TotalLoss,
|
||||
GasCostsSpent: m.GasCostsSpent,
|
||||
NetProfit: m.NetProfit,
|
||||
ProfitFactor: m.ProfitFactor,
|
||||
AverageGasPrice: m.AverageGasPrice,
|
||||
L1DataFeesSpent: m.L1DataFeesSpent,
|
||||
L2ComputeFeesSpent: m.L2ComputeFeesSpent,
|
||||
@@ -206,6 +231,8 @@ type MetricsSnapshot struct {
|
||||
DEXInteractionsFound uint64 `json:"dex_interactions_found"`
|
||||
SwapOpportunities uint64 `json:"swap_opportunities"`
|
||||
ArbitrageOpportunities uint64 `json:"arbitrage_opportunities"`
|
||||
OpportunitiesDropped uint64 `json:"opportunities_dropped"`
|
||||
OpportunityQueueLength uint64 `json:"opportunity_queue_length"`
|
||||
ProcessingLatency time.Duration `json:"processing_latency_ms"`
|
||||
ErrorRate float64 `json:"error_rate"`
|
||||
SuccessfulTrades uint64 `json:"successful_trades"`
|
||||
@@ -217,6 +244,7 @@ type MetricsSnapshot struct {
|
||||
AverageGasPrice uint64 `json:"average_gas_price_gwei"`
|
||||
L1DataFeesSpent float64 `json:"l1_data_fees_spent_eth"`
|
||||
L2ComputeFeesSpent float64 `json:"l2_compute_fees_spent_eth"`
|
||||
ProfitFactor float64 `json:"profit_factor"`
|
||||
UptimeSeconds uint64 `json:"uptime_seconds"`
|
||||
LastHealthCheck time.Time `json:"last_health_check"`
|
||||
}
|
||||
@@ -298,6 +326,7 @@ func (s *MetricsServer) handleMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
"total_loss_eth": ` + floatToString(snapshot.TotalLoss) + `,
|
||||
"gas_costs_spent_eth": ` + floatToString(snapshot.GasCostsSpent) + `,
|
||||
"net_profit_eth": ` + floatToString(snapshot.NetProfit) + `,
|
||||
"profit_factor": ` + floatToString(snapshot.ProfitFactor) + `,
|
||||
"average_gas_price_gwei": ` + uintToString(snapshot.AverageGasPrice) + `,
|
||||
"l1_data_fees_spent_eth": ` + floatToString(snapshot.L1DataFeesSpent) + `,
|
||||
"l2_compute_fees_spent_eth": ` + floatToString(snapshot.L2ComputeFeesSpent) + `,
|
||||
@@ -331,6 +360,10 @@ mev_bot_l2_messages_processed ` + uintToString(snapshot.L2MessagesProcessed) + `
|
||||
# TYPE mev_bot_l2_messages_per_second gauge
|
||||
mev_bot_l2_messages_per_second ` + floatToString(snapshot.L2MessagesPerSecond) + `
|
||||
|
||||
# HELP mev_bot_processing_latency_ms Latest pipeline processing latency in milliseconds
|
||||
# TYPE mev_bot_processing_latency_ms gauge
|
||||
mev_bot_processing_latency_ms ` + durationToString(snapshot.ProcessingLatency) + `
|
||||
|
||||
# HELP mev_bot_successful_trades Total successful trades
|
||||
# TYPE mev_bot_successful_trades counter
|
||||
mev_bot_successful_trades ` + uintToString(snapshot.SuccessfulTrades) + `
|
||||
@@ -339,13 +372,25 @@ mev_bot_successful_trades ` + uintToString(snapshot.SuccessfulTrades) + `
|
||||
# TYPE mev_bot_failed_trades counter
|
||||
mev_bot_failed_trades ` + uintToString(snapshot.FailedTrades) + `
|
||||
|
||||
# HELP mev_bot_trade_error_rate Fraction of failed trades over total attempts
|
||||
# TYPE mev_bot_trade_error_rate gauge
|
||||
mev_bot_trade_error_rate ` + floatToString(snapshot.ErrorRate) + `
|
||||
|
||||
# HELP mev_bot_net_profit_eth Net profit in ETH
|
||||
# TYPE mev_bot_net_profit_eth gauge
|
||||
mev_bot_net_profit_eth ` + floatToString(snapshot.NetProfit) + `
|
||||
|
||||
# HELP mev_bot_error_rate Trade error rate
|
||||
# TYPE mev_bot_error_rate gauge
|
||||
mev_bot_error_rate ` + floatToString(snapshot.ErrorRate) + `
|
||||
# HELP mev_bot_profit_factor Profit factor (net profit divided by gas costs)
|
||||
# TYPE mev_bot_profit_factor gauge
|
||||
mev_bot_profit_factor ` + floatToString(snapshot.ProfitFactor) + `
|
||||
|
||||
# HELP mev_bot_total_profit_eth Cumulative gross profit in ETH
|
||||
# TYPE mev_bot_total_profit_eth counter
|
||||
mev_bot_total_profit_eth ` + floatToString(snapshot.TotalProfit) + `
|
||||
|
||||
# HELP mev_bot_gas_spent_eth Cumulative gas spend in ETH
|
||||
# TYPE mev_bot_gas_spent_eth counter
|
||||
mev_bot_gas_spent_eth ` + floatToString(snapshot.GasCostsSpent) + `
|
||||
|
||||
# HELP mev_bot_uptime_seconds Bot uptime in seconds
|
||||
# TYPE mev_bot_uptime_seconds counter
|
||||
|
||||
Reference in New Issue
Block a user