Skip to content

Commit

Permalink
Merge 989f9c2 into a21c81a
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis88 committed Sep 2, 2019
2 parents a21c81a + 989f9c2 commit 27a0eb4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
3 changes: 3 additions & 0 deletions consensus/dpos/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (api *API) ValidCandidates(epoch uint64) (interface{}, error) {
return sys.GetState(gstate.PreEpoch)
}

// BrowserAllEpoch get all epoch info for browser api
func (api *API) BrowserAllEpoch() (interface{}, error) {
epochs := Epochs{}
epochs.Data = make([]*Epoch, 0)
Expand Down Expand Up @@ -248,6 +249,7 @@ func (api *API) BrowserAllEpoch() (interface{}, error) {
return epochs, nil
}

// BrowserEpochRecord get epoch info for browser api
func (api *API) BrowserEpochRecord(reqEpochNumber uint64) (interface{}, error) {
bstart := time.Now()
var req, data uint64
Expand Down Expand Up @@ -350,6 +352,7 @@ func (api *API) BrowserEpochRecord(reqEpochNumber uint64) (interface{}, error) {
return candidateInfos, nil
}

// BrowserVote get epoch info for browser api
func (api *API) BrowserVote(reqEpochNumber uint64) (interface{}, error) {
var req, history uint64
bstart := time.Now()
Expand Down
1 change: 1 addition & 0 deletions consensus/dpos/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (cfg *Config) minBlockCnt() uint64 {
return cfg.minMEpoch() * cfg.BlockFrequency * cfg.CandidateScheduleSize
}

// IsValid config validate
func (cfg *Config) IsValid() error {
if minEpochInterval := 2 * cfg.minBlockCnt() * cfg.blockInterval(); cfg.epochInterval() < minEpochInterval {
return fmt.Errorf("epoch interval %v invalid (min epoch interval %v)", cfg.epochInterval(), minEpochInterval)
Expand Down
9 changes: 9 additions & 0 deletions consensus/dpos/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ type IDB interface {
GetCandidateInfoByTime(epoch uint64, name string, timestamp uint64) (*CandidateInfo, error)
}

// CandidateType candiate status
type CandidateType uint64

const (
// Normal reg
Normal CandidateType = iota
// Freeze unreg bug not del
Freeze
// Black in black list
Black
// Jail in jail list
Jail
// Unkown not support
Unkown
)

Expand Down Expand Up @@ -166,6 +172,7 @@ func (voter *VoterInfo) key() string {
}

var (
// InvalidIndex magic number
InvalidIndex = uint64(math.MaxUint64)
)

Expand Down Expand Up @@ -209,10 +216,12 @@ type CandidateInfoForBrowser struct {
// CandidateInfoArray array of candidate
type CandidateInfoArray []*CandidateInfo

// Epochs array of epcho
type Epochs struct {
Data []*Epoch `json:"data"`
}

// Epoch timestamp & epoch number
type Epoch struct {
Start uint64 `json:"start"`
Epoch uint64 `json:"epoch"`
Expand Down
24 changes: 14 additions & 10 deletions consensus/dpos/dpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ import (
)

var (
errMissingSignature = errors.New("extra-data 65 byte suffix signature missing")
errInvalidMintBlockTime = errors.New("invalid time to mint the block")
errInvalidBlockCandidate = errors.New("invalid block candidate")
errInvalidTimestamp = errors.New("invalid timestamp")
ErrIllegalCandidateName = errors.New("illegal candidate name")
errMissingSignature = errors.New("extra-data 65 byte suffix signature missing")
errInvalidMintBlockTime = errors.New("invalid time to mint the block")
errInvalidBlockCandidate = errors.New("invalid block candidate")
errInvalidTimestamp = errors.New("invalid timestamp")
// ErrIllegalCandidateName not exist
ErrIllegalCandidateName = errors.New("illegal candidate name")
// ErrIllegalCandidatePubKey mismatch public key
ErrIllegalCandidatePubKey = errors.New("illegal candidate pubkey")
ErrTooMuchRreversible = errors.New("too much rreversible blocks")
ErrSystemTakeOver = errors.New("system account take over")
errUnknownBlock = errors.New("unknown block")
extraSeal = 65
timeOfGenesisBlock int64
// ErrTooMuchRreversible too much rreversible blocks
ErrTooMuchRreversible = errors.New("too much rreversible blocks")
// ErrSystemTakeOver system taking over
ErrSystemTakeOver = errors.New("system account take over")
errUnknownBlock = errors.New("unknown block")
extraSeal = 65
timeOfGenesisBlock int64
)

type stateDB struct {
Expand Down
4 changes: 2 additions & 2 deletions consensus/dpos/ldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ func TestLDBTakeOver(t *testing.T) {
panic(fmt.Errorf("GetTakeOver mismatch"))
}
// return 0 when not set
if z_epoch, err := db.GetTakeOver(); err != nil {
if zepoch, err := db.GetTakeOver(); err != nil {
panic(fmt.Errorf("Zero GetTakeOver --- %v", err))
} else if z_epoch != epoch {
} else if zepoch != epoch {
panic(fmt.Errorf("Zero GetTakeOver mismatch"))
}

Expand Down

0 comments on commit 27a0eb4

Please sign in to comment.