Skip to content

Commit

Permalink
candidate info saved by epoch & rpc api
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis88 committed Jun 1, 2019
1 parent e5c1210 commit ed3217f
Show file tree
Hide file tree
Showing 21 changed files with 613 additions and 673 deletions.
10 changes: 6 additions & 4 deletions blockchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func dposConfig(cfg *params.ChainConfig) *dpos.Config {
BlockFrequency: cfg.DposCfg.BlockFrequency,
CandidateScheduleSize: cfg.DposCfg.CandidateScheduleSize,
BackupScheduleSize: cfg.DposCfg.BackupScheduleSize,
EpchoInterval: cfg.DposCfg.EpchoInterval,
FreezeEpchoSize: cfg.DposCfg.FreezeEpchoSize,
EpochInterval: cfg.DposCfg.EpochInterval,
FreezeEpochSize: cfg.DposCfg.FreezeEpochSize,
AccountName: cfg.DposName,
SystemName: cfg.SysName,
SystemURL: cfg.ChainURL,
Expand Down Expand Up @@ -351,8 +351,10 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
g.Config.SysTokenDecimals = assetInfo.Decimals

sys := dpos.NewSystem(statedb, dposConfig(g.Config))
epoch, _ := sys.GetLastestEpoch()
for _, candidate := range g.AllocCandidates {
if err := sys.SetCandidate(&dpos.CandidateInfo{
Epoch: epoch,
Name: candidate.Name,
URL: candidate.URL,
Quantity: big.NewInt(0),
Expand All @@ -362,7 +364,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
panic(fmt.Sprintf("genesis create candidate err %v", err))
}
}
if err := sys.UpdateElectedCandidates(dpos.LastEpcho, dpos.LastEpcho, number.Uint64(), ""); err != nil {
if err := sys.UpdateElectedCandidates(epoch, epoch, number.Uint64(), ""); err != nil {
panic(fmt.Sprintf("genesis create candidate err %v", err))
}

Expand Down Expand Up @@ -394,7 +396,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
GasLimit: g.GasLimit,
GasUsed: 0,
Difficulty: g.Difficulty,
Coinbase: common.StrToName(g.Config.SysName),
Coinbase: common.StrToName(g.Config.ChainName),
Root: root,
}

Expand Down
6 changes: 3 additions & 3 deletions blockchain/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
memdb "github.com/fractalplatform/fractal/utils/fdb/memdb"
)

var defaultgenesisBlockHash = common.HexToHash("0x057061a2fa8ae022068406f03598d3c154e9558247d996250ae9d7ce5a2adb86")
var defaultgenesisBlockHash = common.HexToHash("0x2889c5a29bf59a78369adee64b052f8e8afe1322fed448b6fbba64c9ae30cbf9")

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

func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0xa392fbabcc9fd548e232b07d5cf1ae9dbc2b9b32ed0f1094caead3a4a5bf1ad7")
customghash = common.HexToHash("0x6ad1c40b2575e50286ca4d03dbb21028c45d3a7a2c25da4474c2e191840f5c03")

customg = Genesis{
Config: params.DefaultChainconfig.Copy(),
Expand All @@ -53,7 +53,7 @@ func TestSetupGenesis(t *testing.T) {
}
oldcustomg = customg

oldcustomghash = common.HexToHash("cc360f77443e60e699a098be39154375997acb3fc11ddbb14f9f95542052cbaf")
oldcustomghash = common.HexToHash("17666dcb4a86c1fe198d5ab9eb1fe23a292b66f4bd022763bb9a0f50e32ae467")
)
customg.Config.ChainID = big.NewInt(5)
oldcustomg.Config = customg.Config.Copy()
Expand Down
2 changes: 1 addition & 1 deletion blockchain/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func makeSystemCandidatesAndTime(parentTime uint64, genesis *Genesis) ([]string,
baseCandidates = getCandidates()
)
dcfg := dposConfig(genesis.Config)
for i := uint64(0); i < (dcfg.EpchoInterval/dcfg.BlockInterval*dcfg.BlockFrequency)+1; i++ {
for i := uint64(0); i < (dcfg.EpochInterval/dcfg.BlockInterval*dcfg.BlockFrequency)+1; i++ {
for j := 0; j < len(baseCandidates); j++ {
for k := 0; k < int(genesis.Config.DposCfg.BlockFrequency); k++ {
candidates = append(candidates, genesis.Config.SysName)
Expand Down
4 changes: 2 additions & 2 deletions build/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"blockFrequency": 6,
"candidateScheduleSize": 3,
"backupScheduleSize": 0,
"epchoInterval": 10800000,
"freezeEpchoSize": 3,
"epochInterval": 10800000,
"freezeEpochSize": 3,
"extraBlockReward": 1,
"blockReward": 5
},
Expand Down
4 changes: 2 additions & 2 deletions build/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"blockFrequency": 6,
"candidateScheduleSize": 21,
"backupScheduleSize": 0,
"epchoInterval": 21600000,
"freezeEpchoSize": 3,
"epochInterval": 21600000,
"freezeEpochSize": 3,
"extraBlockReward": 1,
"blockReward": 5
},
Expand Down
Loading

0 comments on commit ed3217f

Please sign in to comment.