Skip to content

Commit a79f67d

Browse files
committed
fix compile error
1 parent a4d9f9f commit a79f67d

7 files changed

Lines changed: 25 additions & 14 deletions

File tree

consensus/XDPoS/XDPoS.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func (x *XDPoS) GetAuthorisedSignersFromSnapshot(chain consensus.ChainHeaderRead
491491
}
492492
}
493493

494-
func (x *XDPoS) FindParentBlockToAssign(chain consensus.ChainHeaderReader, currentBlock *types.Header) *types.Block {
494+
func (x *XDPoS) FindParentBlockToAssign(chain consensus.ChainReader, currentBlock *types.Header) *types.Block {
495495
var parent *types.Block = nil
496496
if x.config.BlockConsensusVersion(currentBlock.Number) == params.ConsensusEngineVersion2 {
497497
parent = x.EngineV2.FindParentBlockToAssign(chain)

consensus/XDPoS/engines/engine_v1/engine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,10 @@ func removePenaltiesFromBlock(chain consensus.ChainHeaderReader, masternodes []c
10111011
return masternodes
10121012
}
10131013
header := chain.GetHeaderByNumber(epochNumber)
1014-
block := chain.GetBlock(header.Hash(), epochNumber)
1015-
penalties := block.Penalties()
1014+
if header == nil {
1015+
return masternodes
1016+
}
1017+
penalties := header.Penalties
10161018
if penalties != nil {
10171019
prevPenalties := common.ExtractAddressFromBytes(penalties)
10181020
masternodes = common.RemoveItemFromArray(masternodes, prevPenalties)

consensus/XDPoS/engines/engine_v2/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ func (x *XDPoS_v2) GetPreviousPenaltyByHash(chain consensus.ChainHeaderReader, h
10631063
return common.ExtractAddressFromBytes(header.Penalties)
10641064
}
10651065

1066-
func (x *XDPoS_v2) FindParentBlockToAssign(chain consensus.ChainHeaderReader) *types.Block {
1066+
func (x *XDPoS_v2) FindParentBlockToAssign(chain consensus.ChainReader) *types.Block {
10671067
parent := chain.GetBlock(x.highestQuorumCert.ProposedBlockInfo.Hash, x.highestQuorumCert.ProposedBlockInfo.Number.Uint64())
10681068
if parent == nil {
10691069
log.Error("[FindParentBlockToAssign] Can not find parent block from highestQC proposedBlockInfo", "x.highestQuorumCert.ProposedBlockInfo.Hash", x.highestQuorumCert.ProposedBlockInfo.Hash, "x.highestQuorumCert.ProposedBlockInfo.Number", x.highestQuorumCert.ProposedBlockInfo.Number.Uint64())

consensus/ethash/consensus.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func (ethash *Ethash) VerifyHeaders(chain consensus.ChainHeaderReader, headers [
120120
// VerifyUncles verifies that the given block's uncles conform to the consensus
121121
// rules of the stock Ethereum ethash engine.
122122
func (ethash *Ethash) VerifyUncles(chain consensus.ChainHeaderReader, block *types.Block) error {
123+
chainReader, ok := chain.(consensus.ChainReader)
124+
if !ok {
125+
return consensus.ErrUnknownAncestor
126+
}
123127
// Verify that there are at most 2 uncles included in this block
124128
if len(block.Uncles()) > maxUncles {
125129
return errTooManyUncles
@@ -129,7 +133,7 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainHeaderReader, block *typ
129133

130134
number, parent := block.NumberU64()-1, block.ParentHash()
131135
for i := 0; i < 7; i++ {
132-
ancestor := chain.GetBlock(parent, number)
136+
ancestor := chainReader.GetBlock(parent, number)
133137
if ancestor == nil {
134138
break
135139
}

contracts/utils.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ func GetRewardForCheckpoint(c *XDPoS.XDPoS, chain consensus.ChainHeaderReader, h
332332
signingTxs, ok := c.GetCachedSigningTxs(header.Hash())
333333
if !ok {
334334
log.Debug("Failed get from cached", "hash", header.Hash(), "number", i)
335-
block := chain.GetBlock(header.Hash(), i)
336-
txs := block.Transactions()
335+
body := rawdb.ReadBody(c.GetDb(), header.Hash(), i)
336+
if body == nil {
337+
log.Debug("Failed get block body", "hash", header.Hash(), "number", i)
338+
continue
339+
}
340+
txs := body.Transactions
337341
if !chain.Config().IsTIPSigning(header.Number) {
338342
receipts := rawdb.ReadRawReceipts(c.GetDb(), header.Hash(), i)
339343
signingTxs = c.CacheNoneTIPSigningTxs(header, txs, receipts)

eth/hooks/engine_v1_hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func AttachConsensusV1Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
4242
if i%common.MergeSignRange == 0 || !chainConfig.IsTIP2019(big.NewInt(int64(i))) {
4343
bheader := chain.GetHeaderByNumber(i)
4444
bhash := bheader.Hash()
45-
block := chain.GetBlock(bhash, i)
45+
block := bc.GetBlock(bhash, i)
4646
if len(penSigners) > 0 {
4747
signedMasternodes, err := contracts.GetSignersFromContract(canonicalState, block)
4848
if err != nil {
@@ -144,7 +144,7 @@ func AttachConsensusV1Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
144144
}
145145
signingTxs, ok := adaptor.GetCachedSigningTxs(bhash)
146146
if !ok {
147-
block := chain.GetBlock(bhash, blockNumber)
147+
block := bc.GetBlock(bhash, blockNumber)
148148
txs := block.Transactions()
149149
signingTxs = adaptor.CacheSigningTxs(bhash, txs)
150150
}

eth/hooks/engine_v2_hooks.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
1515
"github.com/XinFinOrg/XDPoSChain/contracts"
1616
"github.com/XinFinOrg/XDPoSChain/core"
17+
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
1718
"github.com/XinFinOrg/XDPoSChain/core/state"
1819
"github.com/XinFinOrg/XDPoSChain/core/tracing"
1920
"github.com/XinFinOrg/XDPoSChain/core/types"
@@ -155,7 +156,7 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
155156
}
156157
signingTxs, ok := adaptor.GetCachedSigningTxs(bhash)
157158
if !ok {
158-
block := chain.GetBlock(bhash, blockNumber)
159+
block := bc.GetBlock(bhash, blockNumber)
159160
if block != nil {
160161
txs := block.Transactions()
161162
signingTxs = adaptor.CacheSigningTxs(bhash, txs)
@@ -229,7 +230,7 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
229230
}
230231
signingTxs, ok := adaptor.GetCachedSigningTxs(bhash)
231232
if !ok {
232-
block := chain.GetBlock(bhash, blockNumber)
233+
block := bc.GetBlock(bhash, blockNumber)
233234
if block != nil {
234235
txs := block.Transactions()
235236
signingTxs = adaptor.CacheSigningTxs(bhash, txs)
@@ -504,9 +505,9 @@ func GetSigningTxCount(c *XDPoS.XDPoS, chain consensus.ChainHeaderReader, header
504505
signingTxs, ok := c.GetCachedSigningTxs(h.Hash())
505506
if !ok {
506507
log.Debug("Failed get from cached", "hash", h.Hash(), "number", i)
507-
block := chain.GetBlock(h.Hash(), i)
508-
if block != nil {
509-
txs := block.Transactions()
508+
body := rawdb.ReadBody(c.GetDb(), h.Hash(), i)
509+
if body != nil {
510+
txs := body.Transactions
510511
signingTxs = c.CacheSigningTxs(h.Hash(), txs)
511512
}
512513
}

0 commit comments

Comments
 (0)