blvm-protocol 0.1.10

Bitcoin Commons BLVM: Bitcoin protocol abstraction layer for multiple variants and evolution
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
//! Protocol validation interface
//!
//! This module provides protocol-specific validation that extends
//! the pure mathematical consensus rules with network-specific
//! and protocol-specific validation logic.

use crate::error::ProtocolError;
use crate::{BitcoinProtocolEngine, NetworkParameters, ProtocolVersion};
use crate::{Block, Transaction, ValidationResult};
use blvm_consensus::types::UtxoSet;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// Protocol-specific Result type
type Result<T> = std::result::Result<T, ProtocolError>;

/// Protocol-specific validation rules
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProtocolValidationRules {
    /// Maximum block size for this protocol
    pub max_block_size: u32,
    /// Maximum transaction size for this protocol
    pub max_tx_size: u32,
    /// Maximum script size for this protocol
    pub max_script_size: u32,
    /// Whether SegWit is enabled
    pub segwit_enabled: bool,
    /// Whether Taproot is enabled
    pub taproot_enabled: bool,
    /// Whether RBF (Replace-By-Fee) is enabled
    pub rbf_enabled: bool,
    /// Minimum transaction fee rate
    pub min_fee_rate: u64,
    /// Maximum transaction fee rate
    pub max_fee_rate: u64,
}

impl ProtocolValidationRules {
    /// Get validation rules for a specific protocol version
    pub fn for_protocol(version: ProtocolVersion) -> Self {
        match version {
            ProtocolVersion::BitcoinV1 => Self::mainnet(),
            ProtocolVersion::Testnet3 => Self::testnet(),
            ProtocolVersion::Regtest => Self::regtest(),
        }
    }

    /// Mainnet validation rules (strict production rules)
    pub fn mainnet() -> Self {
        Self {
            max_block_size: 4_000_000, // 4MB block size limit
            max_tx_size: 1_000_000,    // 1MB transaction size limit
            max_script_size: 10_000,   // 10KB script size limit
            segwit_enabled: true,
            taproot_enabled: true,
            rbf_enabled: true,
            min_fee_rate: 1,         // 1 sat/vB minimum
            max_fee_rate: 1_000_000, // 1M sat/vB maximum
        }
    }

    /// Testnet validation rules (same as mainnet but with testnet parameters)
    pub fn testnet() -> Self {
        Self {
            max_block_size: 4_000_000,
            max_tx_size: 1_000_000,
            max_script_size: 10_000,
            segwit_enabled: true,
            taproot_enabled: true,
            rbf_enabled: true,
            min_fee_rate: 1,
            max_fee_rate: 1_000_000,
        }
    }

    /// Regtest validation rules (relaxed for testing)
    pub fn regtest() -> Self {
        Self {
            max_block_size: 4_000_000,
            max_tx_size: 1_000_000,
            max_script_size: 10_000,
            segwit_enabled: true,
            taproot_enabled: true,
            rbf_enabled: true,
            min_fee_rate: 0, // No minimum fee for testing
            max_fee_rate: 1_000_000,
        }
    }
}

/// Protocol-specific validation context
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProtocolValidationContext {
    /// Current block height
    pub block_height: u64,
    /// Current network parameters
    pub network_params: NetworkParameters,
    /// Protocol validation rules
    pub validation_rules: ProtocolValidationRules,
    /// Median time-past used for time-based validation (BIP113)
    ///
    /// This is populated by the node using recent headers and is threaded down
    /// to consensus for timestamp validation.
    pub median_time_past: u64,
    /// Current adjusted network time (Unix timestamp)
    ///
    /// This is populated by the node from its time source and used by consensus
    /// to enforce future timestamp limits.
    pub network_time: u64,
    /// Additional context data
    pub context_data: HashMap<String, String>,
}

impl ProtocolValidationContext {
    /// Create validation context for a protocol version
    pub fn new(version: ProtocolVersion, block_height: u64) -> Result<Self> {
        let network_params = NetworkParameters::for_version(version)?;
        let validation_rules = ProtocolValidationRules::for_protocol(version);

        Ok(Self {
            block_height,
            network_params,
            validation_rules,
            // Default to zero; callers that care about time must set these explicitly.
            median_time_past: 0,
            network_time: 0,
            context_data: HashMap::new(),
        })
    }

