Skip to content

Commit 51ba2c6

Browse files
bin8886ttblack
authored andcommitted
fixed get miner rpc is 0 bug
1 parent aeff4c4 commit 51ba2c6

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

consensus/clique/clique.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const (
5656
var (
5757
epochLength = uint64(30000) // Default number of blocks after which to checkpoint and reset the pending votes
5858

59-
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
60-
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
59+
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
60+
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
6161
extraElaHeight = 8
62-
nonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
63-
nonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.
62+
nonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
63+
nonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.
6464

6565
uncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
6666

@@ -162,7 +162,6 @@ func ecrecover(header *types.Header, sigcache *lru.ARCCache) (common.Address, er
162162
}
163163
var signer common.Address
164164
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])
165-
166165
sigcache.Add(hash, signer)
167166
return signer, nil
168167
}
@@ -383,7 +382,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
383382
if checkpoint != nil {
384383
hash := checkpoint.Hash()
385384
signersSize := len(checkpoint.Extra) - extraVanity - extraSeal
386-
if signersSize %common.AddressLength == extraElaHeight {
385+
if signersSize%common.AddressLength == extraElaHeight {
387386
signersSize -= extraElaHeight
388387
}
389388

@@ -425,7 +424,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
425424
beforeChangeEngine := false
426425
for i := 0; i < len(headers); i++ {
427426
beforeChangeEngine = c.isBeforeChangeEngine(chain, headers[i])
428-
log.Info("snap headers","number:", headers[i].Number.Uint64(), "beforeChangeEngine", beforeChangeEngine)
427+
log.Info("snap headers", "number:", headers[i].Number.Uint64(), "beforeChangeEngine", beforeChangeEngine)
429428
if beforeChangeEngine {
430429
log.Info("get before change engine header")
431430
break
@@ -586,7 +585,7 @@ func (c *Clique) Finalize(chain consensus.ChainReader, header *types.Header, sta
586585
// No block rewards in PoA, so the state remains as is and uncles are dropped
587586
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
588587
header.UncleHash = types.CalcUncleHash(nil)
589-
log.Info("clique finalize", "height", header.Number.Uint64(), "hash", header.Hash().String())
588+
log.Info("clique finalize", "height", header.Number.Uint64(), "hash", header.Hash().String())
590589
}
591590

592591
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
@@ -615,7 +614,7 @@ func (c *Clique) isBeforeChangeEngine(chain consensus.ChainReader,
615614
if chain.Config().PBFTBlock == nil {
616615
return false
617616
}
618-
return chain.Config().PBFTBlock.Uint64() - 1 == header.Number.Uint64()
617+
return chain.Config().PBFTBlock.Uint64()-1 == header.Number.Uint64()
619618
}
620619

621620
// Seal implements consensus.Engine, attempting to create a sealed block using
@@ -696,7 +695,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
696695
if err != nil {
697696
return err
698697
}
699-
copy(header.Extra[length - extraSeal:], sighash)
698+
copy(header.Extra[length-extraSeal:], sighash)
700699
// Wait until sealing is terminated or delay timeout.
701700
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
702701
go func() {

core/headerchain.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ type HeaderChain struct {
6969
}
7070

7171
// NewHeaderChain creates a new HeaderChain structure.
72-
// getValidator should return the parent's validator
73-
// procInterrupt points to the parent's interrupt semaphore
74-
// wg points to the parent's shutdown wait group
72+
//
73+
// getValidator should return the parent's validator
74+
// procInterrupt points to the parent's interrupt semaphore
75+
// wg points to the parent's shutdown wait group
7576
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
7677
headerCache, _ := lru.New(headerCacheLimit)
7778
tdCache, _ := lru.New(tdCacheLimit)
@@ -123,6 +124,14 @@ func (hc *HeaderChain) SetDposChain(engine consensus.Engine) {
123124
hc.pbftEngine = engine
124125
}
125126

127+
func (hc *HeaderChain) GetPOAEngine() consensus.Engine {
128+
return hc.poaEngine
129+
}
130+
131+
func (hc *HeaderChain) GetDposChain() consensus.Engine {
132+
return hc.pbftEngine
133+
}
134+
126135
// GetBlockNumber retrieves the block number belonging to the given hash
127136
// from the cache or database
128137
func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64 {

eth/api_backend.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ type EthAPIBackend struct {
4646
gpo *gasprice.Oracle
4747
}
4848

49-
func (b *EthAPIBackend) Engine() consensus.Engine {
50-
return b.eth.engine
49+
func (b *EthAPIBackend) Engine(number *big.Int) consensus.Engine {
50+
if b.ChainConfig().IsPBFTFork(number) {
51+
return b.eth.BlockChain().GetDposEngine()
52+
}
53+
return b.eth.BlockChain().GetPoAEngine()
5154
}
5255

5356
// ChainConfig returns the active chain configuration.

internal/ethapi/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ func (s *PublicBlockChainAPI) rpcMarshalHeader(header *types.Header) map[string]
12191219
fields := RPCMarshalHeader(header)
12201220
var zeroAddress common.Address
12211221
if header.Coinbase == zeroAddress {
1222-
coinbase, err := s.b.Engine().Author(header)
1222+
coinbase, err := s.b.Engine(header.Number).Author(header)
12231223
if err == nil {
12241224
fields["miner"] = coinbase
12251225
} else {
@@ -1241,7 +1241,7 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullT
12411241
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(b.Hash()))
12421242
var zeroAddress common.Address
12431243
if b.Coinbase() == zeroAddress {
1244-
coinbase, err := s.b.Engine().Author(b.Header())
1244+
coinbase, err := s.b.Engine(b.Number()).Author(b.Header())
12451245
if err == nil {
12461246
fields["miner"] = coinbase
12471247
} else {

internal/ethapi/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Backend interface {
8585

8686
ChainConfig() *params.ChainConfig
8787
CurrentBlock() *types.Block
88-
Engine() consensus.Engine
88+
Engine(number *big.Int) consensus.Engine
8989
}
9090

9191
func GetAPIs(apiBackend Backend) []rpc.API {

les/api_backend.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ type LesApiBackend struct {
4646
gpo *gasprice.Oracle
4747
}
4848

49-
func (b *LesApiBackend) Engine() consensus.Engine {
50-
return b.eth.engine
49+
func (b *LesApiBackend) Engine(number *big.Int) consensus.Engine {
50+
if b.ChainConfig().IsPBFTFork(number) {
51+
return b.eth.BlockChain().GetDposEngine()
52+
}
53+
return b.eth.BlockChain().GetPOAEngine()
5154
}
5255

5356
func (b *LesApiBackend) ChainConfig() *params.ChainConfig {

light/lightchain.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ func (lc *LightChain) SetPOAEngine(engine consensus.Engine) {
150150
lc.hc.SetPOAEngine(engine)
151151
}
152152

153+
func (lc *LightChain) GetDposEngine() consensus.Engine {
154+
return lc.hc.GetDposChain()
155+
}
156+
157+
func (lc *LightChain) GetPOAEngine() consensus.Engine {
158+
return lc.hc.GetPOAEngine()
159+
}
160+
153161
// AddTrustedCheckpoint adds a trusted checkpoint to the blockchain
154162
func (lc *LightChain) AddTrustedCheckpoint(cp *params.TrustedCheckpoint) {
155163
if lc.odr.ChtIndexer() != nil {
@@ -650,4 +658,4 @@ func (lc *LightChain) addEvilSingerEvents(evilEvents []*core.EvilSingerEvent) []
650658
lc.evilSigners = &core.EvilSignersMap{}
651659
}
652660
return lc.evilSigners.AddEvilSingerEvents(evilEvents)
653-
}
661+
}

0 commit comments

Comments
 (0)