core, all: split vm.Context into BlockContext and TxContext (#21672)
* all: core: split vm.Config into BlockConfig and TxConfig * core: core/vm: reset EVM between tx in block instead of creating new * core/vm: added docs
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							6f4cccf8d2
						
					
				
				
					commit
					2045a2bba3
				
			
							
								
								
									
										16
									
								
								core/evm.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								core/evm.go
									
									
									
									
									
								
							| @@ -35,8 +35,8 @@ type ChainContext interface { | ||||
| 	GetHeader(common.Hash, uint64) *types.Header | ||||
| } | ||||
|  | ||||
| // NewEVMContext creates a new context for use in the EVM. | ||||
| func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author *common.Address) vm.Context { | ||||
| // NewEVMBlockContext creates a new context for use in the EVM. | ||||
| func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common.Address) vm.BlockContext { | ||||
| 	// If we don't have an explicit author (i.e. not mining), extract from the header | ||||
| 	var beneficiary common.Address | ||||
| 	if author == nil { | ||||
| @@ -44,17 +44,23 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author | ||||
| 	} else { | ||||
| 		beneficiary = *author | ||||
| 	} | ||||
| 	return vm.Context{ | ||||
| 	return vm.BlockContext{ | ||||
| 		CanTransfer: CanTransfer, | ||||
| 		Transfer:    Transfer, | ||||
| 		GetHash:     GetHashFn(header, chain), | ||||
| 		Origin:      msg.From(), | ||||
| 		Coinbase:    beneficiary, | ||||
| 		BlockNumber: new(big.Int).Set(header.Number), | ||||
| 		Time:        new(big.Int).SetUint64(header.Time), | ||||
| 		Difficulty:  new(big.Int).Set(header.Difficulty), | ||||
| 		GasLimit:    header.GasLimit, | ||||
| 		GasPrice:    new(big.Int).Set(msg.GasPrice()), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // NewEVMTxContext creates a new transaction context for a single transaction. | ||||
| func NewEVMTxContext(msg Message) vm.TxContext { | ||||
| 	return vm.TxContext{ | ||||
| 		Origin:   msg.From(), | ||||
| 		GasPrice: new(big.Int).Set(msg.GasPrice()), | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user