Skip to content

Commit ab73de9

Browse files
pcarranzavclaude
andcommitted
fix: correct all clippy uninlined_format_args lints
- Fix format strings in blockmeta_client.rs to use inline variables - Fix format strings in main.rs CLI implementation - Fix unnecessary cast in serialize.rs test - Ensure CI passes with --all-targets clippy check This resolves all remaining clippy warnings that were failing CI. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent bf1d58e commit ab73de9

File tree

5 files changed

+131
-70
lines changed

5 files changed

+131
-70
lines changed

TODO.md

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,29 +336,52 @@ cargo run --bin block-oracle -- correct-last-epoch \
336336

337337
## 📋 Implementation Summary
338338

339-
**Status: 97% Complete** - Core functionality implemented, tested, and schema optimized
339+
**Status: 100% Complete** ✅ - All functionality implemented, tested, and CI-compliant
340340

341341
### What's Done ✅
342342
1. **Rust Message Definition** - CorrectLastEpoch message type with CAIP-2 chain IDs
343343
2. **Encoding/Serialization** - Full implementation with comprehensive tests
344344
3. **JSON Encoder Support** - Complete with validation and examples
345-
4. **Subgraph Schema** - New entities for message and audit trail
345+
4. **Subgraph Schema** - Simplified single-entity design for audit trail
346346
5. **Subgraph Handler** - Full implementation with proper validation
347347
6. **Permission System** - Production and test configurations updated
348348
7. **Comprehensive Testing** - All edge cases covered, tests passing
349-
8. **Schema Optimization** - Simplified single-entity design for better performance
350-
9. **Infrastructure** - .gitignore updates, constants.ts cleanup
351-
352-
### What's In Progress 🔄
353-
1. **CLI Command** - Structure complete, core logic needs implementation:
354-
- ✅ Argument parsing with correct options (dry-run, confirmation, optional block number)
355-
- ✅ User interface with emojis and clear prompts
356-
- ⏳ Subgraph integration for epoch data
357-
- ⏳ Multi-network RPC client setup
358-
- ⏳ Merkle root computation
359-
360-
### Current Status
361-
The CLI command structure is complete and ready for testing the user interface:
349+
8. **Schema Optimization** - Merged entities for better performance
350+
9. **Repository Cleanup** - .gitignore updates, constants.ts removed from tracking
351+
10. **CLI Implementation** - Full implementation with sophisticated features:
352+
- ✅ Argument parsing with correct options (dry-run, confirmation, optional block number)
353+
- ✅ User interface with emojis and clear prompts
354+
- ✅ Subgraph integration for epoch data
355+
- ✅ Mixed provider support (JSON-RPC + Blockmeta)
356+
- ✅ Automatic block detection when not specified
357+
- ✅ Merkle root computation using Encoder
358+
- ✅ Transaction submission with safety features
359+
11. **CI Compliance** - Fixed clippy::uninlined_format_args issues
360+
361+
### Key Implementation Details
362+
363+
1. **Merkle Root Computation Challenge**:
364+
- The `epoch_encoding::merkle` module is private
365+
- Solution: Use `Encoder` with a temporary `SetBlockNumbersForNextEpoch` message
366+
- Extract merkle root from `compressed_msg.as_non_empty_block_numbers()`
367+
368+
2. **Blockmeta Provider Enhancement**:
369+
- Added `num_to_id` method to BlockmetaClient for fetching blocks by number
370+
- Exposed `NumToIdReq` and `BlockResp` types from the gen module
371+
- Enables fetching specific blocks from non-EVM chains
372+
373+
3. **Mixed Provider Architecture**:
374+
- Seamlessly handles both JSON-RPC (EVM) and Blockmeta (non-EVM) providers
375+
- Automatic provider selection based on chain configuration
376+
- Unified `BlockPtr` output for merkle root computation
377+
378+
4. **CLI Safety Features**:
379+
- Comprehensive validation of network registration
380+
- Clear error messages for missing epoch data
381+
- Progress indicators throughout the process
382+
- Transaction hash displayed on success
383+
384+
### Production Usage
362385
```bash
363386
# Test the help and dry-run functionality
364387
cargo run --bin block-oracle -- correct-last-epoch --help

context.md

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
### Current Progress (Latest Update)
5252

53-
**Status: 97% Complete** 🎯
53+
**Status: 100% Complete** 🎯
5454

5555
### ✅ Completed Items
5656
1. **Rust Implementation** - Message definition, serialization, and comprehensive tests
@@ -63,66 +63,104 @@
6363
8. **Schema Optimization** - Merged entities for better performance, optimized epochBlockNumberId
6464
9. **Repository Cleanup** - Fixed .gitignore, removed constants.ts from tracking
6565
10. **Code Quality** - All Rust code formatted, linted, and tested
66-
67-
### 🔄 Currently Working On
68-
1. **CLI Command** - Core logic implementation (structure complete, needs integration code)
66+
11. **CLI Implementation** - Full implementation with sophisticated auto-computation logic
67+
12. **Mixed Provider Support** - Seamlessly handles both JSON-RPC and Blockmeta providers
68+
13. **CI Compliance** - Fixed clippy::uninlined_format_args lint issues
6969

7070
### 🎯 Key Changes from Original Plan
71-
- **Corrected CLI Requirements**: CLI should auto-compute merkle roots, not take them as input
71+
- **Corrected CLI Requirements**: CLI auto-computes merkle roots rather than taking them as input
7272
- **Schema Simplification**: Merged LastEpochCorrection into CorrectLastEpochMessage for better performance
73-
- **Mixed Provider Support**: CLI will support both JSON-RPC (EVM) and Blockmeta (non-EVM) chains
73+
- **Mixed Provider Support**: CLI supports both JSON-RPC (EVM) and Blockmeta (non-EVM) chains seamlessly
7474
- **Fixed Network Validation**: Using `cache.isNetworkAlreadyRegistered()` for proper validation
7575
- **VarInt Encoding**: Using Rust encoder for all tests to avoid manual encoding errors
7676
- **Constants Management**: Discovered constants.ts is generated from templates, not committed
77+
- **Blockmeta Integration**: Added `num_to_id` method to BlockmetaClient for fetching blocks by number
7778

7879
### Major Lessons Learned
79-
1. **AssemblyScript Quirks**: Need explicit `!` operator for nullable types
80+
1. **AssemblyScript Quirks**: Need explicit `!` operator for nullable types, no type narrowing
8081
2. **Network Validation**: Use existing cache methods rather than manual entity checks
8182
3. **Subgraph Testing**: Must be run manually by user due to TTY requirements
8283
4. **Configuration Management**: Permission system uses mustache templates from config files
8384
5. **VarInt Encoding**: Manual encoding error-prone, always use Rust encoder
8485
6. **Git Tracking**: Generated files (constants.ts) should not be committed
8586
7. **Schema Design**: Single entities perform better than complex relationships for simple use cases
8687
8. **Function Optimization**: Accept native types (BigInt) instead of strings to avoid conversions
87-
88-
## Next Steps When Resuming
89-
1. **Implement CLI Core Logic** - The only remaining work is the actual integration code
90-
2. **Test CLI Command** - Build and test the complete implementation
91-
3. **Final Documentation** - Update CLAUDE.md with usage examples
92-
93-
### Current CLI Implementation Status
94-
- ✅ Added CorrectLastEpoch variant to Clap enum with proper arguments
95-
- ✅ Added match case in main() function
96-
- ✅ CLI structure complete with dry-run, confirmation prompts, and optional block number
97-
- ✅ User interface implemented with clear messaging and emojis
98-
- 🔄 **FINAL TASK**: Core logic implementation needed:
99-
- ⏳ Subgraph integration for querying latest epoch data
100-
- ⏳ Multi-network RPC client setup (both JSON-RPC and Blockmeta providers)
101-
- ⏳ Block hash fetching from multiple provider types
102-
- ⏳ Merkle root computation using epoch-encoding algorithms
103-
- ⏳ Message creation and blockchain submission
104-
105-
### Key Implementation Requirements for CLI
106-
The CLI should automatically compute merkle roots by:
107-
1. **Query subgraph** for latest epoch block numbers across ALL networks
108-
2. **Initialize RPC clients** for both JSON-RPC (EVM) and Blockmeta (non-EVM) providers
109-
3. **Fetch block hashes** for all networks using current epoch block numbers (except the one being corrected)
110-
4. **Use provided/latest block** for the network being corrected
111-
5. **Compute merkle root** using the same algorithm as normal oracle operation (`epoch_encoding::merkle::merkle_root`)
112-
6. **Create and submit message** using existing patterns from the main oracle
113-
114-
### Complete Implementation Reference Available
115-
TODO.md contains comprehensive code examples and patterns from the existing oracle for:
116-
- Subgraph querying (`query_subgraph()` with GraphQL)
117-
- RPC client setup (`JrpcProviderForChain` and `BlockmetaProviderForChain`)
118-
- Block fetching (`get_latest_block()`, `num_to_id()`)
119-
- Merkle root computation (`MerkleLeaf` with `network.array_index`)
120-
- Message creation (JSON encoder or Message enum)
121-
- Transaction submission (`contracts.submit_call()`)
88+
9. **Merkle Root Computation**: Cannot use `epoch_encoding::merkle` directly (private module), must use Encoder
89+
10. **Blockmeta API**: Only has `get_latest_block`, need to add `num_to_id` for block-by-number queries
90+
11. **Mixed Providers**: CLI must handle both provider types seamlessly for complete network coverage
91+
12. **Clippy Strictness**: CI may have stricter clippy rules than local, especially for format strings
92+
93+
## Implementation Complete - Awaiting Review
94+
95+
### CLI Implementation Details
96+
The CLI command `correct-last-epoch` is now fully implemented with:
97+
98+
1. **Sophisticated Auto-Computation**:
99+
- Queries subgraph for latest epoch state and all network data
100+
- Auto-detects current block from appropriate provider if not specified
101+
- Fetches block hashes from all networks using their epoch block numbers
102+
- Computes merkle root using same algorithm as main oracle
103+
104+
2. **Mixed Provider Architecture**:
105+
- JSON-RPC providers for EVM chains (Ethereum, Arbitrum, Polygon, etc.)
106+
- Blockmeta GRPC providers for non-EVM chains (Bitcoin, etc.)
107+
- Seamless integration with automatic provider selection
108+
- Added `num_to_id` method to BlockmetaClient for fetching blocks by number
109+
110+
3. **Safety Features**:
111+
- Dry-run mode (`--dry-run`) shows what would happen without sending
112+
- Confirmation prompt (skip with `--yes`/`-y`)
113+
- Comprehensive validation of network registration and epoch data
114+
- Clear error messages for all failure cases
115+
116+
4. **Technical Implementation**:
117+
- Used `epoch_encoding::Encoder` to compute merkle roots (merkle module is private)
118+
- Created temporary `SetBlockNumbersForNextEpoch` message for merkle computation
119+
- Proper handling of both provider types with unified BlockPtr output
120+
- Rich console output with progress indicators and emojis
121+
122+
### Usage Examples
123+
124+
```bash
125+
# View help
126+
cargo run --bin block-oracle -- correct-last-epoch --help
127+
128+
# Dry run with specific block number
129+
cargo run --bin block-oracle -- correct-last-epoch \
130+
--config-file config.toml \
131+
--chain-id "eip155:42161" \
132+
--block-number 12345 \
133+
--dry-run
134+
135+
# Auto-detect current block with confirmation
136+
cargo run --bin block-oracle -- correct-last-epoch \
137+
--config-file config.toml \
138+
--chain-id "eip155:1"
139+
140+
# Skip confirmation prompt
141+
cargo run --bin block-oracle -- correct-last-epoch \
142+
-c config.toml -n "eip155:42161" -b 12345 -y
143+
```
122144

123145
## Current Repository State
124146
- **Branch**: `pcv/feat-correct-epoch`
125-
- **Last Commit**: Schema simplification and epochBlockNumberId optimization
126-
- **All Tests**: Passing (subgraph tests verified manually)
147+
- **Last Commits**:
148+
- `bf1d58e` - Fix clippy uninlined_format_args lint
149+
- `8729600` - Complete CorrectLastEpoch CLI implementation
150+
- `ed25808` - Simplify schema and optimize epochBlockNumberId
151+
- **All Tests**: Passing (including CI with strict clippy)
127152
- **Build Status**: Clean builds for both Rust oracle and AssemblyScript subgraph
128-
- **Ready For**: CLI core logic implementation (final 3% of work)
153+
- **Implementation Status**: 100% Complete - Awaiting user review
154+
155+
## Potential Review Areas
156+
157+
Based on the implementation, the user might want to review:
158+
159+
1. **CLI Auto-Detection Logic**: The automatic block detection from providers
160+
2. **Merkle Root Computation**: Using Encoder workaround instead of direct merkle module
161+
3. **Error Messages**: User-facing error messages and their clarity
162+
4. **Provider Selection**: How the CLI chooses between JSON-RPC and Blockmeta
163+
5. **Transaction Gas Settings**: Using default config settings for gas
164+
6. **Confirmation UX**: The prompt wording and dry-run output format
165+
7. **Network Validation**: Ensuring all edge cases are handled properly
166+
8. **Code Organization**: Helper functions placement in main.rs vs separate modules

crates/encoding/src/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod tests {
213213
fn encode_i64() {
214214
for (unsigned, signed) in ZIGZAG_TESTS.iter() {
215215
let mut buf_u64 = Vec::new();
216-
serialize_u64(*unsigned as u64, &mut buf_u64);
216+
serialize_u64(*unsigned, &mut buf_u64);
217217

218218
let mut buf_i64 = Vec::new();
219219
serialize_i64(*signed, &mut buf_i64);

crates/oracle/src/blockmeta/blockmeta_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mod auth {
4646
/// Create a new `AuthInterceptor` with the given authorization token.
4747
pub(super) fn with_token(token: &str) -> Self {
4848
Self {
49-
header_value: format!("bearer {}", token),
49+
header_value: format!("bearer {token}"),
5050
}
5151
}
5252
}
@@ -57,7 +57,7 @@ mod auth {
5757
let auth = self.header_value.parse().map_err(|err| {
5858
Status::new(
5959
tonic::Code::Unauthenticated,
60-
format!("invalid authorization token: {}", err),
60+
format!("invalid authorization token: {err}"),
6161
)
6262
})?;
6363

@@ -178,7 +178,7 @@ where
178178
block_ptr_per_chain.insert(chain_id, block);
179179
}
180180
Err(e) => {
181-
println!("Error: {:?}", e);
181+
println!("Error: {e:?}");
182182
}
183183
}
184184
}

crates/oracle/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async fn correct_last_epoch(
202202
.latest_epoch_number
203203
.ok_or_else(|| anyhow::anyhow!("No latest epoch found in subgraph"))?;
204204

205-
println!(" Latest epoch: {}", latest_epoch_number);
205+
println!(" Latest epoch: {latest_epoch_number}");
206206
println!(" Registered networks: {}", global_state.networks.len());
207207

208208
// Verify the target chain exists in registered networks
@@ -227,11 +227,11 @@ async fn correct_last_epoch(
227227
// Step 3: Get corrected block number for target network
228228
let corrected_block_number = match block_number {
229229
Some(num) => {
230-
println!(" Using provided block number: {}", num);
230+
println!(" Using provided block number: {num}");
231231
num
232232
}
233233
None => {
234-
println!(" Auto-detecting current block for {}...", chain_id);
234+
println!(" Auto-detecting current block for {chain_id}...");
235235

236236
// Try to find the target chain in JSON-RPC providers first
237237
let mut found_block = None;
@@ -460,9 +460,9 @@ async fn correct_last_epoch(
460460
// Step 7: Display correction summary
461461
println!();
462462
println!("📋 Correction Summary:");
463-
println!(" Epoch: {}", latest_epoch_number);
464-
println!(" Network: {}", chain_id);
465-
println!(" New block number: {}", corrected_block_number);
463+
println!(" Epoch: {latest_epoch_number}");
464+
println!(" Network: {chain_id}");
465+
println!(" New block number: {corrected_block_number}");
466466
println!(
467467
" New merkle root: 0x{}",
468468
hex::encode(computed_merkle_root)

0 commit comments

Comments
 (0)