Merged develop
This commit is contained in:
commit
721e8ae93f
BIN
_data/chain1
Executable file
BIN
_data/chain1
Executable file
Binary file not shown.
BIN
_data/chain2
Executable file
BIN
_data/chain2
Executable file
Binary file not shown.
@ -77,7 +77,7 @@ func main() {
|
|||||||
var block *types.Block
|
var block *types.Block
|
||||||
|
|
||||||
if len(DumpHash) == 0 && DumpNumber == -1 {
|
if len(DumpHash) == 0 && DumpNumber == -1 {
|
||||||
block = ethereum.ChainManager().CurrentBlock
|
block = ethereum.ChainManager().CurrentBlock()
|
||||||
} else if len(DumpHash) > 0 {
|
} else if len(DumpHash) > 0 {
|
||||||
block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash))
|
block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash))
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,7 +149,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
|||||||
|
|
||||||
self.SetAsm(script)
|
self.SetAsm(script)
|
||||||
|
|
||||||
block := self.lib.eth.ChainManager().CurrentBlock
|
block := self.lib.eth.ChainManager().CurrentBlock()
|
||||||
|
|
||||||
env := utils.NewEnv(statedb, block, account.Address(), value)
|
env := utils.NewEnv(statedb, block, account.Address(), value)
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setInitialChain(ancientBlocks bool) {
|
func (gui *Gui) setInitialChain(ancientBlocks bool) {
|
||||||
sBlk := gui.eth.ChainManager().LastBlockHash
|
sBlk := gui.eth.ChainManager().LastBlockHash()
|
||||||
blk := gui.eth.ChainManager().GetBlock(sBlk)
|
blk := gui.eth.ChainManager().GetBlock(sBlk)
|
||||||
for ; blk != nil; blk = gui.eth.ChainManager().GetBlock(sBlk) {
|
for ; blk != nil; blk = gui.eth.ChainManager().GetBlock(sBlk) {
|
||||||
sBlk = blk.PrevHash
|
sBlk = blk.PrevHash
|
||||||
@ -470,7 +470,7 @@ func (gui *Gui) update() {
|
|||||||
case <-peerUpdateTicker.C:
|
case <-peerUpdateTicker.C:
|
||||||
gui.setPeerInfo()
|
gui.setPeerInfo()
|
||||||
case <-generalUpdateTicker.C:
|
case <-generalUpdateTicker.C:
|
||||||
statusText := "#" + gui.eth.ChainManager().CurrentBlock.Number.String()
|
statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number.String()
|
||||||
lastBlockLabel.Set("text", statusText)
|
lastBlockLabel.Set("text", statusText)
|
||||||
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.GetPow().GetHashrate(), 10)+"Khash")
|
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.GetPow().GetHashrate(), 10)+"Khash")
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ type BlockManager struct {
|
|||||||
mem map[string]*big.Int
|
mem map[string]*big.Int
|
||||||
// Proof of work used for validating
|
// Proof of work used for validating
|
||||||
Pow pow.PoW
|
Pow pow.PoW
|
||||||
// The ethereum manager interface
|
|
||||||
eth EthManager
|
txpool *TxPool
|
||||||
|
|
||||||
// The last attempted block is mainly used for debugging purposes
|
// The last attempted block is mainly used for debugging purposes
|
||||||
// This does not have to be a valid block and will be set during
|
// This does not have to be a valid block and will be set during
|
||||||
@ -69,13 +69,13 @@ type BlockManager struct {
|
|||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockManager(ethereum EthManager) *BlockManager {
|
func NewBlockManager(txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockManager {
|
||||||
sm := &BlockManager{
|
sm := &BlockManager{
|
||||||
mem: make(map[string]*big.Int),
|
mem: make(map[string]*big.Int),
|
||||||
Pow: ezp.New(),
|
Pow: ezp.New(),
|
||||||
eth: ethereum,
|
bc: chainManager,
|
||||||
bc: ethereum.ChainManager(),
|
eventMux: eventMux,
|
||||||
eventMux: ethereum.EventMux(),
|
txpool: txpool,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sm
|
return sm
|
||||||
@ -238,7 +238,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
|
|||||||
|
|
||||||
chainlogger.Infof("Processed block #%d (%x...)\n", block.Number, block.Hash()[0:4])
|
chainlogger.Infof("Processed block #%d (%x...)\n", block.Number, block.Hash()[0:4])
|
||||||
|
|
||||||
sm.eth.TxPool().RemoveSet(block.Transactions())
|
sm.txpool.RemoveSet(block.Transactions())
|
||||||
|
|
||||||
return td, messages, nil
|
return td, messages, nil
|
||||||
} else {
|
} else {
|
||||||
@ -254,12 +254,12 @@ func (sm *BlockManager) CalculateTD(block *types.Block) (*big.Int, bool) {
|
|||||||
|
|
||||||
// TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty
|
// TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty
|
||||||
td := new(big.Int)
|
td := new(big.Int)
|
||||||
td = td.Add(sm.bc.TD, uncleDiff)
|
td = td.Add(sm.bc.Td(), uncleDiff)
|
||||||
td = td.Add(td, block.Difficulty)
|
td = td.Add(td, block.Difficulty)
|
||||||
|
|
||||||
// The new TD will only be accepted if the new difficulty is
|
// The new TD will only be accepted if the new difficulty is
|
||||||
// is greater than the previous.
|
// is greater than the previous.
|
||||||
if td.Cmp(sm.bc.TD) > 0 {
|
if td.Cmp(sm.bc.Td()) > 0 {
|
||||||
return td, true
|
return td, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
|
|||||||
|
|
||||||
diff := block.Time - parent.Time
|
diff := block.Time - parent.Time
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
return ValidationError("Block timestamp less then prev block %v (%v - %v)", diff, block.Time, sm.bc.CurrentBlock.Time)
|
return ValidationError("Block timestamp less then prev block %v (%v - %v)", diff, block.Time, sm.bc.CurrentBlock().Time)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX
|
/* XXX
|
||||||
|
@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
@ -50,16 +51,43 @@ type ChainManager struct {
|
|||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
genesisBlock *types.Block
|
genesisBlock *types.Block
|
||||||
// Last known total difficulty
|
// Last known total difficulty
|
||||||
TD *big.Int
|
mu sync.RWMutex
|
||||||
|
td *big.Int
|
||||||
LastBlockNumber uint64
|
lastBlockNumber uint64
|
||||||
|
currentBlock *types.Block
|
||||||
CurrentBlock *types.Block
|
lastBlockHash []byte
|
||||||
LastBlockHash []byte
|
|
||||||
|
|
||||||
transState *state.StateDB
|
transState *state.StateDB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *ChainManager) Td() *big.Int {
|
||||||
|
self.mu.RLock()
|
||||||
|
defer self.mu.RUnlock()
|
||||||
|
|
||||||
|
return self.td
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ChainManager) LastBlockNumber() uint64 {
|
||||||
|
self.mu.RLock()
|
||||||
|
defer self.mu.RUnlock()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
return self.currentBlock
|
||||||
|
}
|
||||||
|
|
||||||
func NewChainManager(mux *event.TypeMux) *ChainManager {
|
func NewChainManager(mux *event.TypeMux) *ChainManager {
|
||||||
bc := &ChainManager{}
|
bc := &ChainManager{}
|
||||||
bc.genesisBlock = types.NewBlockFromBytes(ethutil.Encode(Genesis))
|
bc.genesisBlock = types.NewBlockFromBytes(ethutil.Encode(Genesis))
|
||||||
@ -81,7 +109,7 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) State() *state.StateDB {
|
func (self *ChainManager) State() *state.StateDB {
|
||||||
return self.CurrentBlock.State()
|
return self.CurrentBlock().State()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) TransState() *state.StateDB {
|
func (self *ChainManager) TransState() *state.StateDB {
|
||||||
@ -95,27 +123,30 @@ func (bc *ChainManager) setLastBlock() {
|
|||||||
AddTestNetFunds(bc.genesisBlock)
|
AddTestNetFunds(bc.genesisBlock)
|
||||||
|
|
||||||
block := types.NewBlockFromBytes(data)
|
block := types.NewBlockFromBytes(data)
|
||||||
bc.CurrentBlock = block
|
bc.currentBlock = block
|
||||||
bc.LastBlockHash = block.Hash()
|
bc.lastBlockHash = block.Hash()
|
||||||
bc.LastBlockNumber = block.Number.Uint64()
|
bc.lastBlockNumber = block.Number.Uint64()
|
||||||
|
|
||||||
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
|
// 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 {
|
} else {
|
||||||
bc.Reset()
|
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
|
// Block creation & chain handling
|
||||||
func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
||||||
|
bc.mu.RLock()
|
||||||
|
defer bc.mu.RUnlock()
|
||||||
|
|
||||||
var root interface{}
|
var root interface{}
|
||||||
hash := ZeroHash256
|
hash := ZeroHash256
|
||||||
|
|
||||||
if bc.CurrentBlock != nil {
|
if bc.CurrentBlock != nil {
|
||||||
root = bc.CurrentBlock.Root()
|
root = bc.currentBlock.Root()
|
||||||
hash = bc.LastBlockHash
|
hash = bc.lastBlockHash
|
||||||
}
|
}
|
||||||
|
|
||||||
block := types.CreateBlock(
|
block := types.CreateBlock(
|
||||||
@ -126,11 +157,11 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
|||||||
nil,
|
nil,
|
||||||
"")
|
"")
|
||||||
|
|
||||||
parent := bc.CurrentBlock
|
parent := bc.currentBlock
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
block.Difficulty = CalcDifficulty(block, parent)
|
block.Difficulty = CalcDifficulty(block, parent)
|
||||||
block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1)
|
block.Number = new(big.Int).Add(bc.currentBlock.Number, ethutil.Big1)
|
||||||
block.GasLimit = block.CalcGasLimit(bc.CurrentBlock)
|
block.GasLimit = block.CalcGasLimit(bc.currentBlock)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,35 +169,42 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) Reset() {
|
func (bc *ChainManager) Reset() {
|
||||||
|
bc.mu.Lock()
|
||||||
|
defer bc.mu.Unlock()
|
||||||
|
|
||||||
AddTestNetFunds(bc.genesisBlock)
|
AddTestNetFunds(bc.genesisBlock)
|
||||||
|
|
||||||
bc.genesisBlock.Trie().Sync()
|
bc.genesisBlock.Trie().Sync()
|
||||||
// Prepare the genesis block
|
// Prepare the genesis block
|
||||||
bc.write(bc.genesisBlock)
|
bc.write(bc.genesisBlock)
|
||||||
bc.insert(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)
|
// 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 {
|
func (self *ChainManager) Export() []byte {
|
||||||
chainlogger.Infoln("exporting", self.CurrentBlock.Number, "blocks")
|
self.mu.RLock()
|
||||||
|
defer self.mu.RUnlock()
|
||||||
|
|
||||||
blocks := make(types.Blocks, int(self.CurrentBlock.Number.Int64())+1)
|
chainlogger.Infof("exporting %v blocks...\n", self.currentBlock.Number)
|
||||||
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
|
blocks[block.Number.Int64()] = block
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.Encode(blocks)
|
return ethutil.Encode(blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) insert(block *types.Block) {
|
func (bc *ChainManager) insert(block *types.Block) {
|
||||||
encodedBlock := block.RlpEncode()
|
encodedBlock := block.RlpEncode()
|
||||||
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
|
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
|
||||||
bc.CurrentBlock = block
|
bc.currentBlock = block
|
||||||
bc.LastBlockHash = block.Hash()
|
bc.lastBlockHash = block.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) write(block *types.Block) {
|
func (bc *ChainManager) write(block *types.Block) {
|
||||||
@ -217,7 +255,10 @@ func (self *ChainManager) GetBlock(hash []byte) *types.Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) GetBlockByNumber(num uint64) *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) {
|
for ; block != nil; block = self.GetBlock(block.PrevHash) {
|
||||||
if block.Number.Uint64() == num {
|
if block.Number.Uint64() == num {
|
||||||
break
|
break
|
||||||
@ -231,9 +272,9 @@ func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block {
|
|||||||
return 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())
|
ethutil.Config.Db.Put([]byte("LTD"), td.Bytes())
|
||||||
bc.TD = td
|
bc.td = td
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
|
func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
|
||||||
@ -266,8 +307,8 @@ func (bc *ChainManager) BlockInfo(block *types.Block) types.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 *ChainManager) writeBlockInfo(block *types.Block) {
|
func (bc *ChainManager) writeBlockInfo(block *types.Block) {
|
||||||
bc.LastBlockNumber++
|
bc.lastBlockNumber++
|
||||||
bi := types.BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD}
|
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
|
// 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())
|
ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode())
|
||||||
@ -293,18 +334,23 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.mu.Lock()
|
||||||
|
{
|
||||||
|
|
||||||
self.write(block)
|
self.write(block)
|
||||||
if td.Cmp(self.TD) > 0 {
|
if td.Cmp(self.td) > 0 {
|
||||||
if block.Number.Cmp(new(big.Int).Add(self.CurrentBlock.Number, ethutil.Big1)) < 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])
|
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.setTotalDifficulty(td)
|
||||||
self.insert(block)
|
self.insert(block)
|
||||||
self.transState = self.State().Copy()
|
self.transState = self.currentBlock.State().Copy()
|
||||||
//sm.eth.TxPool().RemoveSet(block.Transactions())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
self.mu.Unlock()
|
||||||
|
|
||||||
self.eventMux.Post(NewBlockEvent{block})
|
self.eventMux.Post(NewBlockEvent{block})
|
||||||
self.eventMux.Post(messages)
|
self.eventMux.Post(messages)
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,75 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
//logpkg "github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChainInsertions(t *testing.T) {
|
//var Logger logpkg.LogSystem
|
||||||
c1, err := ethutil.ReadAllFile(path.Join("..", "_data", "chain1"))
|
//var Log = logpkg.NewLogger("TEST")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
//Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.InfoLevel)
|
||||||
|
//logpkg.AddLogSystem(Logger)
|
||||||
|
|
||||||
|
ethutil.ReadConfig("/tmp/ethtest", "/tmp/ethtest", "ETH")
|
||||||
|
|
||||||
|
db, err := ethdb.NewMemDatabase()
|
||||||
|
if err != nil {
|
||||||
|
panic("Could not create mem-db, failing")
|
||||||
|
}
|
||||||
|
ethutil.Config.Db = db
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadChain(fn string, t *testing.T) types.Blocks {
|
||||||
|
c1, err := ethutil.ReadAllFile(path.Join("..", "_data", fn))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
data1, _ := ethutil.Decode([]byte(c1), 0)
|
value := ethutil.NewValueFromBytes([]byte(c1))
|
||||||
fmt.Println(data1)
|
blocks := make(types.Blocks, value.Len())
|
||||||
|
it := value.NewIterator()
|
||||||
|
for it.Next() {
|
||||||
|
blocks[it.Idx()] = types.NewBlockFromRlpValue(it.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertChain(done chan bool, chainMan *ChainManager, chain types.Blocks, t *testing.T) {
|
||||||
|
err := chainMan.InsertChain(chain)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
done <- true
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChainInsertions(t *testing.T) {
|
||||||
|
chain1 := loadChain("chain1", t)
|
||||||
|
chain2 := loadChain("chain2", t)
|
||||||
|
var eventMux event.TypeMux
|
||||||
|
chainMan := NewChainManager(&eventMux)
|
||||||
|
txPool := NewTxPool(chainMan, nil, &eventMux)
|
||||||
|
blockMan := NewBlockManager(txPool, chainMan, &eventMux)
|
||||||
|
chainMan.SetProcessor(blockMan)
|
||||||
|
|
||||||
|
const max = 2
|
||||||
|
done := make(chan bool, max)
|
||||||
|
|
||||||
|
go insertChain(done, chainMan, chain1, t)
|
||||||
|
go insertChain(done, chainMan, chain2, t)
|
||||||
|
|
||||||
|
for i := 0; i < max; i++ {
|
||||||
|
<-done
|
||||||
|
}
|
||||||
|
fmt.Println(chainMan.CurrentBlock())
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,11 @@ func (self *Filter) SetSkip(skip int) {
|
|||||||
func (self *Filter) Find() []*state.Message {
|
func (self *Filter) Find() []*state.Message {
|
||||||
var earliestBlockNo uint64 = uint64(self.earliest)
|
var earliestBlockNo uint64 = uint64(self.earliest)
|
||||||
if self.earliest == -1 {
|
if self.earliest == -1 {
|
||||||
earliestBlockNo = self.eth.ChainManager().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.ChainManager().CurrentBlock.Number.Uint64()
|
latestBlockNo = self.eth.ChainManager().CurrentBlock().Number.Uint64()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1,7 +1 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
// import "testing"
|
|
||||||
|
|
||||||
// func TestFilter(t *testing.T) {
|
|
||||||
// NewFilter(NewTestManager())
|
|
||||||
// }
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
@ -57,7 +58,6 @@ type TxProcessor interface {
|
|||||||
// pool is being drained or synced for whatever reason the transactions
|
// pool is being drained or synced for whatever reason the transactions
|
||||||
// will simple queue up and handled when the mutex is freed.
|
// will simple queue up and handled when the mutex is freed.
|
||||||
type TxPool struct {
|
type TxPool struct {
|
||||||
Ethereum EthManager
|
|
||||||
// The mutex for accessing the Tx pool.
|
// The mutex for accessing the Tx pool.
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
// Queueing channel for reading and writing incoming
|
// Queueing channel for reading and writing incoming
|
||||||
@ -71,14 +71,20 @@ type TxPool struct {
|
|||||||
SecondaryProcessor TxProcessor
|
SecondaryProcessor TxProcessor
|
||||||
|
|
||||||
subscribers []chan TxMsg
|
subscribers []chan TxMsg
|
||||||
|
|
||||||
|
broadcaster types.Broadcaster
|
||||||
|
chainManager *ChainManager
|
||||||
|
eventMux *event.TypeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTxPool(ethereum EthManager) *TxPool {
|
func NewTxPool(chainManager *ChainManager, broadcaster types.Broadcaster, eventMux *event.TypeMux) *TxPool {
|
||||||
return &TxPool{
|
return &TxPool{
|
||||||
pool: list.New(),
|
pool: list.New(),
|
||||||
queueChan: make(chan *types.Transaction, txPoolQueueSize),
|
queueChan: make(chan *types.Transaction, txPoolQueueSize),
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
Ethereum: ethereum,
|
chainManager: chainManager,
|
||||||
|
eventMux: eventMux,
|
||||||
|
broadcaster: broadcaster,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +102,7 @@ func (pool *TxPool) addTransaction(tx *types.Transaction) {
|
|||||||
func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
|
func (pool *TxPool) ValidateTransaction(tx *types.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.ChainManager().CurrentBlock
|
block := pool.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("No last block on the block chain")
|
return fmt.Errorf("No last block on the block chain")
|
||||||
@ -112,7 +118,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the sender
|
// Get the sender
|
||||||
sender := pool.Ethereum.ChainManager().State().GetAccount(tx.Sender())
|
sender := pool.chainManager.State().GetAccount(tx.Sender())
|
||||||
|
|
||||||
totAmount := new(big.Int).Set(tx.Value)
|
totAmount := new(big.Int).Set(tx.Value)
|
||||||
// Make sure there's enough in the sender's account. Having insufficient
|
// Make sure there's enough in the sender's account. Having insufficient
|
||||||
@ -156,7 +162,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
|
|||||||
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
|
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
|
||||||
|
|
||||||
// Notify the subscribers
|
// Notify the subscribers
|
||||||
go self.Ethereum.EventMux().Post(TxPreEvent{tx})
|
go self.eventMux.Post(TxPreEvent{tx})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ func (self *Block) Size() ethutil.StorageSize {
|
|||||||
|
|
||||||
// Implement RlpEncodable
|
// Implement RlpEncodable
|
||||||
func (self *Block) RlpData() interface{} {
|
func (self *Block) RlpData() interface{} {
|
||||||
return self.Value().Val
|
return []interface{}{self.header(), self.transactions, self.rlpUncles()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement pow.Block
|
// Implement pow.Block
|
||||||
|
@ -4,8 +4,13 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
|
"github.com/ethereum/go-ethereum/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockProcessor interface {
|
type BlockProcessor interface {
|
||||||
Process(*Block) (*big.Int, state.Messages, error)
|
Process(*Block) (*big.Int, state.Messages, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Broadcaster interface {
|
||||||
|
Broadcast(wire.MsgType, []interface{})
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@ package ethutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -193,8 +192,13 @@ func Encode(object interface{}) []byte {
|
|||||||
if blen < 56 {
|
if blen < 56 {
|
||||||
buff.WriteByte(byte(blen) + 0xc0)
|
buff.WriteByte(byte(blen) + 0xc0)
|
||||||
} else {
|
} else {
|
||||||
buff.WriteByte(byte(intlen(int64(blen))) + 0xf7)
|
ilen := byte(intlen(int64(blen)))
|
||||||
binary.Write(&buff, binary.BigEndian, int64(blen))
|
buff.WriteByte(ilen + 0xf7)
|
||||||
|
t := make([]byte, ilen)
|
||||||
|
for i := byte(0); i < ilen; i++ {
|
||||||
|
t[ilen-i-1] = byte(blen >> (i * 8))
|
||||||
|
}
|
||||||
|
buff.Write(t)
|
||||||
}
|
}
|
||||||
buff.ReadFrom(&b)
|
buff.ReadFrom(&b)
|
||||||
}
|
}
|
||||||
|
@ -397,5 +397,5 @@ func (it *ValueIterator) Value() *Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (it *ValueIterator) Idx() int {
|
func (it *ValueIterator) Idx() int {
|
||||||
return it.idx
|
return it.idx - 1
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ type EasyPow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New() *EasyPow {
|
func New() *EasyPow {
|
||||||
return &EasyPow{}
|
return &EasyPow{turbo: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pow *EasyPow) GetHashrate() int64 {
|
func (pow *EasyPow) GetHashrate() int64 {
|
||||||
|
@ -28,7 +28,7 @@ func (self *JSXEth) BlockByHash(strHash string) *JSBlock {
|
|||||||
|
|
||||||
func (self *JSXEth) BlockByNumber(num int32) *JSBlock {
|
func (self *JSXEth) BlockByNumber(num int32) *JSBlock {
|
||||||
if num == -1 {
|
if num == -1 {
|
||||||
return NewJSBlock(self.obj.ChainManager().CurrentBlock)
|
return NewJSBlock(self.obj.ChainManager().CurrentBlock())
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num)))
|
return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num)))
|
||||||
|
@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V
|
|||||||
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
|
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
|
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
|
||||||
block = self.chainManager.CurrentBlock
|
block = self.chainManager.CurrentBlock()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.Vm.State = self.World().State().Copy()
|
self.Vm.State = self.World().State().Copy()
|
||||||
|
Loading…
Reference in New Issue
Block a user