Skip to content

Increment sender nonce even if we are ignoring a private transaction #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,38 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
if err = self.preCheck(); err != nil {
return
}
msg := self.msg
sender, _ := self.from() // err checked in preCheck

var data []byte
var (
msg = self.msg
sender, _ = self.from() // err checked in preCheck
contractCreation = MessageCreatesContract(msg)
vmenv = self.env
state = vmenv.Db()
data []byte
isPrivate bool
)
if env, ok := vmenv.(DualStateEnv); ok {
state = env.PublicState()
}
if tx, ok := msg.(*types.Transaction); ok && tx.IsPrivate() {
isPrivate = true
data, err = private.P.Receive(self.data)
if err != nil {
if !contractCreation {
// Increment the nonce even if we are ignoring this transaction
state.SetNonce(sender.Address(), state.GetNonce(sender.Address())+1)
}
return nil, nil, nil, err
}
} else {
data = self.data
}

homestead := self.env.RuleSet().IsHomestead(self.env.BlockNumber())
contractCreation := MessageCreatesContract(msg)
// Pay intrinsic gas
if err = self.useGas(IntrinsicGas(data, contractCreation, homestead)); err != nil {
return nil, nil, nil, InvalidTxError(err)
}

vmenv := self.env
//var addr common.Address
if contractCreation {
ret, _, err = vmenv.Create(sender, data, self.gas, self.gasPrice, self.value)
Expand All @@ -266,10 +277,6 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
glog.V(logger.Core).Infoln("VM create err:", err)
}
} else {
state := vmenv.Db()
if env, ok := vmenv.(DualStateEnv); ok {
state = env.PublicState()
}
// Increment the nonce for the next transaction
state.SetNonce(sender.Address(), state.GetNonce(sender.Address())+1)
ret, err = vmenv.Call(sender, self.to().Address(), data, self.gas, self.gasPrice, self.value)
Expand All @@ -292,6 +299,9 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
self.refundGas()
self.state.AddBalance(self.env.Coinbase(), new(big.Int).Mul(self.gasUsed(), self.gasPrice))

if isPrivate {
return ret, new(big.Int), new(big.Int), err
}
return ret, requiredGas, self.gasUsed(), err
}

Expand Down