aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-11-14 20:43:22 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2016-11-14 21:16:06 +0800
commitb10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5 (patch)
tree9acc32d1edca04b8a2b2894b3177f31c78f8298f
parentd8e2e9a41fa0283c8e757a6149c0257d2f8a1ad9 (diff)
downloaddexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar.gz
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar.bz2
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar.lz
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar.xz
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.tar.zst
dexon-b10bcd924ba79f9faa5b8f2d273a7ee02d7b89f5.zip
core/types: turn off nonce checking for Call messages
-rw-r--r--common/registrar/ethreg/api.go2
-rw-r--r--core/types/transaction.go33
-rw-r--r--internal/ethapi/api.go2
-rw-r--r--les/odr_test.go4
-rw-r--r--light/odr_test.go4
-rw-r--r--tests/state_test_util.go2
6 files changed, 25 insertions, 22 deletions
diff --git a/common/registrar/ethreg/api.go b/common/registrar/ethreg/api.go
index a3c48345e..a32653554 100644
--- a/common/registrar/ethreg/api.go
+++ b/common/registrar/ethreg/api.go
@@ -187,7 +187,7 @@ func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr
if gasPrice.BitLen() == 0 {
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
}
- msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr))
+ msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr), false)
header := be.bc.CurrentBlock().Header()
vmenv := core.NewEnv(statedb, be.config, be.bc, msg, header, vm.Config{})
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 972a36706..323bfaee6 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -321,12 +321,13 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int, err er
// XXX Rename message to something less arbitrary?
func (tx *Transaction) AsMessage(s Signer) (Message, error) {
msg := Message{
- nonce: tx.data.AccountNonce,
- price: new(big.Int).Set(tx.data.Price),
- gasLimit: new(big.Int).Set(tx.data.GasLimit),
- to: tx.data.Recipient,
- amount: tx.data.Amount,
- data: tx.data.Payload,
+ nonce: tx.data.AccountNonce,
+ price: new(big.Int).Set(tx.data.Price),
+ gasLimit: new(big.Int).Set(tx.data.GasLimit),
+ to: tx.data.Recipient,
+ amount: tx.data.Amount,
+ data: tx.data.Payload,
+ checkNonce: true,
}
var err error
@@ -535,17 +536,19 @@ type Message struct {
nonce uint64
amount, price, gasLimit *big.Int
data []byte
+ checkNonce bool
}
-func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, gasLimit, price *big.Int, data []byte) Message {
+func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, gasLimit, price *big.Int, data []byte, checkNonce bool) Message {
return Message{
- from: from,
- to: to,
- nonce: nonce,
- amount: amount,
- price: price,
- gasLimit: gasLimit,
- data: data,
+ from: from,
+ to: to,
+ nonce: nonce,
+ amount: amount,
+ price: price,
+ gasLimit: gasLimit,
+ data: data,
+ checkNonce: checkNonce,
}
}
@@ -556,4 +559,4 @@ func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() *big.Int { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
-func (m Message) CheckNonce() bool { return true }
+func (m Message) CheckNonce() bool { return m.checkNonce }
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 0e4dd4524..a25eff5ed 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -545,7 +545,7 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr
if gasPrice.Cmp(common.Big0) == 0 {
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
}
- msg := types.NewMessage(addr, args.To, 0, args.Value.BigInt(), gas, gasPrice, common.FromHex(args.Data))
+ msg := types.NewMessage(addr, args.To, 0, args.Value.BigInt(), gas, gasPrice, common.FromHex(args.Data), false)
// Execute the call and return
vmenv, vmError, err := s.b.GetVMEnv(ctx, msg, state, header)
diff --git a/les/odr_test.go b/les/odr_test.go
index f1fa59ad8..80f7b8208 100644
--- a/les/odr_test.go
+++ b/les/odr_test.go
@@ -119,7 +119,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
from := statedb.GetOrNewStateObject(testBankAddress)
from.SetBalance(common.MaxBig)
- msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)}
+ msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{})
gp := new(core.GasPool).AddGas(common.MaxBig)
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
@@ -132,7 +132,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
if err == nil {
from.SetBalance(common.MaxBig)
- msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)}
+ msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
vmenv := light.NewEnv(ctx, state, config, lc, msg, header, vm.Config{})
gp := new(core.GasPool).AddGas(common.MaxBig)
diff --git a/light/odr_test.go b/light/odr_test.go
index 1f6bcaeb1..50255a7f3 100644
--- a/light/odr_test.go
+++ b/light/odr_test.go
@@ -167,7 +167,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
from := statedb.GetOrNewStateObject(testBankAddress)
from.SetBalance(common.MaxBig)
- msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data)}
+ msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)}
vmenv := core.NewEnv(statedb, testChainConfig(), bc, msg, header, vm.Config{})
gp := new(core.GasPool).AddGas(common.MaxBig)
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
@@ -180,7 +180,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
if err == nil {
from.SetBalance(common.MaxBig)
- msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data)}
+ msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)}
vmenv := NewEnv(ctx, state, testChainConfig(), lc, msg, header, vm.Config{})
gp := new(core.GasPool).AddGas(common.MaxBig)
ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index c08398321..01998c2a4 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -226,7 +226,7 @@ func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx m
key, _ := hex.DecodeString(tx["secretKey"])
addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
- message := types.NewMessage(addr, to, nonce, value, gas, price, data)
+ message := types.NewMessage(addr, to, nonce, value, gas, price, data, true)
vmenv := NewEnvFromMap(chainConfig, statedb, env, tx)
vmenv.origin = addr