From 9008b155d3c8d2a32c4c8945f1174243d48d4e90 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 10:28:02 +0100 Subject: Renamed `chain` => `core` --- core/chain_manager.go | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 core/chain_manager.go (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go new file mode 100644 index 000000000..7acd171ec --- /dev/null +++ b/core/chain_manager.go @@ -0,0 +1,276 @@ +package core + +import ( + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/logger" +) + +var chainlogger = logger.NewLogger("CHAIN") + +func AddTestNetFunds(block *types.Block) { + for _, addr := range []string{ + "51ba59315b3a95761d0863b05ccc7a7f54703d99", + "e4157b34ea9615cfbde6b4fda419828124b70c78", + "b9c015918bdaba24b4ff057a92a3873d6eb201be", + "6c386a4b26f73c802f34673f7248bb118f97424a", + "cd2a3d9f938e13cd947ec05abc7fe734df8dd826", + "2ef47100e0787b915105fd5e3f4ff6752079d5cb", + "e6716f9544a56c530d868e4bfbacb172315bdead", + "1a26338f0d905e295fccb71fa9ea849ffa12aaf4", + } { + codedAddr := ethutil.Hex2Bytes(addr) + account := block.State().GetAccount(codedAddr) + account.SetBalance(ethutil.Big("1606938044258990275541962092341162602522202993782792835301376")) //ethutil.BigPow(2, 200) + block.State().UpdateStateObject(account) + } +} + +func CalcDifficulty(block, parent *types.Block) *big.Int { + diff := new(big.Int) + + adjust := new(big.Int).Rsh(parent.Difficulty, 10) + if block.Time >= parent.Time+5 { + diff.Sub(parent.Difficulty, adjust) + } else { + diff.Add(parent.Difficulty, adjust) + } + + return diff +} + +type ChainManager struct { + //eth EthManager + processor types.BlockProcessor + eventMux *event.TypeMux + genesisBlock *types.Block + // Last known total difficulty + TD *big.Int + + LastBlockNumber uint64 + + CurrentBlock *types.Block + LastBlockHash []byte +} + +func NewChainManager(mux *event.TypeMux) *ChainManager { + bc := &ChainManager{} + bc.genesisBlock = types.NewBlockFromBytes(ethutil.Encode(Genesis)) + bc.eventMux = mux + + bc.setLastBlock() + + return bc +} + +func (self *ChainManager) SetProcessor(proc types.BlockProcessor) { + self.processor = proc +} + +func (bc *ChainManager) setLastBlock() { + data, _ := ethutil.Config.Db.Get([]byte("LastBlock")) + if len(data) != 0 { + // Prep genesis + AddTestNetFunds(bc.genesisBlock) + + block := types.NewBlockFromBytes(data) + bc.CurrentBlock = block + bc.LastBlockHash = block.Hash() + bc.LastBlockNumber = block.Number.Uint64() + + // Set the last know difficulty (might be 0x0 as initial value, Genesis) + bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) + } else { + bc.Reset() + } + + chainlogger.Infof("Last block (#%d) %x\n", bc.LastBlockNumber, bc.CurrentBlock.Hash()) +} + +// Block creation & chain handling +func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block { + var root interface{} + hash := ZeroHash256 + + if bc.CurrentBlock != nil { + root = bc.CurrentBlock.Root() + hash = bc.LastBlockHash + } + + block := types.CreateBlock( + root, + hash, + coinbase, + ethutil.BigPow(2, 32), + nil, + "") + + parent := bc.CurrentBlock + if parent != nil { + block.Difficulty = CalcDifficulty(block, parent) + block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1) + block.GasLimit = block.CalcGasLimit(bc.CurrentBlock) + + } + + return block +} + +func (bc *ChainManager) Reset() { + AddTestNetFunds(bc.genesisBlock) + + bc.genesisBlock.Trie().Sync() + // Prepare the genesis block + bc.add(bc.genesisBlock) + bc.CurrentBlock = bc.genesisBlock + + bc.SetTotalDifficulty(ethutil.Big("0")) + + // Set the last know difficulty (might be 0x0 as initial value, Genesis) + bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) +} + +// Add a block to the chain and record addition information +func (bc *ChainManager) add(block *types.Block) { + bc.writeBlockInfo(block) + + bc.CurrentBlock = block + bc.LastBlockHash = block.Hash() + + encodedBlock := block.RlpEncode() + ethutil.Config.Db.Put(block.Hash(), encodedBlock) + ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) + + //chainlogger.Infof("Imported block #%d (%x...)\n", block.Number, block.Hash()[0:4]) +} + +// Accessors +func (bc *ChainManager) Genesis() *types.Block { + return bc.genesisBlock +} + +// Block fetching methods +func (bc *ChainManager) HasBlock(hash []byte) bool { + data, _ := ethutil.Config.Db.Get(hash) + return len(data) != 0 +} + +func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) { + block := self.GetBlock(hash) + if block == nil { + return + } + + // XXX Could be optimised by using a different database which only holds hashes (i.e., linked list) + for i := uint64(0); i < max; i++ { + + chain = append(chain, block.Hash()) + + if block.Number.Cmp(ethutil.Big0) <= 0 { + break + } + + block = self.GetBlock(block.PrevHash) + } + + return +} + +func (self *ChainManager) GetBlock(hash []byte) *types.Block { + data, _ := ethutil.Config.Db.Get(hash) + if len(data) == 0 { + return nil + } + + return types.NewBlockFromBytes(data) +} + +func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block { + block := self.CurrentBlock + for ; block != nil; block = self.GetBlock(block.PrevHash) { + if block.Number.Uint64() == num { + break + } + } + + if block != nil && block.Number.Uint64() == 0 && num != 0 { + return nil + } + + return block +} + +func (bc *ChainManager) SetTotalDifficulty(td *big.Int) { + ethutil.Config.Db.Put([]byte("LTD"), td.Bytes()) + bc.TD = td +} + +func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) { + parent := self.GetBlock(block.PrevHash) + if parent == nil { + return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.PrevHash) + } + + parentTd := parent.BlockInfo().TD + + uncleDiff := new(big.Int) + for _, uncle := range block.Uncles { + uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty) + } + + td := new(big.Int) + td = td.Add(parentTd, uncleDiff) + td = td.Add(td, block.Difficulty) + + return td, nil +} + +func (bc *ChainManager) BlockInfo(block *types.Block) types.BlockInfo { + bi := types.BlockInfo{} + data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...)) + bi.RlpDecode(data) + + return bi +} + +// Unexported method for writing extra non-essential block info to the db +func (bc *ChainManager) writeBlockInfo(block *types.Block) { + bc.LastBlockNumber++ + bi := types.BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD} + + // For now we use the block hash with the words "info" appended as key + ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode()) +} + +func (bc *ChainManager) Stop() { + if bc.CurrentBlock != nil { + chainlogger.Infoln("Stopped") + } +} + +func (self *ChainManager) InsertChain(chain types.Blocks) error { + for _, block := range chain { + td, messages, err := self.processor.Process(block) + if err != nil { + if IsKnownBlockErr(err) { + continue + } + + chainlogger.Infof("block #%v process failed (%x)\n", block.Number, block.Hash()[:4]) + chainlogger.Infoln(block) + chainlogger.Infoln(err) + return err + } + + self.add(block) + self.SetTotalDifficulty(td) + self.eventMux.Post(NewBlockEvent{block}) + self.eventMux.Post(messages) + } + + return nil +} -- cgit From 73123bf257934e95e08311d4af9b3382f3dcdb39 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 15:35:21 +0100 Subject: Only set TD if it's actually higher --- core/chain_manager.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index 7acd171ec..7d4aeaab6 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -267,7 +267,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { } self.add(block) - self.SetTotalDifficulty(td) + if td.Cmp(self.TD) > 0 { + self.SetTotalDifficulty(td) + } + self.eventMux.Post(NewBlockEvent{block}) self.eventMux.Post(messages) } -- cgit From 9925916851c00323336e213fc18c83da5fceee94 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 5 Dec 2014 16:26:39 +0100 Subject: upped proto version and modified block pool --- core/chain_manager.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index 7d4aeaab6..150139def 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -125,7 +125,8 @@ func (bc *ChainManager) Reset() { bc.genesisBlock.Trie().Sync() // Prepare the genesis block - bc.add(bc.genesisBlock) + bc.write(bc.genesisBlock) + bc.insert(bc.genesisBlock) bc.CurrentBlock = bc.genesisBlock bc.SetTotalDifficulty(ethutil.Big("0")) @@ -134,18 +135,18 @@ func (bc *ChainManager) Reset() { bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) } -// Add a block to the chain and record addition information -func (bc *ChainManager) add(block *types.Block) { - bc.writeBlockInfo(block) - +func (bc *ChainManager) insert(block *types.Block) { + encodedBlock := block.RlpEncode() + ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) bc.CurrentBlock = block bc.LastBlockHash = block.Hash() +} + +func (bc *ChainManager) write(block *types.Block) { + bc.writeBlockInfo(block) encodedBlock := block.RlpEncode() ethutil.Config.Db.Put(block.Hash(), encodedBlock) - ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) - - //chainlogger.Infof("Imported block #%d (%x...)\n", block.Number, block.Hash()[0:4]) } // Accessors @@ -266,9 +267,14 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { return err } - self.add(block) + self.write(block) if td.Cmp(self.TD) > 0 { + if block.Number.Cmp(new(big.Int).Add(self.CurrentBlock.Number, ethutil.Big1)) < 0 { + chainlogger.Infof("Split detected. New head #%v (%x), was #%v (%x)\n", block.Number, block.Hash()[:4], self.CurrentBlock.Number, self.CurrentBlock.Hash()[:4]) + } + self.SetTotalDifficulty(td) + self.insert(block) } self.eventMux.Post(NewBlockEvent{block}) -- cgit From 5553e5aaed5c3f4e303b7d6671d2c92a45aa487e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 10 Dec 2014 19:59:12 +0100 Subject: states moved to chain --- core/chain_manager.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index 150139def..0322edaa5 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/state" ) var chainlogger = logger.NewLogger("CHAIN") @@ -55,6 +56,8 @@ type ChainManager struct { CurrentBlock *types.Block LastBlockHash []byte + + transState *state.StateDB } func NewChainManager(mux *event.TypeMux) *ChainManager { @@ -64,6 +67,8 @@ func NewChainManager(mux *event.TypeMux) *ChainManager { bc.setLastBlock() + bc.transState = bc.State().Copy() + return bc } @@ -71,6 +76,14 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) { self.processor = proc } +func (self *ChainManager) State() *state.StateDB { + return self.CurrentBlock.State() +} + +func (self *ChainManager) TransState() *state.StateDB { + return self.transState +} + func (bc *ChainManager) setLastBlock() { data, _ := ethutil.Config.Db.Get([]byte("LastBlock")) if len(data) != 0 { -- cgit From 2b5fcb464262a7bdd766861b513b2a23706f8b13 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 10 Dec 2014 20:26:55 +0100 Subject: moved interfaces --- core/chain_manager.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index 0322edaa5..edf50e715 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -288,6 +288,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { self.SetTotalDifficulty(td) self.insert(block) + self.transState = self.State().Copy() + //sm.eth.TxPool().RemoveSet(block.Transactions()) } self.eventMux.Post(NewBlockEvent{block}) -- cgit From b1c58b76a9588a90db5a773a997bb70265c378d3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Dec 2014 12:57:35 +0100 Subject: moved err check --- core/chain_manager.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index edf50e715..3e48579b9 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -148,6 +148,16 @@ func (bc *ChainManager) Reset() { bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) } +func (self *ChainManager) Export() []byte { + chainlogger.Infoln("exporting", self.CurrentBlock.Number, "blocks") + + blocks := make(types.Blocks, int(self.CurrentBlock.Number.Int64())+1) + for block := self.CurrentBlock; block != nil; block = self.GetBlock(block.PrevHash) { + blocks[block.Number.Int64()] = block + } + return ethutil.Encode(blocks) +} + func (bc *ChainManager) insert(block *types.Block) { encodedBlock := block.RlpEncode() ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) @@ -181,7 +191,6 @@ func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain // XXX Could be optimised by using a different database which only holds hashes (i.e., linked list) for i := uint64(0); i < max; i++ { - chain = append(chain, block.Hash()) if block.Number.Cmp(ethutil.Big0) <= 0 { -- cgit From 49e0267fe76cfd13eaf3e5e26caa637b93dbdd29 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 13:12:54 +0100 Subject: Locks, refactor, tests * Added additional chain tests * Added proper mutex' on chain * Removed ethereum dependencies --- core/chain_manager.go | 113 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 37 deletions(-) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index 3e48579b9..c81552b5d 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -3,6 +3,7 @@ package core import ( "fmt" "math/big" + "sync" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethutil" @@ -50,14 +51,34 @@ type ChainManager struct { eventMux *event.TypeMux genesisBlock *types.Block // Last known total difficulty - TD *big.Int + mu sync.RWMutex + td *big.Int + lastBlockNumber uint64 + currentBlock *types.Block + lastBlockHash []byte - LastBlockNumber uint64 + transState *state.StateDB +} - CurrentBlock *types.Block - LastBlockHash []byte +func (self *ChainManager) Td() *big.Int { + self.mu.RLock() + defer self.mu.RUnlock() - transState *state.StateDB + return self.td +} + +func (self *ChainManager) LastBlockNumber() uint64 { + self.mu.RLock() + defer self.mu.RUnlock() + + return self.lastBlockNumber +} + +func (self *ChainManager) CurrentBlock() *types.Block { + self.mu.RLock() + defer self.mu.RUnlock() + + return self.currentBlock } func NewChainManager(mux *event.TypeMux) *ChainManager { @@ -77,7 +98,7 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) { } func (self *ChainManager) State() *state.StateDB { - return self.CurrentBlock.State() + return self.CurrentBlock().State() } func (self *ChainManager) TransState() *state.StateDB { @@ -91,27 +112,30 @@ func (bc *ChainManager) setLastBlock() { AddTestNetFunds(bc.genesisBlock) block := types.NewBlockFromBytes(data) - bc.CurrentBlock = block - bc.LastBlockHash = block.Hash() - bc.LastBlockNumber = block.Number.Uint64() + bc.currentBlock = block + bc.lastBlockHash = block.Hash() + bc.lastBlockNumber = block.Number.Uint64() // Set the last know difficulty (might be 0x0 as initial value, Genesis) - bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) + bc.td = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) } else { bc.Reset() } - chainlogger.Infof("Last block (#%d) %x\n", bc.LastBlockNumber, bc.CurrentBlock.Hash()) + chainlogger.Infof("Last block (#%d) %x\n", bc.lastBlockNumber, bc.currentBlock.Hash()) } // Block creation & chain handling func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block { + bc.mu.RLock() + defer bc.mu.RUnlock() + var root interface{} hash := ZeroHash256 if bc.CurrentBlock != nil { - root = bc.CurrentBlock.Root() - hash = bc.LastBlockHash + root = bc.currentBlock.Root() + hash = bc.lastBlockHash } block := types.CreateBlock( @@ -122,11 +146,11 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block { nil, "") - parent := bc.CurrentBlock + parent := bc.currentBlock if parent != nil { block.Difficulty = CalcDifficulty(block, parent) - block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1) - block.GasLimit = block.CalcGasLimit(bc.CurrentBlock) + block.Number = new(big.Int).Add(bc.currentBlock.Number, ethutil.Big1) + block.GasLimit = block.CalcGasLimit(bc.currentBlock) } @@ -134,35 +158,42 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block { } func (bc *ChainManager) Reset() { + bc.mu.Lock() + defer bc.mu.Unlock() + AddTestNetFunds(bc.genesisBlock) bc.genesisBlock.Trie().Sync() // Prepare the genesis block bc.write(bc.genesisBlock) bc.insert(bc.genesisBlock) - bc.CurrentBlock = bc.genesisBlock + bc.currentBlock = bc.genesisBlock - bc.SetTotalDifficulty(ethutil.Big("0")) + bc.setTotalDifficulty(ethutil.Big("0")) // Set the last know difficulty (might be 0x0 as initial value, Genesis) - bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) + bc.td = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) } func (self *ChainManager) Export() []byte { - chainlogger.Infoln("exporting", self.CurrentBlock.Number, "blocks") + self.mu.RLock() + defer self.mu.RUnlock() + + chainlogger.Infof("exporting %v blocks...\n", self.currentBlock.Number) - blocks := make(types.Blocks, int(self.CurrentBlock.Number.Int64())+1) - for block := self.CurrentBlock; block != nil; block = self.GetBlock(block.PrevHash) { + blocks := make([]*types.Block, int(self.currentBlock.Number.Int64())+1) + for block := self.currentBlock; block != nil; block = self.GetBlock(block.PrevHash) { blocks[block.Number.Int64()] = block } + return ethutil.Encode(blocks) } func (bc *ChainManager) insert(block *types.Block) { encodedBlock := block.RlpEncode() ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) - bc.CurrentBlock = block - bc.LastBlockHash = block.Hash() + bc.currentBlock = block + bc.lastBlockHash = block.Hash() } func (bc *ChainManager) write(block *types.Block) { @@ -213,7 +244,10 @@ func (self *ChainManager) GetBlock(hash []byte) *types.Block { } func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block { - block := self.CurrentBlock + self.mu.RLock() + defer self.mu.RUnlock() + + block := self.currentBlock for ; block != nil; block = self.GetBlock(block.PrevHash) { if block.Number.Uint64() == num { break @@ -227,9 +261,9 @@ func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block { return block } -func (bc *ChainManager) SetTotalDifficulty(td *big.Int) { +func (bc *ChainManager) setTotalDifficulty(td *big.Int) { ethutil.Config.Db.Put([]byte("LTD"), td.Bytes()) - bc.TD = td + bc.td = td } func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) { @@ -262,8 +296,8 @@ func (bc *ChainManager) BlockInfo(block *types.Block) types.BlockInfo { // Unexported method for writing extra non-essential block info to the db func (bc *ChainManager) writeBlockInfo(block *types.Block) { - bc.LastBlockNumber++ - bi := types.BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD} + bc.lastBlockNumber++ + bi := types.BlockInfo{Number: bc.lastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.td} // For now we use the block hash with the words "info" appended as key ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode()) @@ -289,17 +323,22 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { return err } - self.write(block) - if td.Cmp(self.TD) > 0 { - if block.Number.Cmp(new(big.Int).Add(self.CurrentBlock.Number, ethutil.Big1)) < 0 { - chainlogger.Infof("Split detected. New head #%v (%x), was #%v (%x)\n", block.Number, block.Hash()[:4], self.CurrentBlock.Number, self.CurrentBlock.Hash()[:4]) + self.mu.Lock() + { + + self.write(block) + if td.Cmp(self.td) > 0 { + if block.Number.Cmp(new(big.Int).Add(self.currentBlock.Number, ethutil.Big1)) < 0 { + chainlogger.Infof("Split detected. New head #%v (%x), was #%v (%x)\n", block.Number, block.Hash()[:4], self.currentBlock.Number, self.currentBlock.Hash()[:4]) + } + + self.setTotalDifficulty(td) + self.insert(block) + self.transState = self.currentBlock.State().Copy() } - self.SetTotalDifficulty(td) - self.insert(block) - self.transState = self.State().Copy() - //sm.eth.TxPool().RemoveSet(block.Transactions()) } + self.mu.Unlock() self.eventMux.Post(NewBlockEvent{block}) self.eventMux.Post(messages) -- cgit From 2d09e67713757e2a80eb614562c97f962af36cf7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 13:17:24 +0100 Subject: Updated to new methods --- core/chain_manager.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core/chain_manager.go') diff --git a/core/chain_manager.go b/core/chain_manager.go index c81552b5d..794ae0011 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -74,6 +74,13 @@ func (self *ChainManager) LastBlockNumber() uint64 { return self.lastBlockNumber } +func (self *ChainManager) LastBlockHash() []byte { + self.mu.RLock() + defer self.mu.RUnlock() + + return self.lastBlockHash +} + func (self *ChainManager) CurrentBlock() *types.Block { self.mu.RLock() defer self.mu.RUnlock() -- cgit