mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 20:47:16 +00:00
wip
This commit is contained in:
parent
a1c830cd3c
commit
37e6870f64
@ -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
|
||||
@ -205,6 +205,8 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
|
||||
receiptSha := types.DeriveSha(receipts)
|
||||
if bytes.Compare(receiptSha, header.ReceiptHash) != 0 {
|
||||
fmt.Println("receipts", receipts)
|
||||
state.Sync()
|
||||
chainlogger.Infof("%s\n", state.Dump())
|
||||
err = fmt.Errorf("validating receipt root. received=%x got=%x", header.ReceiptHash, receiptSha)
|
||||
return
|
||||
}
|
||||
|
@ -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,7 +251,7 @@ 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)
|
||||
sender.AddBalance(remaining)
|
||||
|
||||
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
|
||||
for addr, ref := range self.state.Refunds() {
|
||||
|
@ -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
|
||||
|
||||
|
4
vm/vm.go
4
vm/vm.go
@ -54,6 +54,8 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
||||
|
||||
err = fmt.Errorf("%v", r)
|
||||
|
||||
} else {
|
||||
fmt.Println(me.(*state.StateObject).Storage())
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -727,7 +729,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
|
||||
|
Loading…
Reference in New Issue
Block a user