mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-26 05:17:19 +00:00
Moved on to the state manager
This commit is contained in:
parent
54bcee512d
commit
b15a4985e8
@ -62,6 +62,7 @@ func NewStateManager(ethereum EthManager) *StateManager {
|
|||||||
addrStateStore: NewAddrStateStore(),
|
addrStateStore: NewAddrStateStore(),
|
||||||
bc: ethereum.BlockChain(),
|
bc: ethereum.BlockChain(),
|
||||||
}
|
}
|
||||||
|
sm.procState = ethereum.BlockChain().CurrentBlock.State()
|
||||||
|
|
||||||
return sm
|
return sm
|
||||||
}
|
}
|
||||||
@ -72,8 +73,8 @@ func (sm *StateManager) ProcState() *State {
|
|||||||
|
|
||||||
// Watches any given address and puts it in the address state store
|
// Watches any given address and puts it in the address state store
|
||||||
func (sm *StateManager) WatchAddr(addr []byte) *AccountState {
|
func (sm *StateManager) WatchAddr(addr []byte) *AccountState {
|
||||||
//FIXME account := sm.procState.GetAccount(addr)
|
//XXX account := sm.bc.CurrentBlock.state.GetAccount(addr)
|
||||||
account := sm.bc.CurrentBlock.state.GetAccount(addr)
|
account := sm.procState.GetAccount(addr)
|
||||||
|
|
||||||
return sm.addrStateStore.Add(addr, account)
|
return sm.addrStateStore.Add(addr, account)
|
||||||
}
|
}
|
||||||
@ -104,16 +105,16 @@ func (sm *StateManager) ApplyTransactions(block *Block, txs []*Transaction) {
|
|||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
// If there's no recipient, it's a contract
|
// If there's no recipient, it's a contract
|
||||||
if tx.IsContract() {
|
if tx.IsContract() {
|
||||||
//FIXME sm.MakeContract(tx)
|
sm.MakeContract(tx)
|
||||||
block.MakeContract(tx)
|
//XXX block.MakeContract(tx)
|
||||||
} else {
|
} else {
|
||||||
//FIXME if contract := procState.GetContract(tx.Recipient); contract != nil {
|
if contract := sm.procState.GetContract(tx.Recipient); contract != nil {
|
||||||
if contract := block.state.GetContract(tx.Recipient); contract != nil {
|
//XXX if contract := block.state.GetContract(tx.Recipient); contract != nil {
|
||||||
sm.ProcessContract(contract, tx, block)
|
sm.ProcessContract(contract, tx, block)
|
||||||
} else {
|
} else {
|
||||||
err := sm.Ethereum.TxPool().ProcessTransaction(tx, block)
|
err := sm.Ethereum.TxPool().ProcessTransaction(tx, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethutil.Config.Log.Infoln("[smGR]", err)
|
ethutil.Config.Log.Infoln("[STATE]", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,21 +166,21 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
|
|||||||
|
|
||||||
// I'm not sure, but I don't know if there should be thrown
|
// I'm not sure, but I don't know if there should be thrown
|
||||||
// any errors at this time.
|
// any errors at this time.
|
||||||
if err := sm.AccumelateRewards(sm.bc.CurrentBlock, block); err != nil {
|
if err := sm.AccumelateRewards(block); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if !sm.compState.Cmp(sm.procState)
|
// if !sm.compState.Cmp(sm.procState)
|
||||||
if !block.state.Cmp(sm.bc.CurrentBlock.state) {
|
if !sm.compState.Cmp(sm.procState) {
|
||||||
return fmt.Errorf("Invalid merkle root. Expected %x, got %x", block.State().trie.Root, sm.bc.CurrentBlock.State().trie.Root)
|
//XXX return fmt.Errorf("Invalid merkle root. Expected %x, got %x", block.State().trie.Root, sm.bc.CurrentBlock.State().trie.Root)
|
||||||
//FIXME return fmt.Errorf("Invalid merkle root. Expected %x, got %x", sm.compState.trie.Root, sm.procState.trie.Root)
|
return fmt.Errorf("Invalid merkle root. Expected %x, got %x", sm.compState.trie.Root, sm.procState.trie.Root)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the new total difficulty and sync back to the db
|
// Calculate the new total difficulty and sync back to the db
|
||||||
if sm.CalculateTD(block) {
|
if sm.CalculateTD(block) {
|
||||||
// Sync the current block's state to the database and cancelling out the deferred Undo
|
// Sync the current block's state to the database and cancelling out the deferred Undo
|
||||||
sm.bc.CurrentBlock.Sync()
|
//XXX sm.bc.CurrentBlock.Sync()
|
||||||
//FIXME sm.procState.Sync()
|
sm.procState.Sync()
|
||||||
|
|
||||||
// Broadcast the valid block back to the wire
|
// Broadcast the valid block back to the wire
|
||||||
//sm.Ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val})
|
//sm.Ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val})
|
||||||
@ -193,7 +194,7 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
|
|||||||
sm.SecondaryBlockProcessor.ProcessBlock(block)
|
sm.SecondaryBlockProcessor.ProcessBlock(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
ethutil.Config.Log.Infof("[smGR] Added block #%d (%x)\n", block.BlockInfo().Number, block.Hash())
|
ethutil.Config.Log.Infof("[STATE] Added block #%d (%x)\n", block.BlockInfo().Number, block.Hash())
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("total diff failed")
|
fmt.Println("total diff failed")
|
||||||
}
|
}
|
||||||
@ -270,22 +271,22 @@ func CalculateUncleReward(block *Block) *big.Int {
|
|||||||
return UncleReward
|
return UncleReward
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) AccumelateRewards(processor *Block, block *Block) error {
|
func (sm *StateManager) AccumelateRewards(block *Block) error {
|
||||||
// Get the coinbase rlp data
|
// Get the coinbase rlp data
|
||||||
addr := processor.state.GetAccount(block.Coinbase)
|
//XXX addr := processor.state.GetAccount(block.Coinbase)
|
||||||
//FIXME addr := proc.GetAccount(block.Coinbase)
|
addr := sm.procState.GetAccount(block.Coinbase)
|
||||||
// Reward amount of ether to the coinbase address
|
// Reward amount of ether to the coinbase address
|
||||||
addr.AddFee(CalculateBlockReward(block, len(block.Uncles)))
|
addr.AddFee(CalculateBlockReward(block, len(block.Uncles)))
|
||||||
|
|
||||||
processor.state.UpdateAccount(block.Coinbase, addr)
|
//XXX processor.state.UpdateAccount(block.Coinbase, addr)
|
||||||
//FIXME proc.UpdateAccount(block.Coinbase, addr)
|
sm.procState.UpdateAccount(block.Coinbase, addr)
|
||||||
|
|
||||||
for _, uncle := range block.Uncles {
|
for _, uncle := range block.Uncles {
|
||||||
uncleAddr := processor.state.GetAccount(uncle.Coinbase)
|
uncleAddr := sm.procState.GetAccount(uncle.Coinbase)
|
||||||
uncleAddr.AddFee(CalculateUncleReward(uncle))
|
uncleAddr.AddFee(CalculateUncleReward(uncle))
|
||||||
|
|
||||||
processor.state.UpdateAccount(uncle.Coinbase, uncleAddr)
|
//processor.state.UpdateAccount(uncle.Coinbase, uncleAddr)
|
||||||
//FIXME proc.UpdateAccount(uncle.Coinbase, uncleAddr)
|
sm.procState.UpdateAccount(uncle.Coinbase, uncleAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -306,8 +307,8 @@ func (sm *StateManager) ProcessContract(contract *Contract, tx *Transaction, blo
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
vm := &Vm{}
|
vm := &Vm{}
|
||||||
//vm.Process(contract, sm.procState, RuntimeVars{
|
//vm.Process(contract, block.state, RuntimeVars{
|
||||||
vm.Process(contract, block.state, RuntimeVars{
|
vm.Process(contract, sm.procState, RuntimeVars{
|
||||||
address: tx.Hash()[12:],
|
address: tx.Hash()[12:],
|
||||||
blockNumber: block.BlockInfo().Number,
|
blockNumber: block.BlockInfo().Number,
|
||||||
sender: tx.Sender(),
|
sender: tx.Sender(),
|
||||||
|
@ -233,11 +233,11 @@ func (pool *TxPool) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pool *TxPool) Stop() {
|
func (pool *TxPool) Stop() {
|
||||||
log.Println("[TXP] Stopping...")
|
|
||||||
|
|
||||||
close(pool.quit)
|
close(pool.quit)
|
||||||
|
|
||||||
pool.Flush()
|
pool.Flush()
|
||||||
|
|
||||||
|
log.Println("[TXP] Stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *TxPool) Subscribe(channel chan TxMsg) {
|
func (pool *TxPool) Subscribe(channel chan TxMsg) {
|
||||||
|
3
peer.go
3
peer.go
@ -293,7 +293,8 @@ func (p *Peer) HandleInbound() {
|
|||||||
var err error
|
var err error
|
||||||
for i := msg.Data.Len() - 1; i >= 0; i-- {
|
for i := msg.Data.Len() - 1; i >= 0; i-- {
|
||||||
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
|
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
|
||||||
// FIXME p.ethereum.BlockManager.DefaultPrepare(block)
|
|
||||||
|
p.ethereum.StateManager().PrepareDefault(block)
|
||||||
err = p.ethereum.StateManager().ProcessBlock(block)
|
err = p.ethereum.StateManager().ProcessBlock(block)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user