forked from cerc-io/plugeth
Renamed block_chain to chain_manager
This commit is contained in:
parent
33ca8d7b8f
commit
097ba56df5
@ -66,11 +66,11 @@ func (self *BlockPool) HasLatestHash() bool {
|
|||||||
self.mut.Lock()
|
self.mut.Lock()
|
||||||
defer self.mut.Unlock()
|
defer self.mut.Unlock()
|
||||||
|
|
||||||
return self.pool[string(self.eth.BlockChain().CurrentBlock.Hash())] != nil
|
return self.pool[string(self.eth.ChainManager().CurrentBlock.Hash())] != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockPool) HasCommonHash(hash []byte) bool {
|
func (self *BlockPool) HasCommonHash(hash []byte) bool {
|
||||||
return self.eth.BlockChain().GetBlock(hash) != nil
|
return self.eth.ChainManager().GetBlock(hash) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockPool) Blocks() (blocks ethchain.Blocks) {
|
func (self *BlockPool) Blocks() (blocks ethchain.Blocks) {
|
||||||
@ -137,7 +137,7 @@ func (self *BlockPool) addBlock(b *ethchain.Block, peer *Peer, newBlock bool) {
|
|||||||
|
|
||||||
hash := string(b.Hash())
|
hash := string(b.Hash())
|
||||||
|
|
||||||
if self.pool[hash] == nil && !self.eth.BlockChain().HasBlock(b.Hash()) {
|
if self.pool[hash] == nil && !self.eth.ChainManager().HasBlock(b.Hash()) {
|
||||||
poollogger.Infof("Got unrequested block (%x...)\n", hash[0:4])
|
poollogger.Infof("Got unrequested block (%x...)\n", hash[0:4])
|
||||||
|
|
||||||
self.hashes = append(self.hashes, b.Hash())
|
self.hashes = append(self.hashes, b.Hash())
|
||||||
@ -145,10 +145,10 @@ func (self *BlockPool) addBlock(b *ethchain.Block, peer *Peer, newBlock bool) {
|
|||||||
|
|
||||||
// The following is only performed on an unrequested new block
|
// The following is only performed on an unrequested new block
|
||||||
if newBlock {
|
if newBlock {
|
||||||
fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
|
fmt.Println("1.", !self.eth.ChainManager().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
|
||||||
fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
|
fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
|
||||||
fmt.Println("3.", !self.fetchingHashes)
|
fmt.Println("3.", !self.fetchingHashes)
|
||||||
if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
|
if !self.eth.ChainManager().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
|
||||||
poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
|
poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
|
||||||
peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
|
peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ out:
|
|||||||
ethchain.BlockBy(ethchain.Number).Sort(blocks)
|
ethchain.BlockBy(ethchain.Number).Sort(blocks)
|
||||||
|
|
||||||
if len(blocks) > 0 {
|
if len(blocks) > 0 {
|
||||||
if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
|
if !self.eth.ChainManager().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,14 +287,14 @@ out:
|
|||||||
|
|
||||||
// Find common block
|
// Find common block
|
||||||
for i, block := range blocks {
|
for i, block := range blocks {
|
||||||
if self.eth.BlockChain().HasBlock(block.PrevHash) {
|
if self.eth.ChainManager().HasBlock(block.PrevHash) {
|
||||||
blocks = blocks[i:]
|
blocks = blocks[i:]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(blocks) > 0 {
|
if len(blocks) > 0 {
|
||||||
if self.eth.BlockChain().HasBlock(blocks[0].PrevHash) {
|
if self.eth.ChainManager().HasBlock(blocks[0].PrevHash) {
|
||||||
for i, block := range blocks[1:] {
|
for i, block := range blocks[1:] {
|
||||||
// NOTE: The Ith element in this loop refers to the previous block in
|
// NOTE: The Ith element in this loop refers to the previous block in
|
||||||
// outer "blocks"
|
// outer "blocks"
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
package ethchain
|
|
||||||
|
|
||||||
/*
|
|
||||||
import (
|
|
||||||
_ "fmt"
|
|
||||||
"github.com/ethereum/eth-go/ethdb"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
|
||||||
"math/big"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestVm(t *testing.T) {
|
|
||||||
InitFees()
|
|
||||||
ethutil.ReadConfig("")
|
|
||||||
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
|
||||||
ethutil.Config.Db = db
|
|
||||||
bm := NewStateManager(nil)
|
|
||||||
|
|
||||||
block := bm.bc.genesisBlock
|
|
||||||
bm.Prepare(block.State(), block.State())
|
|
||||||
script := Compile([]string{
|
|
||||||
"PUSH",
|
|
||||||
"1",
|
|
||||||
"PUSH",
|
|
||||||
"2",
|
|
||||||
})
|
|
||||||
tx := NewTransaction(ContractAddr, big.NewInt(200000000), script)
|
|
||||||
addr := tx.Hash()[12:]
|
|
||||||
bm.ApplyTransactions(block, []*Transaction{tx})
|
|
||||||
|
|
||||||
tx2 := NewTransaction(addr, big.NewInt(1e17), nil)
|
|
||||||
tx2.Sign([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
|
||||||
bm.ApplyTransactions(block, []*Transaction{tx2})
|
|
||||||
}
|
|
||||||
*/
|
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
var chainlogger = ethlog.NewLogger("CHAIN")
|
var chainlogger = ethlog.NewLogger("CHAIN")
|
||||||
|
|
||||||
type BlockChain struct {
|
type ChainManager struct {
|
||||||
Ethereum EthManager
|
Ethereum EthManager
|
||||||
// The famous, the fabulous Mister GENESIIIIIIS (block)
|
// The famous, the fabulous Mister GENESIIIIIIS (block)
|
||||||
genesisBlock *Block
|
genesisBlock *Block
|
||||||
@ -24,8 +24,8 @@ type BlockChain struct {
|
|||||||
LastBlockHash []byte
|
LastBlockHash []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockChain(ethereum EthManager) *BlockChain {
|
func NewChainManager(ethereum EthManager) *ChainManager {
|
||||||
bc := &BlockChain{}
|
bc := &ChainManager{}
|
||||||
bc.genesisBlock = NewBlockFromBytes(ethutil.Encode(Genesis))
|
bc.genesisBlock = NewBlockFromBytes(ethutil.Encode(Genesis))
|
||||||
bc.Ethereum = ethereum
|
bc.Ethereum = ethereum
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ func NewBlockChain(ethereum EthManager) *BlockChain {
|
|||||||
return bc
|
return bc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) Genesis() *Block {
|
func (bc *ChainManager) Genesis() *Block {
|
||||||
return bc.genesisBlock
|
return bc.genesisBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
|
func (bc *ChainManager) NewBlock(coinbase []byte) *Block {
|
||||||
var root interface{}
|
var root interface{}
|
||||||
hash := ZeroHash256
|
hash := ZeroHash256
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func CalcDifficulty(block, parent *Block) *big.Int {
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) Reset() {
|
func (bc *ChainManager) Reset() {
|
||||||
AddTestNetFunds(bc.genesisBlock)
|
AddTestNetFunds(bc.genesisBlock)
|
||||||
|
|
||||||
bc.genesisBlock.state.Trie.Sync()
|
bc.genesisBlock.state.Trie.Sync()
|
||||||
@ -97,13 +97,13 @@ func (bc *BlockChain) Reset() {
|
|||||||
bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD())
|
bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) HasBlock(hash []byte) bool {
|
func (bc *ChainManager) HasBlock(hash []byte) bool {
|
||||||
data, _ := ethutil.Config.Db.Get(hash)
|
data, _ := ethutil.Config.Db.Get(hash)
|
||||||
return len(data) != 0
|
return len(data) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: At one point we might want to save a block by prevHash in the db to optimise this...
|
// TODO: At one point we might want to save a block by prevHash in the db to optimise this...
|
||||||
func (bc *BlockChain) HasBlockWithPrevHash(hash []byte) bool {
|
func (bc *ChainManager) HasBlockWithPrevHash(hash []byte) bool {
|
||||||
block := bc.CurrentBlock
|
block := bc.CurrentBlock
|
||||||
|
|
||||||
for ; block != nil; block = bc.GetBlock(block.PrevHash) {
|
for ; block != nil; block = bc.GetBlock(block.PrevHash) {
|
||||||
@ -114,7 +114,7 @@ func (bc *BlockChain) HasBlockWithPrevHash(hash []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int {
|
func (bc *ChainManager) CalculateBlockTD(block *Block) *big.Int {
|
||||||
blockDiff := new(big.Int)
|
blockDiff := new(big.Int)
|
||||||
|
|
||||||
for _, uncle := range block.Uncles {
|
for _, uncle := range block.Uncles {
|
||||||
@ -125,11 +125,11 @@ func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int {
|
|||||||
return blockDiff
|
return blockDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) GenesisBlock() *Block {
|
func (bc *ChainManager) GenesisBlock() *Block {
|
||||||
return bc.genesisBlock
|
return bc.genesisBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockChain) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) {
|
func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) {
|
||||||
block := self.GetBlock(hash)
|
block := self.GetBlock(hash)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return
|
return
|
||||||
@ -167,7 +167,7 @@ func AddTestNetFunds(block *Block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) setLastBlock() {
|
func (bc *ChainManager) setLastBlock() {
|
||||||
data, _ := ethutil.Config.Db.Get([]byte("LastBlock"))
|
data, _ := ethutil.Config.Db.Get([]byte("LastBlock"))
|
||||||
if len(data) != 0 {
|
if len(data) != 0 {
|
||||||
// Prep genesis
|
// Prep genesis
|
||||||
@ -187,13 +187,13 @@ func (bc *BlockChain) setLastBlock() {
|
|||||||
chainlogger.Infof("Last block (#%d) %x\n", bc.LastBlockNumber, bc.CurrentBlock.Hash())
|
chainlogger.Infof("Last block (#%d) %x\n", bc.LastBlockNumber, bc.CurrentBlock.Hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) SetTotalDifficulty(td *big.Int) {
|
func (bc *ChainManager) SetTotalDifficulty(td *big.Int) {
|
||||||
ethutil.Config.Db.Put([]byte("LTD"), td.Bytes())
|
ethutil.Config.Db.Put([]byte("LTD"), td.Bytes())
|
||||||
bc.TD = td
|
bc.TD = td
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a block to the chain and record addition information
|
// Add a block to the chain and record addition information
|
||||||
func (bc *BlockChain) Add(block *Block) {
|
func (bc *ChainManager) Add(block *Block) {
|
||||||
bc.writeBlockInfo(block)
|
bc.writeBlockInfo(block)
|
||||||
// Prepare the genesis block
|
// Prepare the genesis block
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ func (bc *BlockChain) Add(block *Block) {
|
|||||||
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
|
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockChain) CalcTotalDiff(block *Block) (*big.Int, error) {
|
func (self *ChainManager) CalcTotalDiff(block *Block) (*big.Int, error) {
|
||||||
parent := self.GetBlock(block.PrevHash)
|
parent := self.GetBlock(block.PrevHash)
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.PrevHash)
|
return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.PrevHash)
|
||||||
@ -225,7 +225,7 @@ func (self *BlockChain) CalcTotalDiff(block *Block) (*big.Int, error) {
|
|||||||
return td, nil
|
return td, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) GetBlock(hash []byte) *Block {
|
func (bc *ChainManager) GetBlock(hash []byte) *Block {
|
||||||
data, _ := ethutil.Config.Db.Get(hash)
|
data, _ := ethutil.Config.Db.Get(hash)
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@ -234,7 +234,7 @@ func (bc *BlockChain) GetBlock(hash []byte) *Block {
|
|||||||
return NewBlockFromBytes(data)
|
return NewBlockFromBytes(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
|
func (self *ChainManager) GetBlockByNumber(num uint64) *Block {
|
||||||
block := self.CurrentBlock
|
block := self.CurrentBlock
|
||||||
for ; block != nil; block = self.GetBlock(block.PrevHash) {
|
for ; block != nil; block = self.GetBlock(block.PrevHash) {
|
||||||
if block.Number.Uint64() == num {
|
if block.Number.Uint64() == num {
|
||||||
@ -249,7 +249,7 @@ func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
|
|||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockChain) GetBlockBack(num uint64) *Block {
|
func (self *ChainManager) GetBlockBack(num uint64) *Block {
|
||||||
block := self.CurrentBlock
|
block := self.CurrentBlock
|
||||||
|
|
||||||
for ; num != 0 && block != nil; num-- {
|
for ; num != 0 && block != nil; num-- {
|
||||||
@ -259,7 +259,7 @@ func (self *BlockChain) GetBlockBack(num uint64) *Block {
|
|||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) BlockInfoByHash(hash []byte) BlockInfo {
|
func (bc *ChainManager) BlockInfoByHash(hash []byte) BlockInfo {
|
||||||
bi := BlockInfo{}
|
bi := BlockInfo{}
|
||||||
data, _ := ethutil.Config.Db.Get(append(hash, []byte("Info")...))
|
data, _ := ethutil.Config.Db.Get(append(hash, []byte("Info")...))
|
||||||
bi.RlpDecode(data)
|
bi.RlpDecode(data)
|
||||||
@ -267,7 +267,7 @@ func (bc *BlockChain) BlockInfoByHash(hash []byte) BlockInfo {
|
|||||||
return bi
|
return bi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) BlockInfo(block *Block) BlockInfo {
|
func (bc *ChainManager) BlockInfo(block *Block) BlockInfo {
|
||||||
bi := BlockInfo{}
|
bi := BlockInfo{}
|
||||||
data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...))
|
data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...))
|
||||||
bi.RlpDecode(data)
|
bi.RlpDecode(data)
|
||||||
@ -276,7 +276,7 @@ func (bc *BlockChain) BlockInfo(block *Block) BlockInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unexported method for writing extra non-essential block info to the db
|
// Unexported method for writing extra non-essential block info to the db
|
||||||
func (bc *BlockChain) writeBlockInfo(block *Block) {
|
func (bc *ChainManager) writeBlockInfo(block *Block) {
|
||||||
bc.LastBlockNumber++
|
bc.LastBlockNumber++
|
||||||
bi := BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD}
|
bi := BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD}
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ func (bc *BlockChain) writeBlockInfo(block *Block) {
|
|||||||
ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode())
|
ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) Stop() {
|
func (bc *ChainManager) Stop() {
|
||||||
if bc.CurrentBlock != nil {
|
if bc.CurrentBlock != nil {
|
||||||
chainlogger.Infoln("Stopped")
|
chainlogger.Infoln("Stopped")
|
||||||
}
|
}
|
@ -76,16 +76,16 @@ func (self *Filter) SetSkip(skip int) {
|
|||||||
func (self *Filter) Find() []*ethstate.Message {
|
func (self *Filter) Find() []*ethstate.Message {
|
||||||
var earliestBlockNo uint64 = uint64(self.earliest)
|
var earliestBlockNo uint64 = uint64(self.earliest)
|
||||||
if self.earliest == -1 {
|
if self.earliest == -1 {
|
||||||
earliestBlockNo = self.eth.BlockChain().CurrentBlock.Number.Uint64()
|
earliestBlockNo = self.eth.ChainManager().CurrentBlock.Number.Uint64()
|
||||||
}
|
}
|
||||||
var latestBlockNo uint64 = uint64(self.latest)
|
var latestBlockNo uint64 = uint64(self.latest)
|
||||||
if self.latest == -1 {
|
if self.latest == -1 {
|
||||||
latestBlockNo = self.eth.BlockChain().CurrentBlock.Number.Uint64()
|
latestBlockNo = self.eth.ChainManager().CurrentBlock.Number.Uint64()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
messages []*ethstate.Message
|
messages []*ethstate.Message
|
||||||
block = self.eth.BlockChain().GetBlockByNumber(latestBlockNo)
|
block = self.eth.ChainManager().GetBlockByNumber(latestBlockNo)
|
||||||
quit bool
|
quit bool
|
||||||
)
|
)
|
||||||
for i := 0; !quit && block != nil; i++ {
|
for i := 0; !quit && block != nil; i++ {
|
||||||
@ -111,7 +111,7 @@ func (self *Filter) Find() []*ethstate.Message {
|
|||||||
messages = append(messages, self.FilterMessages(msgs)...)
|
messages = append(messages, self.FilterMessages(msgs)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
block = self.eth.BlockChain().GetBlock(block.PrevHash)
|
block = self.eth.ChainManager().GetBlock(block.PrevHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
skip := int(math.Min(float64(len(messages)), float64(self.skip)))
|
skip := int(math.Min(float64(len(messages)), float64(self.skip)))
|
||||||
|
@ -33,7 +33,7 @@ type Peer interface {
|
|||||||
|
|
||||||
type EthManager interface {
|
type EthManager interface {
|
||||||
StateManager() *StateManager
|
StateManager() *StateManager
|
||||||
BlockChain() *BlockChain
|
ChainManager() *ChainManager
|
||||||
TxPool() *TxPool
|
TxPool() *TxPool
|
||||||
Broadcast(msgType ethwire.MsgType, data []interface{})
|
Broadcast(msgType ethwire.MsgType, data []interface{})
|
||||||
PeerCount() int
|
PeerCount() int
|
||||||
@ -50,7 +50,7 @@ type StateManager struct {
|
|||||||
// Mutex for locking the block processor. Blocks can only be handled one at a time
|
// Mutex for locking the block processor. Blocks can only be handled one at a time
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
// Canonical block chain
|
// Canonical block chain
|
||||||
bc *BlockChain
|
bc *ChainManager
|
||||||
// non-persistent key/value memory storage
|
// non-persistent key/value memory storage
|
||||||
mem map[string]*big.Int
|
mem map[string]*big.Int
|
||||||
// Proof of work used for validating
|
// Proof of work used for validating
|
||||||
@ -79,10 +79,10 @@ func NewStateManager(ethereum EthManager) *StateManager {
|
|||||||
mem: make(map[string]*big.Int),
|
mem: make(map[string]*big.Int),
|
||||||
Pow: &EasyPow{},
|
Pow: &EasyPow{},
|
||||||
eth: ethereum,
|
eth: ethereum,
|
||||||
bc: ethereum.BlockChain(),
|
bc: ethereum.ChainManager(),
|
||||||
}
|
}
|
||||||
sm.transState = ethereum.BlockChain().CurrentBlock.State().Copy()
|
sm.transState = ethereum.ChainManager().CurrentBlock.State().Copy()
|
||||||
sm.miningState = ethereum.BlockChain().CurrentBlock.State().Copy()
|
sm.miningState = ethereum.ChainManager().CurrentBlock.State().Copy()
|
||||||
|
|
||||||
return sm
|
return sm
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ func (self *StateManager) updateThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) CurrentState() *ethstate.State {
|
func (sm *StateManager) CurrentState() *ethstate.State {
|
||||||
return sm.eth.BlockChain().CurrentBlock.State()
|
return sm.eth.ChainManager().CurrentBlock.State()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) TransState() *ethstate.State {
|
func (sm *StateManager) TransState() *ethstate.State {
|
||||||
@ -125,12 +125,12 @@ func (sm *StateManager) MiningState() *ethstate.State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) NewMiningState() *ethstate.State {
|
func (sm *StateManager) NewMiningState() *ethstate.State {
|
||||||
sm.miningState = sm.eth.BlockChain().CurrentBlock.State().Copy()
|
sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
|
||||||
|
|
||||||
return sm.miningState
|
return sm.miningState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) BlockChain() *BlockChain {
|
func (sm *StateManager) ChainManager() *ChainManager {
|
||||||
return sm.bc
|
return sm.bc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
|
|||||||
func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
|
func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
|
||||||
// Get the last block so we can retrieve the sender and receiver from
|
// Get the last block so we can retrieve the sender and receiver from
|
||||||
// the merkle trie
|
// the merkle trie
|
||||||
block := pool.Ethereum.BlockChain().CurrentBlock
|
block := pool.Ethereum.ChainManager().CurrentBlock
|
||||||
// Something has gone horribly wrong if this happens
|
// Something has gone horribly wrong if this happens
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return fmt.Errorf("[TXPL] No last block on the block chain")
|
return fmt.Errorf("[TXPL] No last block on the block chain")
|
||||||
|
@ -55,7 +55,7 @@ type Ethereum struct {
|
|||||||
// for later including in the blocks
|
// for later including in the blocks
|
||||||
txPool *ethchain.TxPool
|
txPool *ethchain.TxPool
|
||||||
// The canonical chain
|
// The canonical chain
|
||||||
blockChain *ethchain.BlockChain
|
blockChain *ethchain.ChainManager
|
||||||
// The block pool
|
// The block pool
|
||||||
blockPool *BlockPool
|
blockPool *BlockPool
|
||||||
// Eventer
|
// Eventer
|
||||||
@ -129,7 +129,7 @@ func New(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager
|
|||||||
|
|
||||||
ethereum.blockPool = NewBlockPool(ethereum)
|
ethereum.blockPool = NewBlockPool(ethereum)
|
||||||
ethereum.txPool = ethchain.NewTxPool(ethereum)
|
ethereum.txPool = ethchain.NewTxPool(ethereum)
|
||||||
ethereum.blockChain = ethchain.NewBlockChain(ethereum)
|
ethereum.blockChain = ethchain.NewChainManager(ethereum)
|
||||||
ethereum.stateManager = ethchain.NewStateManager(ethereum)
|
ethereum.stateManager = ethchain.NewStateManager(ethereum)
|
||||||
|
|
||||||
// Start the tx pool
|
// Start the tx pool
|
||||||
@ -146,7 +146,7 @@ func (s *Ethereum) ClientIdentity() ethwire.ClientIdentity {
|
|||||||
return s.clientIdentity
|
return s.clientIdentity
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) BlockChain() *ethchain.BlockChain {
|
func (s *Ethereum) ChainManager() *ethchain.ChainManager {
|
||||||
return s.blockChain
|
return s.blockChain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func (miner *Miner) Start() {
|
|||||||
|
|
||||||
// Insert initial TXs in our little miner 'pool'
|
// Insert initial TXs in our little miner 'pool'
|
||||||
miner.txs = miner.ethereum.TxPool().Flush()
|
miner.txs = miner.ethereum.TxPool().Flush()
|
||||||
miner.block = miner.ethereum.BlockChain().NewBlock(miner.coinbase)
|
miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase)
|
||||||
|
|
||||||
mux := miner.ethereum.EventMux()
|
mux := miner.ethereum.EventMux()
|
||||||
miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxEvent{})
|
miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxEvent{})
|
||||||
@ -95,7 +95,7 @@ func (miner *Miner) listener() {
|
|||||||
case ethchain.NewBlockEvent:
|
case ethchain.NewBlockEvent:
|
||||||
block := event.Block
|
block := event.Block
|
||||||
//logger.Infoln("Got new block via Reactor")
|
//logger.Infoln("Got new block via Reactor")
|
||||||
if bytes.Compare(miner.ethereum.BlockChain().CurrentBlock.Hash(), block.Hash()) == 0 {
|
if bytes.Compare(miner.ethereum.ChainManager().CurrentBlock.Hash(), block.Hash()) == 0 {
|
||||||
// TODO: Perhaps continue mining to get some uncle rewards
|
// TODO: Perhaps continue mining to get some uncle rewards
|
||||||
//logger.Infoln("New top block found resetting state")
|
//logger.Infoln("New top block found resetting state")
|
||||||
|
|
||||||
@ -115,10 +115,10 @@ func (miner *Miner) listener() {
|
|||||||
miner.txs = newtxs
|
miner.txs = newtxs
|
||||||
|
|
||||||
// Setup a fresh state to mine on
|
// Setup a fresh state to mine on
|
||||||
//miner.block = miner.ethereum.BlockChain().NewBlock(miner.coinbase, miner.txs)
|
//miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase, miner.txs)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if bytes.Compare(block.PrevHash, miner.ethereum.BlockChain().CurrentBlock.PrevHash) == 0 {
|
if bytes.Compare(block.PrevHash, miner.ethereum.ChainManager().CurrentBlock.PrevHash) == 0 {
|
||||||
logger.Infoln("Adding uncle block")
|
logger.Infoln("Adding uncle block")
|
||||||
miner.uncles = append(miner.uncles, block)
|
miner.uncles = append(miner.uncles, block)
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ func (miner *Miner) stopMining() {
|
|||||||
func (self *Miner) mineNewBlock() {
|
func (self *Miner) mineNewBlock() {
|
||||||
stateManager := self.ethereum.StateManager()
|
stateManager := self.ethereum.StateManager()
|
||||||
|
|
||||||
self.block = self.ethereum.BlockChain().NewBlock(self.coinbase)
|
self.block = self.ethereum.ChainManager().NewBlock(self.coinbase)
|
||||||
|
|
||||||
// Apply uncles
|
// Apply uncles
|
||||||
if len(self.uncles) > 0 {
|
if len(self.uncles) > 0 {
|
||||||
@ -175,7 +175,7 @@ func (self *Miner) mineNewBlock() {
|
|||||||
|
|
||||||
// Accumulate all valid transactions and apply them to the new state
|
// Accumulate all valid transactions and apply them to the new state
|
||||||
// Error may be ignored. It's not important during mining
|
// Error may be ignored. It's not important during mining
|
||||||
parent := self.ethereum.BlockChain().GetBlock(self.block.PrevHash)
|
parent := self.ethereum.ChainManager().GetBlock(self.block.PrevHash)
|
||||||
coinbase := self.block.State().GetOrNewStateObject(self.block.Coinbase)
|
coinbase := self.block.State().GetOrNewStateObject(self.block.Coinbase)
|
||||||
coinbase.SetGasPool(self.block.CalcGasLimit(parent))
|
coinbase.SetGasPool(self.block.CalcGasLimit(parent))
|
||||||
receipts, txs, unhandledTxs, err := stateManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
|
receipts, txs, unhandledTxs, err := stateManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
|
||||||
|
@ -21,17 +21,17 @@ func NewJSPipe(eth ethchain.EthManager) *JSPipe {
|
|||||||
|
|
||||||
func (self *JSPipe) BlockByHash(strHash string) *JSBlock {
|
func (self *JSPipe) BlockByHash(strHash string) *JSBlock {
|
||||||
hash := ethutil.Hex2Bytes(strHash)
|
hash := ethutil.Hex2Bytes(strHash)
|
||||||
block := self.obj.BlockChain().GetBlock(hash)
|
block := self.obj.ChainManager().GetBlock(hash)
|
||||||
|
|
||||||
return NewJSBlock(block)
|
return NewJSBlock(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSPipe) BlockByNumber(num int32) *JSBlock {
|
func (self *JSPipe) BlockByNumber(num int32) *JSBlock {
|
||||||
if num == -1 {
|
if num == -1 {
|
||||||
return NewJSBlock(self.obj.BlockChain().CurrentBlock)
|
return NewJSBlock(self.obj.ChainManager().CurrentBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewJSBlock(self.obj.BlockChain().GetBlockByNumber(uint64(num)))
|
return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSPipe) Block(v interface{}) *JSBlock {
|
func (self *JSPipe) Block(v interface{}) *JSBlock {
|
||||||
|
@ -21,7 +21,7 @@ type VmVars struct {
|
|||||||
type Pipe struct {
|
type Pipe struct {
|
||||||
obj ethchain.EthManager
|
obj ethchain.EthManager
|
||||||
stateManager *ethchain.StateManager
|
stateManager *ethchain.StateManager
|
||||||
blockChain *ethchain.BlockChain
|
blockChain *ethchain.ChainManager
|
||||||
world *World
|
world *World
|
||||||
|
|
||||||
Vm VmVars
|
Vm VmVars
|
||||||
@ -31,7 +31,7 @@ func New(obj ethchain.EthManager) *Pipe {
|
|||||||
pipe := &Pipe{
|
pipe := &Pipe{
|
||||||
obj: obj,
|
obj: obj,
|
||||||
stateManager: obj.StateManager(),
|
stateManager: obj.StateManager(),
|
||||||
blockChain: obj.BlockChain(),
|
blockChain: obj.ChainManager(),
|
||||||
}
|
}
|
||||||
pipe.world = NewWorld(pipe)
|
pipe.world = NewWorld(pipe)
|
||||||
|
|
||||||
|
29
peer.go
29
peer.go
@ -476,7 +476,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
hash := msg.Data.Get(0).Bytes()
|
hash := msg.Data.Get(0).Bytes()
|
||||||
amount := msg.Data.Get(1).Uint()
|
amount := msg.Data.Get(1).Uint()
|
||||||
|
|
||||||
hashes := p.ethereum.BlockChain().GetChainHashesFromHash(hash, amount)
|
hashes := p.ethereum.ChainManager().GetChainHashesFromHash(hash, amount)
|
||||||
|
|
||||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockHashesTy, ethutil.ByteSliceToInterface(hashes)))
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockHashesTy, ethutil.ByteSliceToInterface(hashes)))
|
||||||
|
|
||||||
@ -487,7 +487,7 @@ func (p *Peer) HandleInbound() {
|
|||||||
|
|
||||||
for i := 0; i < max; i++ {
|
for i := 0; i < max; i++ {
|
||||||
hash := msg.Data.Get(i).Bytes()
|
hash := msg.Data.Get(i).Bytes()
|
||||||
block := p.ethereum.BlockChain().GetBlock(hash)
|
block := p.ethereum.ChainManager().GetBlock(hash)
|
||||||
if block != nil {
|
if block != nil {
|
||||||
blocks = append(blocks, block.Value().Raw())
|
blocks = append(blocks, block.Value().Raw())
|
||||||
}
|
}
|
||||||
@ -674,9 +674,9 @@ func (self *Peer) pushStatus() {
|
|||||||
msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{
|
msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{
|
||||||
//uint32(ProtocolVersion),
|
//uint32(ProtocolVersion),
|
||||||
uint32(NetVersion),
|
uint32(NetVersion),
|
||||||
self.ethereum.BlockChain().TD,
|
self.ethereum.ChainManager().TD,
|
||||||
self.ethereum.BlockChain().CurrentBlock.Hash(),
|
self.ethereum.ChainManager().CurrentBlock.Hash(),
|
||||||
self.ethereum.BlockChain().Genesis().Hash(),
|
self.ethereum.ChainManager().Genesis().Hash(),
|
||||||
})
|
})
|
||||||
|
|
||||||
self.QueueMessage(msg)
|
self.QueueMessage(msg)
|
||||||
@ -693,7 +693,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
|
|||||||
genesis = c.Get(3).Bytes()
|
genesis = c.Get(3).Bytes()
|
||||||
)
|
)
|
||||||
|
|
||||||
if bytes.Compare(self.ethereum.BlockChain().Genesis().Hash(), genesis) != 0 {
|
if bytes.Compare(self.ethereum.ChainManager().Genesis().Hash(), genesis) != 0 {
|
||||||
ethlogger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis)
|
ethlogger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -728,7 +728,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
|
|||||||
func (p *Peer) pushHandshake() error {
|
func (p *Peer) pushHandshake() error {
|
||||||
pubkey := p.ethereum.KeyManager().PublicKey()
|
pubkey := p.ethereum.KeyManager().PublicKey()
|
||||||
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
|
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
|
||||||
P2PVersion, []byte(p.version), []interface{}{"eth", ProtocolVersion}, p.port, pubkey[1:],
|
P2PVersion, []byte(p.version), []interface{}{[]interface{}{"eth", ProtocolVersion}}, p.port, pubkey[1:],
|
||||||
})
|
})
|
||||||
|
|
||||||
p.QueueMessage(msg)
|
p.QueueMessage(msg)
|
||||||
@ -749,6 +749,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
|||||||
|
|
||||||
// Check correctness of p2p protocol version
|
// Check correctness of p2p protocol version
|
||||||
if p2pVersion != P2PVersion {
|
if p2pVersion != P2PVersion {
|
||||||
|
fmt.Println(p)
|
||||||
peerlogger.Debugf("Invalid P2P version. Require protocol %d, received %d\n", P2PVersion, p2pVersion)
|
peerlogger.Debugf("Invalid P2P version. Require protocol %d, received %d\n", P2PVersion, p2pVersion)
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
@ -807,16 +808,16 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
|||||||
p.ethereum.eventMux.Post(PeerListEvent{p.ethereum.Peers()})
|
p.ethereum.eventMux.Post(PeerListEvent{p.ethereum.Peers()})
|
||||||
|
|
||||||
p.protocolCaps = caps
|
p.protocolCaps = caps
|
||||||
capsIt := caps.NewIterator()
|
|
||||||
|
it := caps.NewIterator()
|
||||||
var capsStrs []string
|
var capsStrs []string
|
||||||
for capsIt.Next() {
|
for it.Next() {
|
||||||
cap := capsIt.Value().Str()
|
cap := it.Value().Get(0).Str()
|
||||||
|
ver := it.Value().Get(1).Uint()
|
||||||
switch cap {
|
switch cap {
|
||||||
case "eth":
|
case "eth":
|
||||||
capsIt.Next()
|
if ver != ProtocolVersion {
|
||||||
version := capsIt.Value().Uint()
|
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", ver)
|
||||||
if version != ProtocolVersion {
|
|
||||||
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", version)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
p.pushStatus()
|
p.pushStatus()
|
||||||
|
@ -44,6 +44,9 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
helper.CreateFileTests(t, p, &tests)
|
helper.CreateFileTests(t, p, &tests)
|
||||||
|
|
||||||
for name, test := range tests {
|
for name, test := range tests {
|
||||||
|
if name != "CallRecursiveBomb" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
state := ethstate.New(helper.NewTrie())
|
state := ethstate.New(helper.NewTrie())
|
||||||
for addr, account := range test.Pre {
|
for addr, account := range test.Pre {
|
||||||
obj := StateObjectFromAccount(addr, account)
|
obj := StateObjectFromAccount(addr, account)
|
||||||
@ -56,11 +59,6 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
helper.Log.Infoln(err)
|
helper.Log.Infoln(err)
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s's execution failed. %v\n", name, err)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
rexp := helper.FromHex(test.Out)
|
rexp := helper.FromHex(test.Out)
|
||||||
if bytes.Compare(rexp, ret) != 0 {
|
if bytes.Compare(rexp, ret) != 0 {
|
||||||
@ -94,6 +92,7 @@ func TestVMArithmetic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVMSystemOperation(t *testing.T) {
|
func TestVMSystemOperation(t *testing.T) {
|
||||||
|
helper.Logger.SetLogLevel(5)
|
||||||
const fn = "../files/vmtests/vmSystemOperationsTest.json"
|
const fn = "../files/vmtests/vmSystemOperationsTest.json"
|
||||||
RunVmTest(fn, t)
|
RunVmTest(fn, t)
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
|
|||||||
return closure.Return(nil), nil
|
return closure.Return(nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vmlogger.Debugf("(%s) %x gas: %v (d) %x\n", self.Fn, closure.Address(), closure.Gas, closure.Args)
|
vmlogger.Debugf("(%d) %x gas: %v (d) %x\n", self.depth, closure.Address(), closure.Gas, closure.Args)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
prevStep = step
|
prevStep = step
|
||||||
|
Loading…
Reference in New Issue
Block a user