From 00787fe7818b7baaa95ef7928b5101df2d052dce Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Mon, 11 Jul 2016 11:58:10 +0200 Subject: [PATCH] core: added CheckNonce() to Message interface --- accounts/abi/bind/backends/simulated.go | 3 ++- common/registrar/ethreg/api.go | 5 ++++- core/state_transition.go | 7 +++++-- core/types/transaction.go | 1 + eth/api.go | 4 ++-- internal/ethapi/api.go | 4 ++-- tests/util.go | 1 + 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 490da82a6..9bce3f988 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -203,7 +203,8 @@ type callmsg struct { func (m callmsg) From() (common.Address, error) { return m.from.Address(), nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil } -func (m callmsg) Nonce() uint64 { return m.from.Nonce() } +func (m callmsg) Nonce() uint64 { return 0 } +func (m callmsg) CheckNonce() bool { return false } func (m callmsg) To() *common.Address { return m.to } func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) Gas() *big.Int { return m.gasLimit } diff --git a/common/registrar/ethreg/api.go b/common/registrar/ethreg/api.go index 6d77a9385..6dd0ef46f 100644 --- a/common/registrar/ethreg/api.go +++ b/common/registrar/ethreg/api.go @@ -128,7 +128,10 @@ func (m callmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil } func (m callmsg) Nonce() uint64 { - return m.from.Nonce() + return 0 +} +func (m callmsg) CheckNonce() bool { + return false } func (m callmsg) To() *common.Address { return m.to diff --git a/core/state_transition.go b/core/state_transition.go index c8160424b..9e6b2f567 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -71,6 +71,7 @@ type Message interface { Value() *big.Int Nonce() uint64 + CheckNonce() bool Data() []byte } @@ -208,8 +209,10 @@ func (self *StateTransition) preCheck() (err error) { } // Make sure this transaction's nonce is correct - if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() { - return NonceError(msg.Nonce(), n) + if msg.CheckNonce() { + if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() { + return NonceError(msg.Nonce(), n) + } } // Pre-pay gas diff --git a/core/types/transaction.go b/core/types/transaction.go index b99d3a716..c71c98aa7 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -113,6 +113,7 @@ func (tx *Transaction) Gas() *big.Int { return new(big.Int).Set(tx.data.Gas func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) } func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) } func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce } +func (tx *Transaction) CheckNonce() bool { return true } func (tx *Transaction) To() *common.Address { if tx.data.Recipient == nil { diff --git a/eth/api.go b/eth/api.go index 74a815100..3b7abb69a 100644 --- a/eth/api.go +++ b/eth/api.go @@ -424,7 +424,6 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config *vm.Config) (b // callmsg is the message type used for call transations. type callmsg struct { addr common.Address - nonce uint64 to *common.Address gas, gasPrice *big.Int value *big.Int @@ -434,7 +433,8 @@ type callmsg struct { // accessor boilerplate to implement core.Message func (m callmsg) From() (common.Address, error) { return m.addr, nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil } -func (m callmsg) Nonce() uint64 { return m.nonce } +func (m callmsg) Nonce() uint64 { return 0 } +func (m callmsg) CheckNonce() bool { return false } func (m callmsg) To() *common.Address { return m.to } func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) Gas() *big.Int { return m.gas } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6e888fc93..f604a0ef2 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -534,7 +534,6 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A // callmsg is the message type used for call transations. type callmsg struct { addr common.Address - nonce uint64 to *common.Address gas, gasPrice *big.Int value *big.Int @@ -544,7 +543,8 @@ type callmsg struct { // accessor boilerplate to implement core.Message func (m callmsg) From() (common.Address, error) { return m.addr, nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil } -func (m callmsg) Nonce() uint64 { return m.nonce } +func (m callmsg) Nonce() uint64 { return 0 } +func (m callmsg) CheckNonce() bool { return false } func (m callmsg) To() *common.Address { return m.to } func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) Gas() *big.Int { return m.gas } diff --git a/tests/util.go b/tests/util.go index abc67769d..877e1acdb 100644 --- a/tests/util.go +++ b/tests/util.go @@ -312,4 +312,5 @@ func (self Message) GasPrice() *big.Int { return self.price } func (self Message) Gas() *big.Int { return self.gas } func (self Message) Value() *big.Int { return self.value } func (self Message) Nonce() uint64 { return self.nonce } +func (self Message) CheckNonce() bool { return true } func (self Message) Data() []byte { return self.data }