Skip to content

Commit b10bcd9

Browse files
committed
core/types: turn off nonce checking for Call messages
1 parent d8e2e9a commit b10bcd9

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

common/registrar/ethreg/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr
187187
if gasPrice.BitLen() == 0 {
188188
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
189189
}
190-
msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr))
190+
msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr), false)
191191

192192
header := be.bc.CurrentBlock().Header()
193193
vmenv := core.NewEnv(statedb, be.config, be.bc, msg, header, vm.Config{})

core/types/transaction.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,13 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int, err er
321321
// XXX Rename message to something less arbitrary?
322322
func (tx *Transaction) AsMessage(s Signer) (Message, error) {
323323
msg := Message{
324-
nonce: tx.data.AccountNonce,
325-
price: new(big.Int).Set(tx.data.Price),
326-
gasLimit: new(big.Int).Set(tx.data.GasLimit),
327-
to: tx.data.Recipient,
328-
amount: tx.data.Amount,
329-
data: tx.data.Payload,
324+
nonce: tx.data.AccountNonce,
325+
price: new(big.Int).Set(tx.data.Price),
326+
gasLimit: new(big.Int).Set(tx.data.GasLimit),
327+
to: tx.data.Recipient,
328+
amount: tx.data.Amount,
329+
data: tx.data.Payload,
330+
checkNonce: true,
330331
}
331332

332333
var err error
@@ -535,17 +536,19 @@ type Message struct {
535536
nonce uint64
536537
amount, price, gasLimit *big.Int
537538
data []byte
539+
checkNonce bool
538540
}
539541

540-
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, gasLimit, price *big.Int, data []byte) Message {
542+
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, gasLimit, price *big.Int, data []byte, checkNonce bool) Message {
541543
return Message{
542-
from: from,
543-
to: to,
544-
nonce: nonce,
545-
amount: amount,
546-
price: price,
547-
gasLimit: gasLimit,
548-
data: data,
544+
from: from,
545+
to: to,
546+
nonce: nonce,
547+
amount: amount,
548+
price: price,
549+
gasLimit: gasLimit,
550+
data: data,
551+
checkNonce: checkNonce,
549552
}
550553
}
551554

@@ -556,4 +559,4 @@ func (m Message) Value() *big.Int { return m.amount }
556559
func (m Message) Gas() *big.Int { return m.gasLimit }
557560
func (m Message) Nonce() uint64 { return m.nonce }
558561
func (m Message) Data() []byte { return m.data }
559-
func (m Message) CheckNonce() bool { return true }
562+
func (m Message) CheckNonce() bool { return m.checkNonce }

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr
545545
if gasPrice.Cmp(common.Big0) == 0 {
546546
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
547547
}
548-
msg := types.NewMessage(addr, args.To, 0, args.Value.BigInt(), gas, gasPrice, common.FromHex(args.Data))
548+
msg := types.NewMessage(addr, args.To, 0, args.Value.BigInt(), gas, gasPrice, common.FromHex(args.Data), false)
549549

550550
// Execute the call and return
551551
vmenv, vmError, err := s.b.GetVMEnv(ctx, msg, state, header)

les/odr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
119119
from := statedb.GetOrNewStateObject(testBankAddress)
120120
from.SetBalance(common.MaxBig)
121121

122-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)}
122+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
123123
vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{})
124124
gp := new(core.GasPool).AddGas(common.MaxBig)
125125
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
@@ -132,7 +132,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
132132
if err == nil {
133133
from.SetBalance(common.MaxBig)
134134

135-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)}
135+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
136136

137137
vmenv := light.NewEnv(ctx, state, config, lc, msg, header, vm.Config{})
138138
gp := new(core.GasPool).AddGas(common.MaxBig)

light/odr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
167167
from := statedb.GetOrNewStateObject(testBankAddress)
168168
from.SetBalance(common.MaxBig)
169169

170-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data)}
170+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)}
171171
vmenv := core.NewEnv(statedb, testChainConfig(), bc, msg, header, vm.Config{})
172172
gp := new(core.GasPool).AddGas(common.MaxBig)
173173
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
@@ -180,7 +180,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
180180
if err == nil {
181181
from.SetBalance(common.MaxBig)
182182

183-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data)}
183+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)}
184184
vmenv := NewEnv(ctx, state, testChainConfig(), lc, msg, header, vm.Config{})
185185
gp := new(core.GasPool).AddGas(common.MaxBig)
186186
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)

tests/state_test_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx m
226226

227227
key, _ := hex.DecodeString(tx["secretKey"])
228228
addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
229-
message := types.NewMessage(addr, to, nonce, value, gas, price, data)
229+
message := types.NewMessage(addr, to, nonce, value, gas, price, data, true)
230230
vmenv := NewEnvFromMap(chainConfig, statedb, env, tx)
231231
vmenv.origin = addr
232232

0 commit comments

Comments
 (0)