@@ -116,9 +116,6 @@ class BaseChain(Configurable, ChainAPI):
116
116
117
117
@classmethod
118
118
def get_vm_class_for_block_number (cls , block_number : BlockNumber ) -> Type [VirtualMachineAPI ]:
119
- """
120
- Returns the VM class for the given block number.
121
- """
122
119
if cls .vm_configuration is None :
123
120
raise AttributeError ("Chain classes must define the VMs in vm_configuration" )
124
121
@@ -142,13 +139,6 @@ def validate_chain(
142
139
root : BlockHeaderAPI ,
143
140
descendants : Tuple [BlockHeaderAPI , ...],
144
141
seal_check_random_sample_rate : int = 1 ) -> None :
145
- """
146
- Validate that all of the descendents are valid, given that the root header is valid.
147
-
148
- By default, check the seal validity (Proof-of-Work on Ethereum 1.x mainnet) of all headers.
149
- This can be expensive. Instead, check a random sample of seals using
150
- seal_check_random_sample_rate.
151
- """
152
142
153
143
all_indices = range (len (descendants ))
154
144
if seal_check_random_sample_rate == 1 :
@@ -178,12 +168,6 @@ def validate_chain(
178
168
179
169
180
170
class Chain (BaseChain ):
181
- """
182
- A Chain is a combination of one or more VM classes. Each VM is associated
183
- with a range of blocks. The Chain class acts as a wrapper around these other
184
- VM classes, delegating operations to the appropriate VM depending on the
185
- current block number.
186
- """
187
171
logger = logging .getLogger ("eth.chain.chain.Chain" )
188
172
gas_estimator : StaticMethod [Callable [[StateAPI , SignedTransactionAPI ], int ]] = None
189
173
@@ -219,9 +203,6 @@ def from_genesis(cls,
219
203
base_db : AtomicDatabaseAPI ,
220
204
genesis_params : Dict [str , HeaderParams ],
221
205
genesis_state : AccountState = None ) -> 'BaseChain' :
222
- """
223
- Initializes the Chain from a genesis state.
224
- """
225
206
genesis_vm_class = cls .get_vm_class_for_block_number (BlockNumber (0 ))
226
207
227
208
pre_genesis_header = BlockHeader (difficulty = 0 , block_number = - 1 , gas_limit = 0 )
@@ -255,9 +236,6 @@ def from_genesis(cls,
255
236
def from_genesis_header (cls ,
256
237
base_db : AtomicDatabaseAPI ,
257
238
genesis_header : BlockHeaderAPI ) -> 'BaseChain' :
258
- """
259
- Initializes the chain from the genesis header.
260
- """
261
239
chaindb = cls .get_chaindb_class ()(base_db )
262
240
chaindb .persist_header (genesis_header )
263
241
return cls (base_db )
@@ -266,9 +244,6 @@ def from_genesis_header(cls,
266
244
# VM API
267
245
#
268
246
def get_vm (self , at_header : BlockHeaderAPI = None ) -> VirtualMachineAPI :
269
- """
270
- Returns the VM instance for the given block number.
271
- """
272
247
header = self .ensure_header (at_header )
273
248
vm_class = self .get_vm_class_for_block_number (header .block_number )
274
249
chain_context = ChainContext (self .chain_id )
@@ -280,37 +255,18 @@ def get_vm(self, at_header: BlockHeaderAPI = None) -> VirtualMachineAPI:
280
255
def create_header_from_parent (self ,
281
256
parent_header : BlockHeaderAPI ,
282
257
** header_params : HeaderParams ) -> BlockHeaderAPI :
283
- """
284
- Passthrough helper to the VM class of the block descending from the
285
- given header.
286
- """
287
258
return self .get_vm_class_for_block_number (
288
259
block_number = BlockNumber (parent_header .block_number + 1 ),
289
260
).create_header_from_parent (parent_header , ** header_params )
290
261
291
262
def get_block_header_by_hash (self , block_hash : Hash32 ) -> BlockHeaderAPI :
292
- """
293
- Returns the requested block header as specified by block hash.
294
-
295
- Raises BlockNotFound if there's no block header with the given hash in the db.
296
- """
297
263
validate_word (block_hash , title = "Block Hash" )
298
264
return self .chaindb .get_block_header_by_hash (block_hash )
299
265
300
266
def get_canonical_head (self ) -> BlockHeaderAPI :
301
- """
302
- Returns the block header at the canonical chain head.
303
-
304
- Raises CanonicalHeadNotFound if there's no head defined for the canonical chain.
305
- """
306
267
return self .chaindb .get_canonical_head ()
307
268
308
269
def get_score (self , block_hash : Hash32 ) -> int :
309
- """
310
- Returns the difficulty score of the block with the given hash.
311
-
312
- Raises HeaderNotFound if there is no matching black hash.
313
- """
314
270
return self .headerdb .get_score (block_hash )
315
271
316
272
def ensure_header (self , header : BlockHeaderAPI = None ) -> BlockHeaderAPI :
@@ -328,9 +284,6 @@ def ensure_header(self, header: BlockHeaderAPI = None) -> BlockHeaderAPI:
328
284
# Block API
329
285
#
330
286
def get_ancestors (self , limit : int , header : BlockHeaderAPI ) -> Tuple [BlockAPI , ...]:
331
- """
332
- Return `limit` number of ancestor blocks from the current canonical head.
333
- """
334
287
ancestor_count = min (header .block_number , limit )
335
288
336
289
# We construct a temporary block object
@@ -350,59 +303,29 @@ def get_ancestors(self, limit: int, header: BlockHeaderAPI) -> Tuple[BlockAPI, .
350
303
return tuple (take (ancestor_count , ancestor_generator ))
351
304
352
305
def get_block (self ) -> BlockAPI :
353
- """
354
- Returns the current TIP block.
355
- """
356
306
return self .get_vm ().get_block ()
357
307
358
308
def get_block_by_hash (self , block_hash : Hash32 ) -> BlockAPI :
359
- """
360
- Returns the requested block as specified by block hash.
361
- """
362
309
validate_word (block_hash , title = "Block Hash" )
363
310
block_header = self .get_block_header_by_hash (block_hash )
364
311
return self .get_block_by_header (block_header )
365
312
366
313
def get_block_by_header (self , block_header : BlockHeaderAPI ) -> BlockAPI :
367
- """
368
- Returns the requested block as specified by the block header.
369
- """
370
314
vm = self .get_vm (block_header )
371
315
return vm .get_block ()
372
316
373
317
def get_canonical_block_by_number (self , block_number : BlockNumber ) -> BlockAPI :
374
- """
375
- Returns the block with the given number in the canonical chain.
376
-
377
- Raises BlockNotFound if there's no block with the given number in the
378
- canonical chain.
379
- """
380
318
validate_uint256 (block_number , title = "Block Number" )
381
319
return self .get_block_by_hash (self .chaindb .get_canonical_block_hash (block_number ))
382
320
383
321
def get_canonical_block_hash (self , block_number : BlockNumber ) -> Hash32 :
384
- """
385
- Returns the block hash with the given number in the canonical chain.
386
-
387
- Raises BlockNotFound if there's no block with the given number in the
388
- canonical chain.
389
- """
390
322
return self .chaindb .get_canonical_block_hash (block_number )
391
323
392
324
def build_block_with_transactions (
393
325
self ,
394
326
transactions : Sequence [SignedTransactionAPI ],
395
327
parent_header : BlockHeaderAPI = None
396
328
) -> Tuple [BlockAPI , Tuple [ReceiptAPI , ...], Tuple [ComputationAPI , ...]]:
397
- """
398
- Generate a block with the provided transactions. This does *not* import
399
- that block into your chain. If you want this new block in your chain,
400
- run :meth:`~import_block` with the result block from this method.
401
-
402
- :param transactions: an iterable of transactions to insert to the block
403
- :param parent_header: parent of the new block -- or canonical head if ``None``
404
- :return: (new block, receipts, computations)
405
- """
406
329
base_header = self .ensure_header (parent_header )
407
330
vm = self .get_vm (base_header )
408
331
@@ -415,13 +338,6 @@ def build_block_with_transactions(
415
338
# Transaction API
416
339
#
417
340
def get_canonical_transaction (self , transaction_hash : Hash32 ) -> SignedTransactionAPI :
418
- """
419
- Returns the requested transaction as specified by the transaction hash
420
- from the canonical chain.
421
-
422
- Raises TransactionNotFound if no transaction with the specified hash is
423
- found in the main chain.
424
- """
425
341
(block_num , index ) = self .chaindb .get_transaction_index (transaction_hash )
426
342
VM_class = self .get_vm_class_for_block_number (block_num )
427
343
@@ -440,9 +356,6 @@ def get_canonical_transaction(self, transaction_hash: Hash32) -> SignedTransacti
440
356
)
441
357
442
358
def create_transaction (self , * args : Any , ** kwargs : Any ) -> SignedTransactionAPI :
443
- """
444
- Passthrough helper to the current VM class.
445
- """
446
359
return self .get_vm ().create_transaction (* args , ** kwargs )
447
360
448
361
def create_unsigned_transaction (self ,
@@ -453,9 +366,6 @@ def create_unsigned_transaction(self,
453
366
to : Address ,
454
367
value : int ,
455
368
data : bytes ) -> UnsignedTransactionAPI :
456
- """
457
- Passthrough helper to the current VM class.
458
- """
459
369
return self .get_vm ().create_unsigned_transaction (
460
370
nonce = nonce ,
461
371
gas_price = gas_price ,
@@ -483,10 +393,7 @@ def get_transaction_result(
483
393
self ,
484
394
transaction : SignedTransactionAPI ,
485
395
at_header : BlockHeaderAPI ) -> bytes :
486
- """
487
- Return the result of running the given transaction.
488
- This is referred to as a `call()` in web3.
489
- """
396
+
490
397
with self .get_vm (at_header ).state_in_temp_block () as state :
491
398
computation = state .costless_execute_transaction (transaction )
492
399
@@ -497,10 +404,6 @@ def estimate_gas(
497
404
self ,
498
405
transaction : SignedTransactionAPI ,
499
406
at_header : BlockHeaderAPI = None ) -> int :
500
- """
501
- Returns an estimation of the amount of gas the given transaction will
502
- use if executed on top of the block specified by the given header.
503
- """
504
407
if at_header is None :
505
408
at_header = self .get_canonical_head ()
506
409
with self .get_vm (at_header ).state_in_temp_block () as state :
@@ -510,13 +413,6 @@ def import_block(self,
510
413
block : BlockAPI ,
511
414
perform_validation : bool = True
512
415
) -> Tuple [BlockAPI , Tuple [BlockAPI , ...], Tuple [BlockAPI , ...]]:
513
- """
514
- Imports a complete block and returns a 3-tuple
515
-
516
- - the imported block
517
- - a tuple of blocks which are now part of the canonical chain.
518
- - a tuple of blocks which were canonical and now are no longer canonical.
519
- """
520
416
521
417
try :
522
418
parent_header = self .get_block_header_by_hash (block .header .parent_hash )
@@ -567,15 +463,6 @@ def validate_receipt(self, receipt: ReceiptAPI, at_header: BlockHeaderAPI) -> No
567
463
VM_class .validate_receipt (receipt )
568
464
569
465
def validate_block (self , block : BlockAPI ) -> None :
570
- """
571
- Performs validation on a block that is either being mined or imported.
572
-
573
- Since block validation (specifically the uncle validation) must have
574
- access to the ancestor blocks, this validation must occur at the Chain
575
- level.
576
-
577
- Cannot be used to validate genesis block.
578
- """
579
466
if block .is_genesis :
580
467
raise ValidationError ("Cannot validate genesis block this way" )
581
468
VM_class = self .get_vm_class_for_block_number (BlockNumber (block .number ))
@@ -585,16 +472,10 @@ def validate_block(self, block: BlockAPI) -> None:
585
472
self .validate_gaslimit (block .header )
586
473
587
474
def validate_seal (self , header : BlockHeaderAPI ) -> None :
588
- """
589
- Validate the seal on the given header.
590
- """
591
475
VM_class = self .get_vm_class_for_block_number (BlockNumber (header .block_number ))
592
476
VM_class .validate_seal (header )
593
477
594
478
def validate_gaslimit (self , header : BlockHeaderAPI ) -> None :
595
- """
596
- Validate the gas limit on the given header.
597
- """
598
479
parent_header = self .get_block_header_by_hash (header .parent_hash )
599
480
low_bound , high_bound = compute_gas_limit_bounds (parent_header )
600
481
if header .gas_limit < low_bound :
@@ -611,9 +492,6 @@ def validate_gaslimit(self, header: BlockHeaderAPI) -> None:
611
492
)
612
493
613
494
def validate_uncles (self , block : BlockAPI ) -> None :
614
- """
615
- Validate the uncles for the given block.
616
- """
617
495
has_uncles = len (block .uncles ) > 0
618
496
should_have_uncles = block .header .uncles_hash != EMPTY_UNCLE_HASH
619
497
@@ -701,12 +579,6 @@ def __init__(self, base_db: AtomicDatabaseAPI, header: BlockHeaderAPI = None) ->
701
579
def apply_transaction (self ,
702
580
transaction : SignedTransactionAPI
703
581
) -> Tuple [BlockAPI , ReceiptAPI , ComputationAPI ]:
704
- """
705
- Applies the transaction to the current tip block.
706
-
707
- WARNING: ReceiptAPI and Transaction trie generation is computationally
708
- heavy and incurs significant performance overhead.
709
- """
710
582
vm = self .get_vm (self .header )
711
583
base_block = vm .get_block ()
712
584
@@ -737,10 +609,6 @@ def import_block(self,
737
609
return imported_block , new_canonical_blocks , old_canonical_blocks
738
610
739
611
def mine_block (self , * args : Any , ** kwargs : Any ) -> BlockAPI :
740
- """
741
- Mines the current block. Proxies to the current Virtual Machine.
742
- See VM. :meth:`~eth.vm.base.VM.mine_block`
743
- """
744
612
mined_block = self .get_vm (self .header ).mine_block (* args , ** kwargs )
745
613
746
614
self .validate_block (mined_block )
0 commit comments