Skip to content
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
16 changes: 8 additions & 8 deletions consensus/XDPoS/XDPoS.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (x *XDPoS) UpdateParams(header *types.Header) {
}
}

func (x *XDPoS) Initial(chain consensus.ChainReader, header *types.Header) error {
func (x *XDPoS) Initial(chain consensus.ChainHeaderReader, header *types.Header) error {
switch x.config.BlockConsensusVersion(header.Number) {
case params.ConsensusEngineVersion2:
return x.EngineV2.Initial(chain, header)
Expand Down Expand Up @@ -309,7 +309,7 @@ func (x *XDPoS) CalcDifficulty(chain consensus.ChainReader, time uint64, parent
}
}

func (x *XDPoS) HandleProposedBlock(chain consensus.ChainReader, header *types.Header) error {
func (x *XDPoS) HandleProposedBlock(chain consensus.ChainHeaderReader, header *types.Header) error {
switch x.config.BlockConsensusVersion(header.Number) {
case params.ConsensusEngineVersion2:
return x.EngineV2.ProposedBlockHandler(chain, header)
Expand Down Expand Up @@ -343,7 +343,7 @@ func (x *XDPoS) IsAuthorisedAddress(chain consensus.ChainReader, header *types.H
}
}

func (x *XDPoS) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address {
func (x *XDPoS) GetMasternodes(chain consensus.ChainHeaderReader, header *types.Header) []common.Address {
switch x.config.BlockConsensusVersion(header.Number) {
case params.ConsensusEngineVersion2:
return x.EngineV2.GetMasternodes(chain, header)
Expand All @@ -352,7 +352,7 @@ func (x *XDPoS) GetMasternodes(chain consensus.ChainReader, header *types.Header
}
}

func (x *XDPoS) GetMasternodesByNumber(chain consensus.ChainReader, blockNumber uint64) []common.Address {
func (x *XDPoS) GetMasternodesByNumber(chain consensus.ChainHeaderReader, blockNumber uint64) []common.Address {
blockHeader := chain.GetHeaderByNumber(blockNumber)
if blockHeader == nil {
log.Error("[GetMasternodesByNumber] Unable to find block", "Num", blockNumber)
Expand All @@ -375,7 +375,7 @@ func (x *XDPoS) YourTurn(chain consensus.ChainReader, parent *types.Header, sign
}
}

func (x *XDPoS) GetValidator(creator common.Address, chain consensus.ChainReader, header *types.Header) (common.Address, error) {
func (x *XDPoS) GetValidator(creator common.Address, chain consensus.ChainHeaderReader, header *types.Header) (common.Address, error) {
switch x.config.BlockConsensusVersion(header.Number) {
default: // Default "v1", v2 does not need this function
return x.EngineV1.GetValidator(creator, chain, header)
Expand Down Expand Up @@ -430,7 +430,7 @@ func (x *XDPoS) IsEpochSwitch(header *types.Header) (bool, uint64, error) {
}
}

func (x *XDPoS) GetCurrentEpochSwitchBlock(chain consensus.ChainReader, blockNumber *big.Int) (uint64, uint64, error) {
func (x *XDPoS) GetCurrentEpochSwitchBlock(chain consensus.ChainHeaderReader, blockNumber *big.Int) (uint64, uint64, error) {
switch x.config.BlockConsensusVersion(blockNumber) {
case params.ConsensusEngineVersion2:
return x.EngineV2.GetCurrentEpochSwitchBlock(chain, blockNumber)
Expand All @@ -439,7 +439,7 @@ func (x *XDPoS) GetCurrentEpochSwitchBlock(chain consensus.ChainReader, blockNum
}
}

func (x *XDPoS) CalculateMissingRounds(chain consensus.ChainReader, header *types.Header) (*utils.PublicApiMissedRoundsMetadata, error) {
func (x *XDPoS) CalculateMissingRounds(chain consensus.ChainHeaderReader, header *types.Header) (*utils.PublicApiMissedRoundsMetadata, error) {
switch x.config.BlockConsensusVersion(header.Number) {
case params.ConsensusEngineVersion2:
return x.EngineV2.CalculateMissingRounds(chain, header)
Expand Down Expand Up @@ -554,7 +554,7 @@ func (x *XDPoS) GetCachedSigningTxs(hash common.Hash) ([]*types.Transaction, boo
return x.signingTxsCache.Get(hash)
}

func (x *XDPoS) GetEpochSwitchInfoBetween(chain consensus.ChainReader, begin, end *types.Header) ([]*types.EpochSwitchInfo, error) {
func (x *XDPoS) GetEpochSwitchInfoBetween(chain consensus.ChainHeaderReader, begin, end *types.Header) ([]*types.EpochSwitchInfo, error) {
beginBlockVersion := x.config.BlockConsensusVersion(begin.Number)
endBlockVersion := x.config.BlockConsensusVersion(end.Number)
if beginBlockVersion == params.ConsensusEngineVersion2 && endBlockVersion == params.ConsensusEngineVersion2 {
Expand Down
8 changes: 4 additions & 4 deletions consensus/XDPoS/engines/engine_v1/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (x *XDPoS_v1) StoreSnapshot(snap *SnapshotV1) error {
return snap.store(x.db)
}

func (x *XDPoS_v1) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address {
func (x *XDPoS_v1) GetMasternodes(chain consensus.ChainHeaderReader, header *types.Header) []common.Address {
n := header.Number.Uint64()
e := x.config.Epoch
switch {
Expand Down Expand Up @@ -549,7 +549,7 @@ func (x *XDPoS_v1) snapshot(chain consensus.ChainReader, number uint64, hash com

// VerifyUncles implements consensus.Engine, always returning an error for any
// uncles as this consensus mechanism doesn't permit uncles.
func (x *XDPoS_v1) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
func (x *XDPoS_v1) VerifyUncles(chain consensus.ChainHeaderReader, block *types.Block) error {
if len(block.Uncles()) > 0 {
return errors.New("uncles not allowed")
}
Expand Down Expand Up @@ -657,7 +657,7 @@ func (x *XDPoS_v1) verifySeal(chain consensus.ChainReader, header *types.Header,
return nil
}

func (x *XDPoS_v1) GetValidator(creator common.Address, chain consensus.ChainReader, header *types.Header) (common.Address, error) {
func (x *XDPoS_v1) GetValidator(creator common.Address, chain consensus.ChainHeaderReader, header *types.Header) (common.Address, error) {
epoch := x.config.Epoch
no := header.Number.Uint64()
cpNo := no
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func removePenaltiesFromBlock(chain consensus.ChainReader, masternodes []common.
return masternodes
}

func (x *XDPoS_v1) getSignersFromContract(chain consensus.ChainReader, checkpointHeader *types.Header) ([]common.Address, error) {
func (x *XDPoS_v1) getSignersFromContract(chain consensus.ChainHeaderReader, checkpointHeader *types.Header) ([]common.Address, error) {
startGapBlockHeader := checkpointHeader
number := checkpointHeader.Number.Uint64()
for step := uint64(1); step <= chain.Config().XDPoS.Gap; step++ {
Expand Down
2 changes: 1 addition & 1 deletion consensus/XDPoS/engines/engine_v2/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

// TODO: what should be new difficulty
func (x *XDPoS_v2) calcDifficulty(chain consensus.ChainReader, parent *types.Header, signer common.Address) *big.Int {
func (x *XDPoS_v2) calcDifficulty(chain consensus.ChainHeaderReader, parent *types.Header, signer common.Address) *big.Int {
return big.NewInt(1)
}
38 changes: 19 additions & 19 deletions consensus/XDPoS/engines/engine_v2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ func (x *XDPoS_v2) SignHash(header *types.Header) (hash common.Hash) {
}

// Initial V2 related parameters
func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header) error {
func (x *XDPoS_v2) Initial(chain consensus.ChainHeaderReader, header *types.Header) error {
x.lock.Lock()
defer x.lock.Unlock()

return x.initial(chain, header)
}

func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) error {
func (x *XDPoS_v2) initial(chain consensus.ChainHeaderReader, header *types.Header) error {
log.Warn("[initial] initial v2 related parameters")

if x.highestQuorumCert.ProposedBlockInfo.Hash != (common.Hash{}) { // already initialized
Expand Down Expand Up @@ -555,11 +555,11 @@ func (x *XDPoS_v2) Seal(chain consensus.ChainReader, block *types.Block, stop <-
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have based on the previous blocks in the chain and the
// current signer.
func (x *XDPoS_v2) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
func (x *XDPoS_v2) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
return x.calcDifficulty(chain, parent, x.signer)
}

func (x *XDPoS_v2) IsAuthorisedAddress(chain consensus.ChainReader, header *types.Header, address common.Address) bool {
func (x *XDPoS_v2) IsAuthorisedAddress(chain consensus.ChainHeaderReader, header *types.Header, address common.Address) bool {
snap, err := x.GetSnapshot(chain, header)
if err != nil {
log.Error("[IsAuthorisedAddress] Can't get snapshot with at ", "number", header.Number, "hash", header.Hash().Hex(), "err", err)
Expand All @@ -573,7 +573,7 @@ func (x *XDPoS_v2) IsAuthorisedAddress(chain consensus.ChainReader, header *type
return false
}

func (x *XDPoS_v2) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*SnapshotV2, error) {
func (x *XDPoS_v2) GetSnapshot(chain consensus.ChainHeaderReader, header *types.Header) (*SnapshotV2, error) {
number := header.Number.Uint64()
log.Trace("get snapshot", "number", number)
snap, err := x.getSnapshot(chain, number, false)
Expand All @@ -583,7 +583,7 @@ func (x *XDPoS_v2) GetSnapshot(chain consensus.ChainReader, header *types.Header
return snap, nil
}

func (x *XDPoS_v2) UpdateMasternodes(chain consensus.ChainReader, header *types.Header, ms []utils.Masternode) error {
func (x *XDPoS_v2) UpdateMasternodes(chain consensus.ChainHeaderReader, header *types.Header, ms []utils.Masternode) error {
number := header.Number.Uint64()
log.Trace("[UpdateMasternodes]", "number", number, "hash", header.Hash())
if number%x.config.Epoch != x.config.Epoch-x.config.Gap {
Expand Down Expand Up @@ -617,7 +617,7 @@ func (x *XDPoS_v2) UpdateMasternodes(chain consensus.ChainReader, header *types.

// VerifyUncles implements consensus.Engine, always returning an error for any
// uncles as this consensus mechanism doesn't permit uncles.
func (x *XDPoS_v2) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
func (x *XDPoS_v2) VerifyUncles(chain consensus.ChainHeaderReader, block *types.Block) error {
if len(block.Uncles()) > 0 {
return errors.New("uncles not allowed in XDPoS_v2")
}
Expand Down Expand Up @@ -652,7 +652,7 @@ func (x *XDPoS_v2) VerifyHeaders(chain consensus.ChainReader, headers []*types.H
/*
Proposed Block workflow
*/
func (x *XDPoS_v2) ProposedBlockHandler(chain consensus.ChainReader, blockHeader *types.Header) error {
func (x *XDPoS_v2) ProposedBlockHandler(chain consensus.ChainHeaderReader, blockHeader *types.Header) error {
x.lock.Lock()
defer x.lock.Unlock()

Expand Down Expand Up @@ -695,7 +695,7 @@ func (x *XDPoS_v2) ProposedBlockHandler(chain consensus.ChainReader, blockHeader
*/

// To be used by different message verification. Verify local DB block info against the received block information(i.e hash, blockNum, round)
func (x *XDPoS_v2) VerifyBlockInfo(blockChainReader consensus.ChainReader, blockInfo *types.BlockInfo, blockHeader *types.Header) error {
func (x *XDPoS_v2) VerifyBlockInfo(blockChainReader consensus.ChainHeaderReader, blockInfo *types.BlockInfo, blockHeader *types.Header) error {
/*
1. Check if is able to get header by hash from the chain
2. Check the header from step 1 matches what's in the blockInfo. This includes the block number and the round
Expand Down Expand Up @@ -742,7 +742,7 @@ func (x *XDPoS_v2) VerifyBlockInfo(blockChainReader consensus.ChainReader, block
return nil
}

func (x *XDPoS_v2) verifyQC(blockChainReader consensus.ChainReader, quorumCert *types.QuorumCert, parentHeader *types.Header) error {
func (x *XDPoS_v2) verifyQC(blockChainReader consensus.ChainHeaderReader, quorumCert *types.QuorumCert, parentHeader *types.Header) error {
if quorumCert == nil {
log.Warn("[verifyQC] QC is Nil")
return utils.ErrInvalidQC
Expand Down Expand Up @@ -817,7 +817,7 @@ func (x *XDPoS_v2) verifyQC(blockChainReader consensus.ChainReader, quorumCert *
}

// Update local QC variables including highestQC & lockQuorumCert, as well as commit the blocks that satisfy the algorithm requirements
func (x *XDPoS_v2) processQC(blockChainReader consensus.ChainReader, incomingQuorumCert *types.QuorumCert) error {
func (x *XDPoS_v2) processQC(blockChainReader consensus.ChainHeaderReader, incomingQuorumCert *types.QuorumCert) error {
log.Debug("[processQC][Before]", "HighQC", x.highestQuorumCert.ProposedBlockInfo.Round)
// 1. Update HighestQC
if incomingQuorumCert.ProposedBlockInfo.Round > x.highestQuorumCert.ProposedBlockInfo.Round {
Expand Down Expand Up @@ -862,7 +862,7 @@ func (x *XDPoS_v2) processQC(blockChainReader consensus.ChainReader, incomingQuo
3. Reset vote and timeout Pools
4. Send signal to miner
*/
func (x *XDPoS_v2) setNewRound(blockChainReader consensus.ChainReader, round types.Round) {
func (x *XDPoS_v2) setNewRound(blockChainReader consensus.ChainHeaderReader, round types.Round) {
log.Info("[setNewRound] new round and reset pools and workers", "round", round)
x.currentRound = round
x.timeoutCount = 0
Expand Down Expand Up @@ -891,7 +891,7 @@ func (x *XDPoS_v2) getSyncInfo() *types.SyncInfo {
}

// Find parent and grandparent, check round number, if so, commit grandparent(grandGrandParent of currentBlock)
func (x *XDPoS_v2) commitBlocks(blockChainReader consensus.ChainReader, proposedBlockHeader *types.Header, proposedBlockRound *types.Round, incomingQc *types.QuorumCert) (bool, error) {
func (x *XDPoS_v2) commitBlocks(blockChainReader consensus.ChainHeaderReader, proposedBlockHeader *types.Header, proposedBlockRound *types.Round, incomingQc *types.QuorumCert) (bool, error) {
// XDPoS v1.0 switch to v2.0, skip commit
if big.NewInt(0).Sub(proposedBlockHeader.Number, big.NewInt(2)).Cmp(x.config.V2.SwitchBlock) <= 0 {
return false, nil
Expand Down Expand Up @@ -961,7 +961,7 @@ func (x *XDPoS_v2) GetMasternodesFromEpochSwitchHeader(epochSwitchHeader *types.
}

// Given header, get master node from the epoch switch block of that epoch
func (x *XDPoS_v2) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address {
func (x *XDPoS_v2) GetMasternodes(chain consensus.ChainHeaderReader, header *types.Header) []common.Address {
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
if err != nil {
log.Error("[GetMasternodes] Adaptor v2 getEpochSwitchInfo has error", "err", err)
Expand All @@ -971,7 +971,7 @@ func (x *XDPoS_v2) GetMasternodes(chain consensus.ChainReader, header *types.Hea
}

// Given header, get master node from the epoch switch block of that epoch
func (x *XDPoS_v2) GetPenalties(chain consensus.ChainReader, header *types.Header) []common.Address {
func (x *XDPoS_v2) GetPenalties(chain consensus.ChainHeaderReader, header *types.Header) []common.Address {
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
if err != nil {
log.Error("[GetPenalties] Adaptor v2 getEpochSwitchInfo has error", "err", err)
Expand All @@ -980,7 +980,7 @@ func (x *XDPoS_v2) GetPenalties(chain consensus.ChainReader, header *types.Heade
return epochSwitchInfo.Penalties
}

func (x *XDPoS_v2) GetStandbynodes(chain consensus.ChainReader, header *types.Header) []common.Address {
func (x *XDPoS_v2) GetStandbynodes(chain consensus.ChainHeaderReader, header *types.Header) []common.Address {
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
if err != nil {
log.Error("[GetStandbynodes] Adaptor v2 getEpochSwitchInfo has error", "err", err)
Expand Down Expand Up @@ -1030,7 +1030,7 @@ func (x *XDPoS_v2) calcMasternodes(chain consensus.ChainReader, blockNum *big.In
}

// Given hash, get master node from the epoch switch block of the epoch
func (x *XDPoS_v2) GetMasternodesByHash(chain consensus.ChainReader, hash common.Hash) []common.Address {
func (x *XDPoS_v2) GetMasternodesByHash(chain consensus.ChainHeaderReader, hash common.Hash) []common.Address {
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, nil, hash)
if err != nil {
log.Error("[GetMasternodes] Adaptor v2 getEpochSwitchInfo has error, potentially bug", "err", err)
Expand All @@ -1040,7 +1040,7 @@ func (x *XDPoS_v2) GetMasternodesByHash(chain consensus.ChainReader, hash common
}

// Given hash, get master node from the epoch switch block of the previous `limit` epoch
func (x *XDPoS_v2) GetPreviousPenaltyByHash(chain consensus.ChainReader, hash common.Hash, limit int) []common.Address {
func (x *XDPoS_v2) GetPreviousPenaltyByHash(chain consensus.ChainHeaderReader, hash common.Hash, limit int) []common.Address {
currentEpochSwitchInfo, err := x.getEpochSwitchInfo(chain, nil, hash)
if err != nil {
log.Error("[GetPreviousPenaltyByHash] Adaptor v2 getPreviousEpochSwitchInfoByHash has error, potentially bug", "err", err)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func (x *XDPoS_v2) FindParentBlockToAssign(chain consensus.ChainReader) *types.B
return parent
}

func (x *XDPoS_v2) allowedToSend(chain consensus.ChainReader, blockHeader *types.Header, sendType string) bool {
func (x *XDPoS_v2) allowedToSend(chain consensus.ChainHeaderReader, blockHeader *types.Header, sendType string) bool {
// Don't hold the signFn for the whole signing operation
x.signLock.RLock()
signer := x.signer
Expand Down
6 changes: 3 additions & 3 deletions consensus/XDPoS/engines/engine_v2/epochSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Given header and its hash, get epoch switch info from the epoch switch block of that epoch,
// 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.ChainHeaderReader, header *types.Header, hash common.Hash) (*types.EpochSwitchInfo, error) {
epochSwitchInfo, ok := x.epochSwitches.Get(hash)
if ok && epochSwitchInfo != nil {
log.Debug("[getEpochSwitchInfo] cache hit", "number", epochSwitchInfo.EpochSwitchBlockInfo.Number, "hash", hash.Hex())
Expand Down Expand Up @@ -131,7 +131,7 @@ func (x *XDPoS_v2) isEpochSwitchAtRound(round types.Round, parentHeader *types.H
return parentRound < epochStartRound, epochNum, nil
}

func (x *XDPoS_v2) GetCurrentEpochSwitchBlock(chain consensus.ChainReader, blockNum *big.Int) (uint64, uint64, error) {
func (x *XDPoS_v2) GetCurrentEpochSwitchBlock(chain consensus.ChainHeaderReader, blockNum *big.Int) (uint64, uint64, error) {
header := chain.GetHeaderByNumber(blockNum.Uint64())
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
if err != nil {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (x *XDPoS_v2) IsEpochSwitch(header *types.Header) (bool, uint64, error) {

// GetEpochSwitchInfoBetween get epoch switch between begin and end headers
// Search backwardly from end number to begin number
func (x *XDPoS_v2) GetEpochSwitchInfoBetween(chain consensus.ChainReader, begin, end *types.Header) ([]*types.EpochSwitchInfo, error) {
func (x *XDPoS_v2) GetEpochSwitchInfoBetween(chain consensus.ChainHeaderReader, begin, end *types.Header) ([]*types.EpochSwitchInfo, error) {
infos := make([]*types.EpochSwitchInfo, 0)
// after the first iteration, it becomes nil since epoch switch info does not have header info
iteratorHeader := end
Expand Down
Loading