    /// Check if a feature is enabled at current block height
    pub fn is_feature_enabled(&self, feature: &str) -> bool {
        match feature {
            "segwit" => self.validation_rules.segwit_enabled,
            "taproot" => self.validation_rules.taproot_enabled,
            "rbf" => self.validation_rules.rbf_enabled,
            _ => false,
        }
    }

    /// Get maximum allowed size for a component
    pub fn get_max_size(&self, component: &str) -> u32 {
        match component {
            "block" => self.validation_rules.max_block_size,
            "transaction" => self.validation_rules.max_tx_size,
            "script" => self.validation_rules.max_script_size,
            _ => 0,
        }
    }
}

impl BitcoinProtocolEngine {
    /// Validate a block with protocol-specific rules
    pub fn validate_block_with_protocol(
        &self,
        block: &Block,
        _utxos: &UtxoSet,
        _height: u64,
        context: &ProtocolValidationContext,
    ) -> Result<ValidationResult> {
        // First, apply protocol-specific validation
        self.apply_protocol_validation(block, context)?;

        Ok(ValidationResult::Valid)
    }

    /// Validate a transaction with protocol-specific rules
    pub fn validate_transaction_with_protocol(
        &self,
        tx: &Transaction,
        context: &ProtocolValidationContext,
    ) -> Result<ValidationResult> {
        // First, run consensus validation
        let consensus_result = self.consensus.validate_transaction(tx)?;

        // Then, apply protocol-specific validation
        self.apply_transaction_protocol_validation(tx, context)?;

        Ok(consensus_result)
    }

    /// Apply protocol-specific validation rules
    fn apply_protocol_validation(
        &self,
        block: &Block,
        context: &ProtocolValidationContext,
    ) -> Result<()> {
        // Check block size limits
        let block_size = self.calculate_block_size(block);
        if block_size > context.validation_rules.max_block_size {
            return Err(ProtocolError::Validation(
                format!(
                    "Block size exceeds maximum: {} bytes (max {} bytes)",
                    block_size, context.validation_rules.max_block_size
                )
                .into(),
            ));
        }

        // Check transaction count limits
        if block.transactions.len() > 10000 {
            // Reasonable limit
            return Err(ProtocolError::Validation(
                "Too many transactions in block (max 10000)".into(),
            ));
        }

        // Validate each transaction with protocol rules
        for tx in &block.transactions {
            self.apply_transaction_protocol_validation(tx, context)?;
        }

        Ok(())
    }

    /// Apply protocol-specific transaction validation
    fn apply_transaction_protocol_validation(
        &self,
        tx: &Transaction,
        context: &ProtocolValidationContext,
    ) -> Result<()> {
        // Check transaction size limits
        let tx_size = self.calculate_transaction_size(tx);
        if tx_size > context.validation_rules.max_tx_size {
            return Err(ProtocolError::Validation(
                format!(
                    "Transaction size exceeds maximum: {} bytes (max {} bytes)",
                    tx_size, context.validation_rules.max_tx_size
                )
                .into(),
            ));
        }

        // Check script size limits
        for input in &tx.inputs {
            if input.script_sig.len() > context.validation_rules.max_script_size as usize {
                return Err(ProtocolError::Validation(
                    format!(
                        "Script size exceeds maximum: {} bytes (max {} bytes)",
                        input.script_sig.len(),
                        context.validation_rules.max_script_size
                    )
                    .into(),
                ));
            }
        }

        for output in &tx.outputs {
            if output.script_pubkey.len() > context.validation_rules.max_script_size as usize {
                return Err(ProtocolError::Validation(
                    format!(
                        "Script size exceeds maximum: {} bytes (max {} bytes)",
                        output.script_pubkey.len(),
                        context.validation_rules.max_script_size
                    )
                    .into(),
                ));
            }
        }

        Ok(())
    }

