Skip to content

Commit

Permalink
Merge b92f562 into 28891ca
Browse files Browse the repository at this point in the history
  • Loading branch information
findbug2019 committed May 18, 2019
2 parents 28891ca + b92f562 commit 0d3b170
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type IEngine interface {

GetActivedCandidateSize(state *state.StateDB, epoch uint64) (size uint64, err error)

GetActivedCandidate(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)
GetActivedCandidate(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, totalVote *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)

GetCandidateStake(state *state.StateDB, epoch uint64, candidate string) (stake *big.Int, err error)

Expand Down
12 changes: 6 additions & 6 deletions consensus/dpos/dpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,25 +453,25 @@ func (dpos *Dpos) GetActivedCandidateSize(state *state.StateDB, epcho uint64) (u
}

// GetActivedCandidate get actived candidate info
func (dpos *Dpos) GetActivedCandidate(state *state.StateDB, epcho uint64, index uint64) (string, *big.Int, uint64, uint64, uint64, error) {
func (dpos *Dpos) GetActivedCandidate(state *state.StateDB, epcho uint64, index uint64) (string, *big.Int, *big.Int, uint64, uint64, uint64, error) {
sys := NewSystem(state, dpos.config)
gstate, err := sys.GetState(epcho)
if err != nil {
return "", big.NewInt(0), 0, 0, 0, err
return "", big.NewInt(0), big.NewInt(0), 0, 0, 0, err
}
if index >= uint64(len(gstate.ActivatedCandidateSchedule)) {
return "", big.NewInt(0), 0, 0, 0, fmt.Errorf("out of index")
return "", big.NewInt(0), big.NewInt(0), 0, 0, 0, fmt.Errorf("out of index")
}

candidate := gstate.ActivatedCandidateSchedule[index]
prevCandidateInfo, err := sys.GetCandidateInfoByTime(candidate, dpos.config.epochTimeStamp(gstate.PreEpcho))
if err != nil {
return "", big.NewInt(0), 0, 0, 0, err
return "", big.NewInt(0), big.NewInt(0), 0, 0, 0, err
}

candidateInfo, err := sys.GetCandidateInfoByTime(candidate, dpos.config.epochTimeStamp(gstate.Epcho))
if err != nil {
return "", big.NewInt(0), 0, 0, 0, err
return "", big.NewInt(0), big.NewInt(0), 0, 0, 0, err
}

counter := candidateInfo.Counter
Expand All @@ -486,7 +486,7 @@ func (dpos *Dpos) GetActivedCandidate(state *state.StateDB, epcho uint64, index
rindex = gstate.OffCandidateSchedule[index-dpos.config.CandidateScheduleSize]
}

return candidate, new(big.Int).Mul(candidateInfo.Quantity, sys.config.unitStake()), counter, actualCounter, rindex, err
return candidate, new(big.Int).Mul(candidateInfo.Quantity, sys.config.unitStake()), candidateInfo.TotalQuantity, counter, actualCounter, rindex, err
}

// GetCandidateStake candidate delegate stake
Expand Down
2 changes: 1 addition & 1 deletion processor/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type EngineContext interface {

GetActivedCandidateSize(state *state.StateDB, epoch uint64) (size uint64, err error)

GetActivedCandidate(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)
GetActivedCandidate(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, totalVote *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)

GetVoterStake(state *state.StateDB, epoch uint64, voter string, candidate string) (stake *big.Int, err error)
}
Expand Down
42 changes: 21 additions & 21 deletions processor/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,31 +1058,31 @@ func opGetCandidateNum(pc *uint64, evm *EVM, contract *Contract, memory *Memory,

// opGetCandidate
func opGetCandidate(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
nameOffset, nameSize, index, epochID := stack.pop(), stack.pop(), stack.pop(), stack.pop()
index, epochID := stack.pop(), stack.pop()
id := epochID.Uint64()
i := index.Uint64()
//
name, stake, counter, actualCounter, replace, err := evm.Context.GetActivedCandidate(evm.StateDB, id, i)
nameBytes := []byte(name)
datalen := len(nameBytes)
if uint64(datalen) > nameSize.Uint64()*32 {
err = errors.New("out of space")
}
if err != nil {
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
//don't copy
} else {
stack.push(evm.interpreter.intPool.get().SetUint64(replace))
stack.push(evm.interpreter.intPool.get().SetUint64(actualCounter))
stack.push(evm.interpreter.intPool.get().SetUint64(counter))
stack.push(evm.interpreter.intPool.get().Set(stake))
stack.push(evm.interpreter.intPool.get().SetUint64(uint64(datalen)))
memory.Set(nameOffset.Uint64(), uint64(datalen), nameBytes)
name, stake, totalVote, counter, actualCounter, replace, err := evm.Context.GetActivedCandidate(evm.StateDB, id, i)
//
if err == nil {
id, err := evm.AccountDB.GetAccountIDByName(common.Name(name))
if err == nil {
stack.push(evm.interpreter.intPool.get().SetUint64(replace))
stack.push(evm.interpreter.intPool.get().SetUint64(actualCounter))
stack.push(evm.interpreter.intPool.get().SetUint64(counter))
stack.push(evm.interpreter.intPool.get().SetUint64(totalVote.Uint64()))
stack.push(evm.interpreter.intPool.get().Set(stake))
stack.push(evm.interpreter.intPool.get().SetUint64(id))
return nil, nil
}
}

stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
stack.push(evm.interpreter.intPool.getZero())
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions processor/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func NewEnv(cfg *Config) *vm.EVM {
return 3, nil
},
//GetActivedCandidate
GetActivedCandidate: func(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, counter uint64, actualCounter uint64, replace uint64, err error) {
return "testname", big.NewInt(3), 3, 3, 3, nil
GetActivedCandidate: func(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, totalVote *big.Int, counter uint64, actualCounter uint64, replace uint64, err error) {
return "testname", big.NewInt(0), big.NewInt(3), 3, 3, 3, nil
},

//GetVoterStake
Expand Down
2 changes: 1 addition & 1 deletion processor/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type (
//GetActivedCandidateSize
GetActivedCandidateSizeFunc func(state *state.StateDB, epoch uint64) (size uint64, err error)
//GetActivedCandidate
GetActivedCandidateFunc func(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)
GetActivedCandidateFunc func(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, votes *big.Int, counter uint64, actualCounter uint64, replace uint64, err error)
//GetVoterStake
GetVoterStakeFunc func(state *state.StateDB, epoch uint64, voter string, candidate string) (stake *big.Int, err error)
// GetHeaderByNumberFunc
Expand Down

0 comments on commit 0d3b170

Please sign in to comment.