@@ -206,10 +206,11 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, balanceFee, blo
206206// indicates a core error meaning that the message would always fail for that particular
207207// state and would never be accepted within a block.
208208func ApplyMessage (evm * vm.EVM , msg * Message , gp * GasPool , owner common.Address ) (* ExecutionResult , error ) {
209- return NewStateTransition (evm , msg , gp ).TransitionDb (owner )
209+ evm .SetTxContext (NewEVMTxContext (msg ))
210+ return newStateTransition (evm , msg , gp ).execute (owner )
210211}
211212
212- // StateTransition represents a state transition.
213+ // stateTransition represents a state transition.
213214//
214215// == The State Transitioning Model
215216//
@@ -231,7 +232,7 @@ func ApplyMessage(evm *vm.EVM, msg *Message, gp *GasPool, owner common.Address)
231232//
232233// 5. Run Script section
233234// 6. Derive new state root
234- type StateTransition struct {
235+ type stateTransition struct {
235236 gp * GasPool
236237 msg * Message
237238 gasRemaining uint64
@@ -240,25 +241,25 @@ type StateTransition struct {
240241 evm * vm.EVM
241242}
242243
243- // NewStateTransition initialises and returns a new state transition object.
244- func NewStateTransition (evm * vm.EVM , msg * Message , gp * GasPool ) * StateTransition {
245- return & StateTransition {
244+ // newStateTransition initialises and returns a new state transition object.
245+ func newStateTransition (evm * vm.EVM , msg * Message , gp * GasPool ) * stateTransition {
246+ return & stateTransition {
246247 gp : gp ,
247248 evm : evm ,
248249 msg : msg ,
249250 state : evm .StateDB ,
250251 }
251252}
252253
253- func (st * StateTransition ) from () common.Address {
254+ func (st * stateTransition ) from () common.Address {
254255 f := st .msg .From
255256 if ! st .state .Exist (f ) {
256257 st .state .CreateAccount (f )
257258 }
258259 return f
259260}
260261
261- func (st * StateTransition ) to () common.Address {
262+ func (st * stateTransition ) to () common.Address {
262263 if st .msg == nil {
263264 return common.Address {}
264265 }
@@ -272,7 +273,7 @@ func (st *StateTransition) to() common.Address {
272273 return * to
273274}
274275
275- func (st * StateTransition ) buyGas () error {
276+ func (st * stateTransition ) buyGas () error {
276277 mgval := new (big.Int ).SetUint64 (st .msg .GasLimit )
277278 mgval = mgval .Mul (mgval , st .msg .GasPrice )
278279 if st .msg .BalanceTokenFee == nil {
@@ -304,7 +305,7 @@ func (st *StateTransition) buyGas() error {
304305 return nil
305306}
306307
307- func (st * StateTransition ) preCheck () error {
308+ func (st * stateTransition ) preCheck () error {
308309 // Only check transactions that are not fake
309310 msg := st .msg
310311 if ! msg .SkipNonceChecks {
@@ -371,20 +372,17 @@ func (st *StateTransition) preCheck() error {
371372 return st .buyGas ()
372373}
373374
374- // TransitionDb will transition the state by applying the current message and
375+ // execute will transition the state by applying the current message and
375376// returning the evm execution result with following fields.
376377//
377- // - used gas:
378- // total gas used (including gas being refunded)
379- // - returndata:
380- // the returned data from evm
381- // - concrete execution error:
382- // various **EVM** error which aborts the execution,
383- // e.g. ErrOutOfGas, ErrExecutionReverted
378+ // - used gas: total gas used (including gas being refunded)
379+ // - returndata: the returned data from evm
380+ // - concrete execution error: various EVM errors which abort the execution, e.g.
381+ // ErrOutOfGas, ErrExecutionReverted
384382//
385383// However if any consensus issue encountered, return the error directly with
386384// nil evm execution result.
387- func (st * StateTransition ) TransitionDb (owner common.Address ) (* ExecutionResult , error ) {
385+ func (st * stateTransition ) execute (owner common.Address ) (* ExecutionResult , error ) {
388386 // First check this message satisfies all consensus rules before
389387 // applying the message. The rules include these clauses
390388 //
@@ -523,7 +521,7 @@ func (st *StateTransition) TransitionDb(owner common.Address) (*ExecutionResult,
523521}
524522
525523// validateAuthorization validates an EIP-7702 authorization against the state.
526- func (st * StateTransition ) validateAuthorization (auth * types.SetCodeAuthorization ) (authority common.Address , err error ) {
524+ func (st * stateTransition ) validateAuthorization (auth * types.SetCodeAuthorization ) (authority common.Address , err error ) {
527525 // Verify chain ID is null or equal to current chain ID.
528526 if ! auth .ChainID .IsZero () && auth .ChainID .CmpBig (st .evm .ChainConfig ().ChainID ) != 0 {
529527 return authority , ErrAuthorizationWrongChainID
@@ -554,7 +552,7 @@ func (st *StateTransition) validateAuthorization(auth *types.SetCodeAuthorizatio
554552}
555553
556554// applyAuthorization applies an EIP-7702 code delegation to the state.
557- func (st * StateTransition ) applyAuthorization (msg * Message , auth * types.SetCodeAuthorization ) error {
555+ func (st * stateTransition ) applyAuthorization (msg * Message , auth * types.SetCodeAuthorization ) error {
558556 authority , err := st .validateAuthorization (auth )
559557 if err != nil {
560558 return err
@@ -581,7 +579,7 @@ func (st *StateTransition) applyAuthorization(msg *Message, auth *types.SetCodeA
581579}
582580
583581// calcRefund computes refund counter, capped to a refund quotient.
584- func (st * StateTransition ) calcRefund () uint64 {
582+ func (st * stateTransition ) calcRefund () uint64 {
585583 var refund uint64
586584 if ! st .evm .ChainConfig ().IsEIP1559 (st .evm .Context .BlockNumber ) {
587585 // Before EIP-3529: refunds were capped to gasUsed / 2
@@ -601,7 +599,7 @@ func (st *StateTransition) calcRefund() uint64 {
601599
602600// returnGas returns ETH for remaining gas,
603601// exchanged at the original rate.
604- func (st * StateTransition ) returnGas () {
602+ func (st * stateTransition ) returnGas () {
605603 if st .msg .BalanceTokenFee == nil {
606604 remaining := new (big.Int ).SetUint64 (st .gasRemaining )
607605 remaining .Mul (remaining , st .msg .GasPrice )
@@ -618,6 +616,6 @@ func (st *StateTransition) returnGas() {
618616}
619617
620618// gasUsed returns the amount of gas used up by the state transition.
621- func (st * StateTransition ) gasUsed () uint64 {
619+ func (st * stateTransition ) gasUsed () uint64 {
622620 return st .initialGas - st .gasRemaining
623621}
0 commit comments