    /// Calculate block size in bytes
    fn calculate_block_size(&self, block: &Block) -> u32 {
        // Simplified size calculation
        // In reality, this would include proper serialization
        let header_size = 80; // Block header is always 80 bytes
        let tx_count_size = 4; // Varint for transaction count
        let tx_sizes: u32 = block
            .transactions
            .iter()
            .map(|tx| self.calculate_transaction_size(tx))
            .sum();

        header_size + tx_count_size + tx_sizes
    }

    /// Calculate transaction size in bytes
    fn calculate_transaction_size(&self, tx: &Transaction) -> u32 {
        // Use canonical serialization-based size from consensus layer (TX_NO_WITNESS size).
        //
        // This keeps protocol-level size limits aligned with the exact serialization
        // used for consensus checks and transaction size tests.
        blvm_consensus::transaction::calculate_transaction_size(tx) as u32
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use blvm_consensus::types::{OutPoint, TransactionInput, TransactionOutput};
    use blvm_consensus::{Block, BlockHeader, Transaction};

    #[test]
    fn test_validation_rules() {
        let mainnet_rules = ProtocolValidationRules::mainnet();
        assert_eq!(mainnet_rules.max_block_size, 4_000_000);
        assert!(mainnet_rules.segwit_enabled);
        assert!(mainnet_rules.taproot_enabled);

        let regtest_rules = ProtocolValidationRules::regtest();
        assert_eq!(regtest_rules.max_block_size, 4_000_000);
        assert!(regtest_rules.segwit_enabled);
        assert_eq!(regtest_rules.min_fee_rate, 0); // No minimum fee for testing
    }

    #[test]
    fn test_validation_rules_all_protocols() {
        let mainnet_rules = ProtocolValidationRules::for_protocol(ProtocolVersion::BitcoinV1);
        let testnet_rules = ProtocolValidationRules::for_protocol(ProtocolVersion::Testnet3);
        let regtest_rules = ProtocolValidationRules::for_protocol(ProtocolVersion::Regtest);

        // Mainnet and testnet should have same rules
        assert_eq!(mainnet_rules.max_block_size, testnet_rules.max_block_size);
        assert_eq!(mainnet_rules.max_tx_size, testnet_rules.max_tx_size);
        assert_eq!(mainnet_rules.max_script_size, testnet_rules.max_script_size);
        assert_eq!(mainnet_rules.segwit_enabled, testnet_rules.segwit_enabled);
        assert_eq!(mainnet_rules.taproot_enabled, testnet_rules.taproot_enabled);
        assert_eq!(mainnet_rules.rbf_enabled, testnet_rules.rbf_enabled);
        assert_eq!(mainnet_rules.min_fee_rate, testnet_rules.min_fee_rate);
        assert_eq!(mainnet_rules.max_fee_rate, testnet_rules.max_fee_rate);

        // Regtest should have relaxed fee rules
        assert_eq!(regtest_rules.min_fee_rate, 0);
        assert_eq!(regtest_rules.max_fee_rate, mainnet_rules.max_fee_rate);
    }

    #[test]
    fn test_validation_rules_serialization() {
        let mainnet_rules = ProtocolValidationRules::mainnet();
        let json = serde_json::to_string(&mainnet_rules).unwrap();
        let deserialized: ProtocolValidationRules = serde_json::from_str(&json).unwrap();

        assert_eq!(mainnet_rules.max_block_size, deserialized.max_block_size);
        assert_eq!(mainnet_rules.max_tx_size, deserialized.max_tx_size);
        assert_eq!(mainnet_rules.max_script_size, deserialized.max_script_size);
        assert_eq!(mainnet_rules.segwit_enabled, deserialized.segwit_enabled);
        assert_eq!(mainnet_rules.taproot_enabled, deserialized.taproot_enabled);
        assert_eq!(mainnet_rules.rbf_enabled, deserialized.rbf_enabled);
        assert_eq!(mainnet_rules.min_fee_rate, deserialized.min_fee_rate);
        assert_eq!(mainnet_rules.max_fee_rate, deserialized.max_fee_rate);
    }

    #[test]
    fn test_validation_rules_equality() {
        let mainnet1 = ProtocolValidationRules::mainnet();
        let mainnet2 = ProtocolValidationRules::mainnet();
        let testnet = ProtocolValidationRules::testnet();

        assert_eq!(mainnet1, mainnet2);
        assert_eq!(mainnet1, testnet); // Mainnet and testnet should be identical
    }

    #[test]
    fn test_validation_context() {
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();
        assert_eq!(context.block_height, 1000);
        assert!(context.is_feature_enabled("segwit"));
        assert!(!context.is_feature_enabled("nonexistent"));
        assert_eq!(context.get_max_size("block"), 4_000_000);
    }

    #[test]
    fn test_validation_context_all_protocols() {
        let mainnet_context =
            ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();
        let testnet_context =
            ProtocolValidationContext::new(ProtocolVersion::Testnet3, 1000).unwrap();
        let regtest_context =
            ProtocolValidationContext::new(ProtocolVersion::Regtest, 1000).unwrap();

        // All should have same block height
        assert_eq!(mainnet_context.block_height, 1000);
        assert_eq!(testnet_context.block_height, 1000);
        assert_eq!(regtest_context.block_height, 1000);

        // All should support same features
        assert!(mainnet_context.is_feature_enabled("segwit"));
        assert!(testnet_context.is_feature_enabled("segwit"));
        assert!(regtest_context.is_feature_enabled("segwit"));

        assert!(mainnet_context.is_feature_enabled("taproot"));
        assert!(testnet_context.is_feature_enabled("taproot"));
        assert!(regtest_context.is_feature_enabled("taproot"));

        assert!(mainnet_context.is_feature_enabled("rbf"));
        assert!(testnet_context.is_feature_enabled("rbf"));
        assert!(regtest_context.is_feature_enabled("rbf"));
    }

    #[test]
    fn test_validation_context_feature_queries() {
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        // Test all supported features
        assert!(context.is_feature_enabled("segwit"));
        assert!(context.is_feature_enabled("taproot"));
        assert!(context.is_feature_enabled("rbf"));

        // Test unsupported features
        assert!(!context.is_feature_enabled("nonexistent"));
        assert!(!context.is_feature_enabled(""));
        assert!(!context.is_feature_enabled("fast_mining"));
    }

    #[test]
    fn test_validation_context_size_queries() {
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        assert_eq!(context.get_max_size("block"), 4_000_000);
        assert_eq!(context.get_max_size("transaction"), 1_000_000);
        assert_eq!(context.get_max_size("script"), 10_000);

        // Test unknown component
        assert_eq!(context.get_max_size("unknown"), 0);
    }

    #[test]
    fn test_validation_context_serialization() {
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();
        let json = serde_json::to_string(&context).unwrap();
        let deserialized: ProtocolValidationContext = serde_json::from_str(&json).unwrap();

        assert_eq!(context.block_height, deserialized.block_height);
        assert_eq!(
            context.network_params.network_name,
            deserialized.network_params.network_name
        );
        assert_eq!(
            context.validation_rules.max_block_size,
            deserialized.validation_rules.max_block_size
        );
    }

    #[test]
    fn test_validation_context_equality() {
        let context1 = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();
        let context2 = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();
        let context3 = ProtocolValidationContext::new(ProtocolVersion::Testnet3, 1000).unwrap();

        assert_eq!(context1, context2);
        assert_ne!(context1, context3); // Different network parameters
    }

    #[test]
    fn test_block_size_validation() {
        let engine = BitcoinProtocolEngine::new(ProtocolVersion::BitcoinV1).unwrap();
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        // Create a block that's within size limits with a valid coinbase transaction
        let coinbase_tx = Transaction {
            version: 1,
            inputs: blvm_consensus::tx_inputs![TransactionInput {
                prevout: OutPoint {
                    hash: [0u8; 32],
                    index: 0xffffffff,
                },
                script_sig: vec![0x01, 0x00], // Height 0
                sequence: 0xffffffff,
            }],
            outputs: blvm_consensus::tx_outputs![TransactionOutput {
                value: 50_0000_0000,
                script_pubkey: vec![blvm_consensus::opcodes::OP_1],
            }],
            lock_time: 0,
        };

        // Calculate proper merkle root
        let merkle_root = blvm_consensus::mining::calculate_merkle_root(&[coinbase_tx.clone()])
            .expect("Should calculate merkle root");

        let small_block = Block {
            header: BlockHeader {
                version: 1,
                prev_block_hash: [0u8; 32],
                merkle_root,
                timestamp: 1231006505,
                bits: 0x1d00ffff,
                nonce: 0,
            },
            transactions: vec![coinbase_tx].into_boxed_slice(),
        };

        // This should pass validation
        let result =
            engine.validate_block_with_protocol(&small_block, &UtxoSet::default(), 1000, &context);
        assert!(result.is_ok());
    }

    #[test]
    fn test_transaction_size_validation() {
        let engine = BitcoinProtocolEngine::new(ProtocolVersion::BitcoinV1).unwrap();
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        // Create a small transaction
        let small_tx = Transaction {
            version: 1,
            inputs: vec![TransactionInput {
                prevout: OutPoint {
                    hash: [0u8; 32],
                    index: 0,
                },
                script_sig: vec![blvm_consensus::opcodes::PUSH_65_BYTES, 0x04],
                sequence: 0xffffffff,
            }]
            .into(),
            outputs: vec![TransactionOutput {
                value: 50_0000_0000,
                script_pubkey: vec![
                    blvm_consensus::opcodes::OP_DUP,
                    blvm_consensus::opcodes::OP_HASH160,
                    blvm_consensus::opcodes::PUSH_20_BYTES,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    blvm_consensus::opcodes::OP_EQUALVERIFY,
                    blvm_consensus::opcodes::OP_CHECKSIG,
                ],
            }]
            .into(),
            lock_time: 0,
        };

        // This should pass validation
        let result = engine.validate_transaction_with_protocol(&small_tx, &context);
        assert!(result.is_ok());
    }

    #[test]
    fn test_script_size_validation() {
        let engine = BitcoinProtocolEngine::new(ProtocolVersion::BitcoinV1).unwrap();
        let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        // Create a transaction with small scripts
        let tx = Transaction {
            version: 1,
            inputs: vec![TransactionInput {
                prevout: OutPoint {
                    hash: [0u8; 32],
                    index: 0,
                },
                script_sig: vec![blvm_consensus::opcodes::PUSH_65_BYTES, 0x04],
                sequence: 0xffffffff,
            }]
            .into(),
            outputs: vec![TransactionOutput {
                value: 50_0000_0000,
                script_pubkey: vec![
                    blvm_consensus::opcodes::OP_DUP,
                    blvm_consensus::opcodes::OP_HASH160,
                    blvm_consensus::opcodes::PUSH_20_BYTES,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    blvm_consensus::opcodes::OP_EQUALVERIFY,
                    blvm_consensus::opcodes::OP_CHECKSIG,
                ],
            }]
            .into(),
            lock_time: 0,
        };

        // This should pass validation
        let result = engine.validate_transaction_with_protocol(&tx, &context);
        assert!(result.is_ok());
    }

    #[test]
    fn test_validation_context_data() {
        let mut context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 1000).unwrap();

        // Add some context data
        context
            .context_data
            .insert("test_key".to_string(), "test_value".to_string());

        assert_eq!(
            context.context_data.get("test_key"),
            Some(&"test_value".to_string())
        );
        assert_eq!(context.context_data.get("nonexistent"), None);
    }

    #[test]
    fn test_validation_rules_boundary_values() {
        let rules = ProtocolValidationRules::mainnet();

        // Test boundary values
        assert!(rules.max_block_size > 0);
        assert!(rules.max_tx_size > 0);
        assert!(rules.max_script_size > 0);
        assert!(rules.max_fee_rate > rules.min_fee_rate);

        // Test that limits are reasonable
        assert!(rules.max_block_size <= 10_000_000); // Not unreasonably large
        assert!(rules.max_tx_size <= 5_000_000); // Not unreasonably large
        assert!(rules.max_script_size <= 50_000); // Not unreasonably large
    }
}