Skip to content

Commit f970610

Browse files
authored
Merge pull request ethereum#2799 from zsfelfoldi/api-nonce-fix2
core: added CheckNonce() to Message interface
2 parents 68b48cc + 00787fe commit f970610

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ type callmsg struct {
203203

204204
func (m callmsg) From() (common.Address, error) { return m.from.Address(), nil }
205205
func (m callmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil }
206-
func (m callmsg) Nonce() uint64 { return m.from.Nonce() }
206+
func (m callmsg) Nonce() uint64 { return 0 }
207+
func (m callmsg) CheckNonce() bool { return false }
207208
func (m callmsg) To() *common.Address { return m.to }
208209
func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
209210
func (m callmsg) Gas() *big.Int { return m.gasLimit }

common/registrar/ethreg/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ func (m callmsg) FromFrontier() (common.Address, error) {
128128
return m.from.Address(), nil
129129
}
130130
func (m callmsg) Nonce() uint64 {
131-
return m.from.Nonce()
131+
return 0
132+
}
133+
func (m callmsg) CheckNonce() bool {
134+
return false
132135
}
133136
func (m callmsg) To() *common.Address {
134137
return m.to

core/state_transition.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Message interface {
7171
Value() *big.Int
7272

7373
Nonce() uint64
74+
CheckNonce() bool
7475
Data() []byte
7576
}
7677

@@ -208,8 +209,10 @@ func (self *StateTransition) preCheck() (err error) {
208209
}
209210

210211
// Make sure this transaction's nonce is correct
211-
if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() {
212-
return NonceError(msg.Nonce(), n)
212+
if msg.CheckNonce() {
213+
if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() {
214+
return NonceError(msg.Nonce(), n)
215+
}
213216
}
214217

215218
// Pre-pay gas

core/types/transaction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (tx *Transaction) Gas() *big.Int { return new(big.Int).Set(tx.data.Gas
113113
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) }
114114
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
115115
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
116+
func (tx *Transaction) CheckNonce() bool { return true }
116117

117118
func (tx *Transaction) To() *common.Address {
118119
if tx.data.Recipient == nil {

eth/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config *vm.Config) (b
424424
// callmsg is the message type used for call transations.
425425
type callmsg struct {
426426
addr common.Address
427-
nonce uint64
428427
to *common.Address
429428
gas, gasPrice *big.Int
430429
value *big.Int
@@ -434,7 +433,8 @@ type callmsg struct {
434433
// accessor boilerplate to implement core.Message
435434
func (m callmsg) From() (common.Address, error) { return m.addr, nil }
436435
func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil }
437-
func (m callmsg) Nonce() uint64 { return m.nonce }
436+
func (m callmsg) Nonce() uint64 { return 0 }
437+
func (m callmsg) CheckNonce() bool { return false }
438438
func (m callmsg) To() *common.Address { return m.to }
439439
func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
440440
func (m callmsg) Gas() *big.Int { return m.gas }

internal/ethapi/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
534534
// callmsg is the message type used for call transations.
535535
type callmsg struct {
536536
addr common.Address
537-
nonce uint64
538537
to *common.Address
539538
gas, gasPrice *big.Int
540539
value *big.Int
@@ -544,7 +543,8 @@ type callmsg struct {
544543
// accessor boilerplate to implement core.Message
545544
func (m callmsg) From() (common.Address, error) { return m.addr, nil }
546545
func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil }
547-
func (m callmsg) Nonce() uint64 { return m.nonce }
546+
func (m callmsg) Nonce() uint64 { return 0 }
547+
func (m callmsg) CheckNonce() bool { return false }
548548
func (m callmsg) To() *common.Address { return m.to }
549549
func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
550550
func (m callmsg) Gas() *big.Int { return m.gas }

tests/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,5 @@ func (self Message) GasPrice() *big.Int { return self.price }
312312
func (self Message) Gas() *big.Int { return self.gas }
313313
func (self Message) Value() *big.Int { return self.value }
314314
func (self Message) Nonce() uint64 { return self.nonce }
315+
func (self Message) CheckNonce() bool { return true }
315316
func (self Message) Data() []byte { return self.data }

0 commit comments

Comments
 (0)