Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis88 committed Mar 19, 2019
1 parent 26a46c7 commit 364a0c1
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 1,522 deletions.
33 changes: 33 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package blockchain

import (
"fmt"
"io"
"math/big"
mrand "math/rand"
"sync"
Expand Down Expand Up @@ -1010,3 +1011,35 @@ func (bc *BlockChain) CalcGasLimit(parent *types.Block) uint64 {
func (bc *BlockChain) ForkUpdate(block *types.Block, statedb *state.StateDB) error {
return bc.fcontroller.update(block, statedb)
}

// Export writes the active chain to the given writer.
func (bc *BlockChain) Export(w io.Writer) error {
return bc.ExportN(w, uint64(0), bc.CurrentBlock().NumberU64())
}

// ExportN writes a subset of the active chain to the given writer.
func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
bc.chainmu.RLock()
defer bc.chainmu.RUnlock()

if first > last {
return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last)
}
log.Info("Exporting batch of blocks", "count", last-first+1)

start, reported := time.Now(), time.Now()
for nr := first; nr <= last; nr++ {
block := bc.GetBlockByNumber(nr)
if block == nil {
return fmt.Errorf("export failed on #%d: not found", nr)
}
if err := block.ExtEncodeRLP(w); err != nil {
return err
}
if time.Since(reported) >= 8*time.Second {
log.Info("Exporting blocks", "exported", block.NumberU64()-first, "elapsed", common.PrettyDuration(time.Since(start)))
reported = time.Now()
}
}
return nil
}
4 changes: 2 additions & 2 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package blockchain

// import (
// "testing"
import (
"testing"

"github.com/ethereum/go-ethereum/log"
"github.com/fractalplatform/fractal/params"
Expand Down
31 changes: 28 additions & 3 deletions blockchain/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/fractalplatform/fractal/utils/fdb"
)

var defaultgenesisBlockHash = common.HexToHash("0xa593e2eb387413dedcd631239a6271cae71d373f52925bf3e79b897bc97a90f8")
var defaultgenesisBlockHash = common.HexToHash("0x364bd3992fab22d8ef84f1168042e942585aa4990d2a4b0b280b379e254f164a")

func TestDefaultGenesisBlock(t *testing.T) {
block := DefaultGenesis().ToBlock(nil)
Expand All @@ -41,7 +41,7 @@ func TestDefaultGenesisBlock(t *testing.T) {

func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0x14c45c9bd85c97f2cc51c3cc7ef2d22da251054d1a48abbd2990526dc2560bf0")
customghash = common.HexToHash("0x4a8fbed6696cf57ae8081e9d17a1b4518f26075d7f6602912329561bcfdd5c35")
customg = Genesis{
Config: &params.ChainConfig{ChainID: big.NewInt(3), SysName: "systemio", SysToken: "fractalfoundation"},
Dpos: dpos.DefaultConfig,
Expand All @@ -50,7 +50,32 @@ func TestSetupGenesis(t *testing.T) {
AllocAssets: DefaultGenesisAssets(),
}
oldcustomg = customg
oldcustomghash = common.HexToHash("0x3c2adfd707667a4a69f4d61da4191941b83bbf6355bef6d9248ee7db57927b7a")
oldcustomghash = common.HexToHash("768c8e4e507b3d691c2b85e5cdc912ba06829ee72d373b3724159e61f32731c6")
dposConfig = &dpos.Config{
MaxURLLen: 512,
UnitStake: big.NewInt(1000),
CadidateMinQuantity: big.NewInt(10),
VoterMinQuantity: big.NewInt(1),
ActivatedMinQuantity: big.NewInt(100),
BlockInterval: 3000,
BlockFrequency: 6,
CadidateScheduleSize: 3,
DelayEcho: 2,
AccountName: "ftsystemdpos",
SystemName: "ftsystemio",
SystemURL: "www.fractalproject.com",
ExtraBlockReward: big.NewInt(1),
BlockReward: big.NewInt(5),
Decimals: 18,
}

chainConfig = &params.ChainConfig{
ChainID: big.NewInt(1),
SysName: "ftsystemio",
SysToken: "ftoken",
AssetChargeRatio: 80,
ContractChargeRatio: 80,
}
)
oldcustomg.Config = &params.ChainConfig{ChainID: big.NewInt(2), SysName: "ftsystem", SysToken: "ftoken"}

Expand Down

0 comments on commit 364a0c1

Please sign in to comment.