@@ -93,8 +93,8 @@ The state transitioning model does all the necessary work to work out a valid ne
93936) Derive new state root
9494*/
9595
96- // StateTransition is the state of current tx in vm
97- type StateTransition struct {
96+ // stateTransition is the state of current tx in vm
97+ type stateTransition struct {
9898 gp * GasPool
9999 qp * QuotaPool
100100 msg * Message
@@ -106,27 +106,27 @@ type StateTransition struct {
106106}
107107
108108type Message struct {
109- To * common.Address
110- From common.Address
111- Nonce uint64
112- Value * big.Int
113- GasLimit uint64
114- GasPrice * big.Int
115- Data []byte
116- SkipAccountChecks bool
109+ To * common.Address
110+ From common.Address
111+ Nonce uint64
112+ Value * big.Int
113+ GasLimit uint64
114+ GasPrice * big.Int
115+ Data []byte
116+ SkipNonceChecks bool
117117}
118118
119119// XXX Rename message to something less arbitrary?
120120// TransactionToMessage converts a transaction into a Message.
121121func TransactionToMessage (tx * types.Transaction , s types.Signer ) (* Message , error ) {
122122 msg := & Message {
123- Nonce : tx .Nonce (),
124- GasLimit : tx .Gas (),
125- GasPrice : new (big.Int ).Set (tx .GasPrice ()),
126- To : tx .To (),
127- Value : tx .Value (),
128- Data : tx .Data (),
129- SkipAccountChecks : false ,
123+ Nonce : tx .Nonce (),
124+ GasLimit : tx .Gas (),
125+ GasPrice : new (big.Int ).Set (tx .GasPrice ()),
126+ To : tx .To (),
127+ Value : tx .Value (),
128+ Data : tx .Data (),
129+ SkipNonceChecks : false ,
130130 }
131131
132132 var err error
@@ -171,9 +171,9 @@ func IntrinsicGas(data []byte, contractCreation, upload, isHomestead, isEIP2028
171171 return gas , nil
172172}
173173
174- // NewStateTransition initialises and returns a new state transition object.
175- func NewStateTransition (cvm * vm.CVM , msg * Message , gp * GasPool , qp * QuotaPool ) * StateTransition {
176- return & StateTransition {
174+ // newStateTransition initialises and returns a new state transition object.
175+ func newStateTransition (cvm * vm.CVM , msg * Message , gp * GasPool , qp * QuotaPool ) * stateTransition {
176+ return & stateTransition {
177177 gp : gp ,
178178 qp : qp ,
179179 cvm : cvm ,
@@ -191,18 +191,18 @@ func NewStateTransition(cvm *vm.CVM, msg *Message, gp *GasPool, qp *QuotaPool) *
191191// state and would never be accepted within a block.
192192func ApplyMessage (cvm * vm.CVM , msg * Message , gp * GasPool , qp * QuotaPool ) (* ExecutionResult , error ) {
193193 cvm .SetTxContext (NewCVMTxContext (msg ))
194- return NewStateTransition (cvm , msg , gp , qp ).execute ()
194+ return newStateTransition (cvm , msg , gp , qp ).execute ()
195195}
196196
197197// to returns the recipient of the message.
198- func (st * StateTransition ) to () common.Address {
198+ func (st * stateTransition ) to () common.Address {
199199 if st .msg == nil || st .msg .To == nil /* contract creation */ {
200200 return common.Address {}
201201 }
202202 return * st .msg .To
203203}
204204
205- //func (st *StateTransition ) useGas(amount uint64) error {
205+ //func (st *stateTransition ) useGas(amount uint64) error {
206206// if st.gasRemaining < amount {
207207// return vm.ErrOutOfGas
208208// }
@@ -211,7 +211,7 @@ func (st *StateTransition) to() common.Address {
211211// return nil
212212//}
213213
214- func (st * StateTransition ) buyGas () error {
214+ func (st * stateTransition ) buyGas () error {
215215 mgval := new (big.Int ).Mul (new (big.Int ).SetUint64 (st .msg .GasLimit ), st .msg .GasPrice )
216216 if have , want := st .state .GetBalance (st .msg .From ), mgval ; have .Cmp (want ) < 0 {
217217 return fmt .Errorf ("%w: address %v have %v want %v gas %v price %v" , errInsufficientBalanceForGas , st .msg .From .Hex (), have , want , st .msg .GasLimit , st .msg .GasPrice )
@@ -227,16 +227,17 @@ func (st *StateTransition) buyGas() error {
227227}
228228
229229// var confirmTime = params.CONFIRM_TIME * time.Second //-3600 * 24 * 30 * time.Second
230- func (st * StateTransition ) preCheck () error {
230+ func (st * stateTransition ) preCheck () error {
231231 // Make sure this transaction's nonce is correct.
232- if ! st .msg .SkipAccountChecks {
233- stNonce := st .state .GetNonce (st .msg .From )
234- if msgNonce := st .msg .Nonce ; stNonce < msgNonce {
235- return fmt .Errorf ("%w: address %v, tx: %d state: %d" , ErrNonceTooHigh , st .msg .From .Hex (), msgNonce , stNonce )
232+ msg := st .msg
233+ if ! msg .SkipNonceChecks {
234+ stNonce := st .state .GetNonce (msg .From )
235+ if msgNonce := msg .Nonce ; stNonce < msgNonce {
236+ return fmt .Errorf ("%w: address %v, tx: %d state: %d" , ErrNonceTooHigh , msg .From .Hex (), msgNonce , stNonce )
236237 } else if stNonce > msgNonce {
237- return fmt .Errorf ("%w: address %v, tx: %d state: %d" , ErrNonceTooLow , st . msg .From .Hex (), msgNonce , stNonce )
238+ return fmt .Errorf ("%w: address %v, tx: %d state: %d" , ErrNonceTooLow , msg .From .Hex (), msgNonce , stNonce )
238239 } else if stNonce + 1 < stNonce {
239- return fmt .Errorf ("%w: address %v, nonce: %d" , ErrNonceMax , st . msg .From .Hex (), stNonce )
240+ return fmt .Errorf ("%w: address %v, nonce: %d" , ErrNonceMax , msg .From .Hex (), stNonce )
240241 }
241242 }
242243
@@ -249,7 +250,7 @@ func (st *StateTransition) preCheck() error {
249250
250251/*const interv = 5
251252
252- func (st *StateTransition ) TorrentSync(meta common.Address, dir string, errCh chan error) {
253+ func (st *stateTransition ) TorrentSync(meta common.Address, dir string, errCh chan error) {
253254 street := big.NewInt(0).Sub(st.cvm.PeekNumber, st.cvm.BlockNumber)
254255 point := big.NewInt(time.Now().Add(confirmTime).Unix())
255256 if point.Cmp(st.cvm.Context.Time) > 0 || street.Cmp(big.NewInt(params.CONFIRM_BLOCKS)) > 0 {
@@ -292,7 +293,7 @@ func (st *StateTransition) TorrentSync(meta common.Address, dir string, errCh ch
292293// execute will transition the state by applying the current message and
293294// returning the result including the used gas. It returns an error if failed.
294295// An error indicates a consensus issue.
295- func (st * StateTransition ) execute () (* ExecutionResult , error ) {
296+ func (st * stateTransition ) execute () (* ExecutionResult , error ) {
296297 if err := st .preCheck (); err != nil {
297298 return nil , err
298299 }
@@ -416,11 +417,11 @@ func (st *StateTransition) execute() (*ExecutionResult, error) {
416417}
417418
418419// vote to model
419- func (st * StateTransition ) uploading () bool {
420+ func (st * stateTransition ) uploading () bool {
420421 return st .msg != nil && st .msg .To != nil && st .msg .Value .Sign () == 0 && st .state .Uploading (st .to ()) // && st.gasRemaining >= params.UploadGas
421422}
422423
423- func (st * StateTransition ) refundGas () uint64 {
424+ func (st * stateTransition ) refundGas () uint64 {
424425 // Apply refund counter, capped to half of the used gas.
425426 refund := st .gasUsed () / 2
426427 if refund > st .state .GetRefund () {
@@ -440,6 +441,6 @@ func (st *StateTransition) refundGas() uint64 {
440441}
441442
442443// gasUsed returns the amount of gas used up by the state transition.
443- func (st * StateTransition ) gasUsed () uint64 {
444+ func (st * stateTransition ) gasUsed () uint64 {
444445 return st .initialGas - st .gasRemaining
445446}
0 commit comments