Skip to content

Commit

Permalink
Merge pull request ethereum#2799 from zsfelfoldi/api-nonce-fix2
Browse files Browse the repository at this point in the history
core: added CheckNonce() to Message interface
  • Loading branch information
karalabe authored Jul 12, 2016
2 parents 68b48cc + 00787fe commit f970610
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 4 additions & 1 deletion common/registrar/ethreg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Message interface {
Value() *big.Int

Nonce() uint64
CheckNonce() bool
Data() []byte
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit f970610

Please sign in to comment.