mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
consensus: fix unused warnings (#1815)
This commit is contained in:
parent
0c2b0f3234
commit
0ef3edf183
5 changed files with 0 additions and 153 deletions
|
|
@ -10,23 +10,6 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// get epoch switch of the previous `limit` epoch
|
|
||||||
func (x *XDPoS_v2) getPreviousEpochSwitchInfoByHash(chain consensus.ChainReader, hash common.Hash, limit int) (*types.EpochSwitchInfo, error) {
|
|
||||||
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, nil, hash)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[getPreviousEpochSwitchInfoByHash] Adaptor v2 getEpochSwitchInfo has error, potentially bug", "err", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for i := 0; i < limit; i++ {
|
|
||||||
epochSwitchInfo, err = x.getEpochSwitchInfo(chain, nil, epochSwitchInfo.EpochSwitchParentBlockInfo.Hash)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[getPreviousEpochSwitchInfoByHash] Adaptor v2 getEpochSwitchInfo has error, potentially bug", "err", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return epochSwitchInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given header and its hash, get epoch switch info from the epoch switch block of that epoch,
|
// Given header and its hash, get epoch switch info from the epoch switch block of that epoch,
|
||||||
// header is allow to be nil.
|
// header is allow to be nil.
|
||||||
func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types.Header, hash common.Hash) (*types.EpochSwitchInfo, error) {
|
func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types.Header, hash common.Hash) (*types.EpochSwitchInfo, error) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
|
@ -201,65 +200,6 @@ func (f *Forensics) SendForensicProof(chain consensus.ChainReader, engine *XDPoS
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utils function to help find the n-th previous QC. It returns an array of QC in ascending order including the currentQc as the last item in the array
|
|
||||||
func (f *Forensics) findAncestorQCs(chain consensus.ChainReader, currentQc types.QuorumCert, distanceFromCurrrentQc int) ([]types.QuorumCert, error) {
|
|
||||||
var quorumCerts []types.QuorumCert
|
|
||||||
quorumCertificate := currentQc
|
|
||||||
// Append the initial value
|
|
||||||
quorumCerts = append(quorumCerts, quorumCertificate)
|
|
||||||
// Append the parents
|
|
||||||
for i := 0; i < distanceFromCurrrentQc; i++ {
|
|
||||||
parentHash := quorumCertificate.ProposedBlockInfo.Hash
|
|
||||||
parentHeader := chain.GetHeaderByHash(parentHash)
|
|
||||||
if parentHeader == nil {
|
|
||||||
log.Error("[findAncestorQCs] Forensics findAncestorQCs unable to find its parent block header", "ParentHash", parentHash.Hex())
|
|
||||||
return nil, errors.New("unable to find parent block header in forensics")
|
|
||||||
}
|
|
||||||
var decodedExtraField types.ExtraFields_v2
|
|
||||||
err := utils.DecodeBytesExtraFields(parentHeader.Extra, &decodedExtraField)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[findAncestorQCs] Error while trying to decode from parent block extra", "BlockNum", parentHeader.Number.Int64(), "ParentHash", parentHash.Hex())
|
|
||||||
}
|
|
||||||
quorumCertificate = *decodedExtraField.QuorumCert
|
|
||||||
quorumCerts = append(quorumCerts, quorumCertificate)
|
|
||||||
}
|
|
||||||
// The quorumCerts is in the reverse order, we need to flip it
|
|
||||||
var quorumCertsInAscendingOrder []types.QuorumCert
|
|
||||||
for i := len(quorumCerts) - 1; i >= 0; i-- {
|
|
||||||
quorumCertsInAscendingOrder = append(quorumCertsInAscendingOrder, quorumCerts[i])
|
|
||||||
}
|
|
||||||
return quorumCertsInAscendingOrder, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether two provided QC set are on the same chain
|
|
||||||
func (f *Forensics) checkQCsOnTheSameChain(chain consensus.ChainReader, highestCommittedQCs []types.QuorumCert, incomingQCandItsParents []types.QuorumCert) (bool, error) {
|
|
||||||
// Re-order two sets of QCs by block Number
|
|
||||||
lowerBlockNumQCs := highestCommittedQCs
|
|
||||||
higherBlockNumQCs := incomingQCandItsParents
|
|
||||||
if incomingQCandItsParents[0].ProposedBlockInfo.Number.Cmp(highestCommittedQCs[0].ProposedBlockInfo.Number) == -1 {
|
|
||||||
lowerBlockNumQCs = incomingQCandItsParents
|
|
||||||
higherBlockNumQCs = highestCommittedQCs
|
|
||||||
}
|
|
||||||
|
|
||||||
proposedBlockInfo := higherBlockNumQCs[0].ProposedBlockInfo
|
|
||||||
for i := 0; i < int((big.NewInt(0).Sub(higherBlockNumQCs[0].ProposedBlockInfo.Number, lowerBlockNumQCs[0].ProposedBlockInfo.Number)).Int64()); i++ {
|
|
||||||
parentHeader := chain.GetHeaderByHash(proposedBlockInfo.Hash)
|
|
||||||
var decodedExtraField types.ExtraFields_v2
|
|
||||||
err := utils.DecodeBytesExtraFields(parentHeader.Extra, &decodedExtraField)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[checkQCsOnTheSameChain] Fail to decode extra when checking the two QCs set on the same chain", "err", err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
proposedBlockInfo = decodedExtraField.QuorumCert.ProposedBlockInfo
|
|
||||||
}
|
|
||||||
// Check the final proposed blockInfo is the same as what we have from lowerBlockNumQCs[0]
|
|
||||||
if reflect.DeepEqual(proposedBlockInfo, lowerBlockNumQCs[0].ProposedBlockInfo) {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given the two QCs set, find if there are any QC that have the same round
|
// Given the two QCs set, find if there are any QC that have the same round
|
||||||
func (f *Forensics) findQCsInSameRound(quorumCerts1 []types.QuorumCert, quorumCerts2 []types.QuorumCert) (bool, types.QuorumCert, types.QuorumCert) {
|
func (f *Forensics) findQCsInSameRound(quorumCerts1 []types.QuorumCert, quorumCerts2 []types.QuorumCert) (bool, types.QuorumCert, types.QuorumCert) {
|
||||||
for _, quorumCert1 := range quorumCerts1 {
|
for _, quorumCert1 := range quorumCerts1 {
|
||||||
|
|
@ -294,37 +234,6 @@ func (f *Forensics) getQcSignerAddresses(quorumCert types.QuorumCert) []string {
|
||||||
return signerList
|
return signerList
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the given QCs are on the same chain as the stored committed QCs(f.HighestCommittedQCs) regardless their orders
|
|
||||||
func (f *Forensics) findAncestorQcThroughRound(chain consensus.ChainReader, highestCommittedQCs []types.QuorumCert, incomingQCandItsParents []types.QuorumCert) (types.QuorumCert, []types.QuorumCert, []types.QuorumCert, error) {
|
|
||||||
/*
|
|
||||||
Re-order two sets of QCs by Round number
|
|
||||||
*/
|
|
||||||
lowerRoundQCs := highestCommittedQCs
|
|
||||||
higherRoundQCs := incomingQCandItsParents
|
|
||||||
if incomingQCandItsParents[0].ProposedBlockInfo.Round < highestCommittedQCs[0].ProposedBlockInfo.Round {
|
|
||||||
lowerRoundQCs = incomingQCandItsParents
|
|
||||||
higherRoundQCs = highestCommittedQCs
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the ancestorFromIncomingQC1 that matches round number < lowerRoundQCs3
|
|
||||||
ancestorQC := higherRoundQCs[0]
|
|
||||||
for ancestorQC.ProposedBlockInfo.Round >= lowerRoundQCs[NUM_OF_FORENSICS_QC-1].ProposedBlockInfo.Round {
|
|
||||||
proposedBlock := chain.GetHeaderByHash(ancestorQC.ProposedBlockInfo.Hash)
|
|
||||||
var decodedExtraField types.ExtraFields_v2
|
|
||||||
err := utils.DecodeBytesExtraFields(proposedBlock.Extra, &decodedExtraField)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[findAncestorQcThroughRound] Error while trying to decode extra field", "ProposedBlockInfo.Hash", ancestorQC.ProposedBlockInfo.Hash)
|
|
||||||
return ancestorQC, lowerRoundQCs, higherRoundQCs, err
|
|
||||||
}
|
|
||||||
// Found the ancestor QC
|
|
||||||
if decodedExtraField.QuorumCert.ProposedBlockInfo.Round < lowerRoundQCs[NUM_OF_FORENSICS_QC-1].ProposedBlockInfo.Round {
|
|
||||||
return ancestorQC, lowerRoundQCs, higherRoundQCs, nil
|
|
||||||
}
|
|
||||||
ancestorQC = *decodedExtraField.QuorumCert
|
|
||||||
}
|
|
||||||
return ancestorQC, lowerRoundQCs, higherRoundQCs, errors.New("[findAncestorQcThroughRound] Could not find ancestor QC")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBlockInfo *types.BlockInfo, secondBlockInfo *types.BlockInfo) (common.Hash, []string, []string, error) {
|
func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBlockInfo *types.BlockInfo, secondBlockInfo *types.BlockInfo) (common.Hash, []string, []string, error) {
|
||||||
// Re-arrange by block number
|
// Re-arrange by block number
|
||||||
lowerBlockNumHash := firstBlockInfo.Hash
|
lowerBlockNumHash := firstBlockInfo.Hash
|
||||||
|
|
@ -455,41 +364,6 @@ func (f *Forensics) ProcessVoteEquivocation(chain consensus.ChainReader, engine
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (f *Forensics) isExtendingFromAncestor(blockChainReader consensus.ChainReader, currentBlock *types.BlockInfo, ancestorBlock *types.BlockInfo) (bool, error) {
|
|
||||||
blockNumDiff := int(big.NewInt(0).Sub(currentBlock.Number, ancestorBlock.Number).Int64())
|
|
||||||
|
|
||||||
nextBlockHash := currentBlock.Hash
|
|
||||||
for i := 0; i < blockNumDiff; i++ {
|
|
||||||
parentBlock := blockChainReader.GetHeaderByHash(nextBlockHash)
|
|
||||||
if parentBlock == nil {
|
|
||||||
return false, fmt.Errorf("could not find its parent block when checking whether currentBlock %v with hash %v is extending from the ancestorBlock %v", currentBlock.Number, currentBlock.Hash, ancestorBlock.Number)
|
|
||||||
} else {
|
|
||||||
nextBlockHash = parentBlock.ParentHash
|
|
||||||
}
|
|
||||||
log.Debug("[isExtendingFromAncestor] Found parent block", "CurrentBlockHash", currentBlock.Hash, "ParentHash", nextBlockHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
if nextBlockHash == ancestorBlock.Hash {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Forensics) isVoteBlamed(chain consensus.ChainReader, highestCommittedQCs []types.QuorumCert, incomingVote *types.Vote) (bool, *types.QuorumCert, error) {
|
|
||||||
proposedBlock := chain.GetHeaderByHash(incomingVote.ProposedBlockInfo.Hash)
|
|
||||||
var decodedExtraField types.ExtraFields_v2
|
|
||||||
err := utils.DecodeBytesExtraFields(proposedBlock.Extra, &decodedExtraField)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("[findAncestorVoteThroughRound] Error while trying to decode extra field", "ProposedBlockInfo.Hash", incomingVote.ProposedBlockInfo.Hash)
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
// Found the parent QC, if its round < hcqc3's round, return true
|
|
||||||
if decodedExtraField.QuorumCert.ProposedBlockInfo.Round < highestCommittedQCs[NUM_OF_FORENSICS_QC-1].ProposedBlockInfo.Round {
|
|
||||||
return true, decodedExtraField.QuorumCert, nil
|
|
||||||
}
|
|
||||||
return false, decodedExtraField.QuorumCert, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Forensics) DetectEquivocationInVotePool(vote *types.Vote, votePool *utils.Pool) {
|
func (f *Forensics) DetectEquivocationInVotePool(vote *types.Vote, votePool *utils.Pool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,10 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
|
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Utils to help mocking the signing of signatures
|
// Utils to help mocking the signing of signatures
|
||||||
var (
|
|
||||||
signer1, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
|
||||||
signer2, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
|
|
||||||
signer3, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
||||||
)
|
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
func SignHashByPK(pk *ecdsa.PrivateKey, itemToSign []byte) []byte {
|
func SignHashByPK(pk *ecdsa.PrivateKey, itemToSign []byte) []byte {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ const (
|
||||||
// Clique proof-of-authority protocol constants.
|
// Clique proof-of-authority protocol constants.
|
||||||
var (
|
var (
|
||||||
epochLength = uint64(30000) // Default number of blocks after which to checkpoint and reset the pending votes
|
epochLength = uint64(30000) // Default number of blocks after which to checkpoint and reset the pending votes
|
||||||
blockPeriod = uint64(15) // Default minimum difference between two consecutive block's timestamps
|
|
||||||
|
|
||||||
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
|
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
|
||||||
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
|
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,6 @@ var (
|
||||||
errUncleIsAncestor = errors.New("uncle is ancestor")
|
errUncleIsAncestor = errors.New("uncle is ancestor")
|
||||||
errDanglingUncle = errors.New("uncle's parent is not ancestor")
|
errDanglingUncle = errors.New("uncle's parent is not ancestor")
|
||||||
errInvalidDifficulty = errors.New("non-positive difficulty")
|
errInvalidDifficulty = errors.New("non-positive difficulty")
|
||||||
errInvalidMixDigest = errors.New("invalid mix digest")
|
|
||||||
errInvalidPoW = errors.New("invalid proof-of-work")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Author implements consensus.Engine, returning the header's coinbase as the
|
// Author implements consensus.Engine, returning the header's coinbase as the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue