@@ -21,14 +21,15 @@ import (
2121
2222 "github.com/ethereum/go-ethereum/common"
2323 "github.com/ethereum/go-ethereum/consensus"
24+ istanbulcommon "github.com/ethereum/go-ethereum/consensus/istanbul/common"
2425 "github.com/ethereum/go-ethereum/core/types"
2526 "github.com/ethereum/go-ethereum/rpc"
2627)
2728
2829// API is a user facing RPC API to dump Istanbul state
2930type API struct {
30- chain consensus.ChainHeaderReader
31- istanbul * backend
31+ chain consensus.ChainHeaderReader
32+ backend * Backend
3233}
3334
3435// BlockSigners is contains who created and who signed a particular block, denoted by its number and hash
@@ -46,7 +47,7 @@ type Status struct {
4647
4748// NodeAddress returns the public address that is used to sign block headers in IBFT
4849func (api * API ) NodeAddress () common.Address {
49- return api .istanbul .Address ()
50+ return api .backend .Address ()
5051}
5152
5253// GetSignersFromBlock returns the signers and minter for a given block number, or the
@@ -61,7 +62,7 @@ func (api *API) GetSignersFromBlock(number *rpc.BlockNumber) (*BlockSigners, err
6162 }
6263
6364 if header == nil {
64- return nil , errUnknownBlock
65+ return nil , istanbulcommon . ErrUnknownBlock
6566 }
6667
6768 return api .signers (header )
@@ -71,19 +72,19 @@ func (api *API) GetSignersFromBlock(number *rpc.BlockNumber) (*BlockSigners, err
7172func (api * API ) GetSignersFromBlockByHash (hash common.Hash ) (* BlockSigners , error ) {
7273 header := api .chain .GetHeaderByHash (hash )
7374 if header == nil {
74- return nil , errUnknownBlock
75+ return nil , istanbulcommon . ErrUnknownBlock
7576 }
7677
7778 return api .signers (header )
7879}
7980
8081func (api * API ) signers (header * types.Header ) (* BlockSigners , error ) {
81- author , err := api .istanbul .Author (header )
82+ author , err := api .backend .Author (header )
8283 if err != nil {
8384 return nil , err
8485 }
8586
86- committers , err := api .istanbul .Signers (header )
87+ committers , err := api .backend .Signers (header )
8788 if err != nil {
8889 return nil , err
8990 }
@@ -107,18 +108,18 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
107108 }
108109 // Ensure we have an actually valid block and return its snapshot
109110 if header == nil {
110- return nil , errUnknownBlock
111+ return nil , istanbulcommon . ErrUnknownBlock
111112 }
112- return api .istanbul .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
113+ return api .backend .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
113114}
114115
115116// GetSnapshotAtHash retrieves the state snapshot at a given block.
116117func (api * API ) GetSnapshotAtHash (hash common.Hash ) (* Snapshot , error ) {
117118 header := api .chain .GetHeaderByHash (hash )
118119 if header == nil {
119- return nil , errUnknownBlock
120+ return nil , istanbulcommon . ErrUnknownBlock
120121 }
121- return api .istanbul .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
122+ return api .backend .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
122123}
123124
124125// GetValidators retrieves the list of authorized validators at the specified block.
@@ -132,9 +133,9 @@ func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
132133 }
133134 // Ensure we have an actually valid block and return the validators from its snapshot
134135 if header == nil {
135- return nil , errUnknownBlock
136+ return nil , istanbulcommon . ErrUnknownBlock
136137 }
137- snap , err := api .istanbul .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
138+ snap , err := api .backend .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
138139 if err != nil {
139140 return nil , err
140141 }
@@ -145,9 +146,9 @@ func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
145146func (api * API ) GetValidatorsAtHash (hash common.Hash ) ([]common.Address , error ) {
146147 header := api .chain .GetHeaderByHash (hash )
147148 if header == nil {
148- return nil , errUnknownBlock
149+ return nil , istanbulcommon . ErrUnknownBlock
149150 }
150- snap , err := api .istanbul .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
151+ snap , err := api .backend .snapshot (api .chain , header .Number .Uint64 (), header .Hash (), nil )
151152 if err != nil {
152153 return nil , err
153154 }
@@ -156,11 +157,11 @@ func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)
156157
157158// Candidates returns the current candidates the node tries to uphold and vote on.
158159func (api * API ) Candidates () map [common.Address ]bool {
159- api .istanbul .candidatesLock .RLock ()
160- defer api .istanbul .candidatesLock .RUnlock ()
160+ api .backend .candidatesLock .RLock ()
161+ defer api .backend .candidatesLock .RUnlock ()
161162
162163 proposals := make (map [common.Address ]bool )
163- for address , auth := range api .istanbul .candidates {
164+ for address , auth := range api .backend .candidates {
164165 proposals [address ] = auth
165166 }
166167 return proposals
@@ -169,19 +170,19 @@ func (api *API) Candidates() map[common.Address]bool {
169170// Propose injects a new authorization candidate that the validator will attempt to
170171// push through.
171172func (api * API ) Propose (address common.Address , auth bool ) {
172- api .istanbul .candidatesLock .Lock ()
173- defer api .istanbul .candidatesLock .Unlock ()
173+ api .backend .candidatesLock .Lock ()
174+ defer api .backend .candidatesLock .Unlock ()
174175
175- api .istanbul .candidates [address ] = auth
176+ api .backend .candidates [address ] = auth
176177}
177178
178179// Discard drops a currently running candidate, stopping the validator from casting
179180// further votes (either for or against).
180181func (api * API ) Discard (address common.Address ) {
181- api .istanbul .candidatesLock .Lock ()
182- defer api .istanbul .candidatesLock .Unlock ()
182+ api .backend .candidatesLock .Lock ()
183+ defer api .backend .candidatesLock .Unlock ()
183184
184- delete (api .istanbul .candidates , address )
185+ delete (api .backend .candidates , address )
185186}
186187
187188func (api * API ) Status (startBlockNum * rpc.BlockNumber , endBlockNum * rpc.BlockNumber ) (* Status , error ) {
@@ -264,7 +265,7 @@ func (api *API) IsValidator(blockNum *rpc.BlockNumber) (bool, error) {
264265 s , _ := api .GetValidators (& blockNumber )
265266
266267 for _ , v := range s {
267- if v == api .istanbul .address {
268+ if v == api .backend .address {
268269 return true , nil
269270 }
270271 }
0 commit comments