PoC 6 networking code.

* Added block pool for gathering blocks from the network (chunks)
* Re wrote syncing
This commit is contained in:
obscuren
2014-08-21 14:47:58 +02:00
parent 79c64f6bca
commit eaa2e8900d
7 changed files with 296 additions and 197 deletions

View File

@@ -208,6 +208,26 @@ func (bc *BlockChain) GenesisBlock() *Block {
return bc.genesisBlock
}
func (self *BlockChain) 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
}
// Get chain return blocks from hash up to max in RLP format
func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} {
var chain []interface{}

View File

@@ -1,9 +1,10 @@
package ethchain
import (
"math/big"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
/*
@@ -26,7 +27,8 @@ var GenesisHeader = []interface{}{
// tx sha
"",
// Difficulty
ethutil.BigPow(2, 22),
//ethutil.BigPow(2, 22),
big.NewInt(4096),
// Number
ethutil.Big0,
// Block minimum gas price