Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

共识错误 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions consensus/alien/alien.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,18 @@ func (a *Alien) Prepare(chain consensus.ChainReader, header *types.Header) error

// Set the correct difficulty
header.Difficulty = new(big.Int).Set(defaultDifficulty)

number := header.Number.Uint64()

parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil {
return consensus.ErrUnknownAncestor
}
header.Time = new(big.Int).Add(parent.Time, new(big.Int).SetUint64(a.config.Period))
if header.Time.Int64() < time.Now().Unix() {
header.Time = big.NewInt(time.Now().Unix())
}

// If now is later than genesis timestamp, skip prepare
if a.config.GenesisTimestamp < uint64(time.Now().Unix()) {
return nil
Expand Down Expand Up @@ -743,20 +755,11 @@ func (a *Alien) mcConfirmBlock(chain consensus.ChainReader, header *types.Header
// rewards given, and returns the final block.
func (a *Alien) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {

number := header.Number.Uint64()

// Mix digest is reserved for now, set to empty
header.MixDigest = common.Hash{}

// Ensure the timestamp has the correct delay
parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil {
return nil, consensus.ErrUnknownAncestor
}
header.Time = new(big.Int).Add(parent.Time, new(big.Int).SetUint64(a.config.Period))
if header.Time.Int64() < time.Now().Unix() {
header.Time = big.NewInt(time.Now().Unix())
}


// Ensure the extra data has all it's components
if len(header.Extra) < extraVanity {
Expand Down
2 changes: 1 addition & 1 deletion consensus/alien/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ func (s *Snapshot) updateSnapshotByVotes(votes []Vote, headerNumber *big.Int) {
}

s.Votes[vote.Voter] = &Vote{vote.Voter, vote.Candidate, new(big.Int).Set(vote.Stake)}
s.Voters[vote.Voter] = headerNumber
s.Voters[vote.Voter] = new(big.Int).Set(headerNumber)
}
}

Expand Down