Fixed consensus issue for refunding
* Refund should _always_ go to the origin
This commit is contained in:
parent
a1c830cd3c
commit
e235b57234
@ -48,9 +48,8 @@ type BlockProcessor struct {
|
||||
|
||||
func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
||||
sm := &BlockProcessor{
|
||||
db: db,
|
||||
mem: make(map[string]*big.Int),
|
||||
//Pow: ðash.Ethash{},
|
||||
db: db,
|
||||
mem: make(map[string]*big.Int),
|
||||
Pow: ezp.New(),
|
||||
bc: chainManager,
|
||||
eventMux: eventMux,
|
||||
@ -100,7 +99,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
|
||||
// Notify all subscribers
|
||||
if !transientProcess {
|
||||
go self.eventMux.Post(TxPostEvent{tx})
|
||||
go self.eventMux.Post(statedb.Logs())
|
||||
logs := statedb.Logs()
|
||||
go self.eventMux.Post(logs)
|
||||
}
|
||||
|
||||
return receipt, txGas, err
|
||||
|
@ -126,7 +126,7 @@ func (self *StateTransition) BuyGas() error {
|
||||
|
||||
self.AddGas(self.msg.Gas())
|
||||
self.initialGas.Set(self.msg.Gas())
|
||||
sender.SubAmount(MessageGasValue(self.msg))
|
||||
sender.SubBalance(MessageGasValue(self.msg))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -251,13 +251,16 @@ func (self *StateTransition) RefundGas() {
|
||||
coinbase, sender := self.Coinbase(), self.From()
|
||||
// Return remaining gas
|
||||
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
|
||||
sender.AddAmount(remaining)
|
||||
fmt.Println("REFUND:", remaining)
|
||||
sender.AddBalance(remaining)
|
||||
|
||||
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
|
||||
for addr, ref := range self.state.Refunds() {
|
||||
refund := ethutil.BigMin(uhalf, ref)
|
||||
self.gas.Add(self.gas, refund)
|
||||
self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
|
||||
addToIt := refund.Mul(refund, self.msg.GasPrice())
|
||||
fmt.Println("ADD TO IT", addToIt)
|
||||
self.state.AddBalance([]byte(addr), addToIt)
|
||||
}
|
||||
|
||||
coinbase.RefundGas(self.gas, self.msg.GasPrice())
|
||||
|
@ -197,7 +197,7 @@ gasLimit:
|
||||
}
|
||||
self.eth.TxPool().RemoveSet(remove)
|
||||
|
||||
self.current.coinbase.AddAmount(core.BlockReward)
|
||||
self.current.coinbase.AddBalance(core.BlockReward)
|
||||
|
||||
self.current.state.Update(ethutil.Big0)
|
||||
self.push()
|
||||
@ -225,7 +225,7 @@ func (self *worker) commitUncle(uncle *types.Header) error {
|
||||
}
|
||||
|
||||
uncleAccount := self.current.state.GetAccount(uncle.Coinbase)
|
||||
uncleAccount.AddAmount(uncleReward)
|
||||
uncleAccount.AddBalance(uncleReward)
|
||||
|
||||
self.current.coinbase.AddBalance(uncleReward)
|
||||
|
||||
|
@ -35,7 +35,7 @@ func (self *StateDB) Dump() []byte {
|
||||
|
||||
storageIt := stateObject.State.trie.Iterator()
|
||||
for storageIt.Next() {
|
||||
account.Storage[ethutil.Bytes2Hex(it.Key)] = ethutil.Bytes2Hex(it.Value)
|
||||
account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value)
|
||||
}
|
||||
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
||||
}
|
||||
|
@ -19,6 +19,14 @@ func (self Code) String() string {
|
||||
|
||||
type Storage map[string]*ethutil.Value
|
||||
|
||||
func (self Storage) String() (str string) {
|
||||
for key, value := range self {
|
||||
str += fmt.Sprintf("%X : %X\n", key, value.Bytes())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (self Storage) Copy() Storage {
|
||||
cpy := make(Storage)
|
||||
for key, value := range self {
|
||||
@ -119,10 +127,9 @@ func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value {
|
||||
}
|
||||
func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
|
||||
self.SetState(key.Bytes(), value)
|
||||
self.dirty = true
|
||||
}
|
||||
|
||||
func (self *StateObject) Storage() map[string]*ethutil.Value {
|
||||
func (self *StateObject) Storage() Storage {
|
||||
return self.storage
|
||||
}
|
||||
|
||||
@ -172,20 +179,22 @@ func (c *StateObject) AddBalance(amount *big.Int) {
|
||||
|
||||
statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount)
|
||||
}
|
||||
func (c *StateObject) AddAmount(amount *big.Int) { c.AddBalance(amount) }
|
||||
|
||||
func (c *StateObject) SubBalance(amount *big.Int) {
|
||||
c.SetBalance(new(big.Int).Sub(c.balance, amount))
|
||||
|
||||
statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount)
|
||||
}
|
||||
func (c *StateObject) SubAmount(amount *big.Int) { c.SubBalance(amount) }
|
||||
|
||||
func (c *StateObject) SetBalance(amount *big.Int) {
|
||||
c.balance = amount
|
||||
c.dirty = true
|
||||
}
|
||||
|
||||
func (c *StateObject) St() Storage {
|
||||
return c.storage
|
||||
}
|
||||
|
||||
//
|
||||
// Gas setters and getters
|
||||
//
|
||||
@ -198,7 +207,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
|
||||
return fmt.Errorf("insufficient amount: %v, %v", c.balance, total)
|
||||
}
|
||||
|
||||
c.SubAmount(total)
|
||||
c.SubBalance(total)
|
||||
|
||||
c.dirty = true
|
||||
|
||||
@ -221,7 +230,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
|
||||
rGas := new(big.Int).Set(gas)
|
||||
rGas.Mul(rGas, price)
|
||||
|
||||
self.AddAmount(rGas)
|
||||
self.AddBalance(rGas)
|
||||
|
||||
self.dirty = true
|
||||
|
||||
|
5
vm/vm.go
5
vm/vm.go
@ -664,6 +664,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
||||
}
|
||||
addr = ref.Address()
|
||||
|
||||
fmt.Printf("CREATE %X\n", addr)
|
||||
stack.Push(ethutil.BigD(addr))
|
||||
|
||||
}
|
||||
@ -727,7 +728,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
||||
|
||||
self.Printf(" => (%x) %v", receiver.Address()[:4], balance)
|
||||
|
||||
receiver.AddAmount(balance)
|
||||
receiver.AddBalance(balance)
|
||||
statedb.Delete(context.Address())
|
||||
|
||||
fallthrough
|
||||
@ -828,7 +829,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
|
||||
// 0 => non 0
|
||||
mult = ethutil.Big3
|
||||
} else if len(val) > 0 && len(y.Bytes()) == 0 {
|
||||
statedb.Refund(caller.Address(), GasSStoreRefund)
|
||||
statedb.Refund(self.env.Origin(), GasSStoreRefund)
|
||||
|
||||
mult = ethutil.Big0
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user