mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
add debug rpc endpoints for checkpoint whitelist service
This commit is contained in:
parent
2ba7c036a7
commit
d4e7603315
8 changed files with 60 additions and 10 deletions
|
|
@ -359,3 +359,11 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re
|
|||
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, error) {
|
||||
return b.eth.stateAtTransaction(block, txIndex, reexec)
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) GetCheckpointWhitelist() map[uint64]common.Hash {
|
||||
return b.eth.Downloader().ChainValidator.GetCheckpointWhitelist()
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) PurgeCheckpointWhitelist() {
|
||||
b.eth.Downloader().ChainValidator.PurgeCheckpointWhitelist()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ type Downloader struct {
|
|||
type ChainValidator interface {
|
||||
IsValidChain(remoteHeader *types.Header, fetchHeadersByNumber func(number uint64, amount int, skip int, reverse bool) ([]*types.Header, []common.Hash, error)) (bool, error)
|
||||
ProcessCheckpoint(endBlockNum uint64, endBlockHash common.Hash)
|
||||
GetCheckpointWhitelist() map[uint64]common.Hash
|
||||
PurgeCheckpointWhitelist()
|
||||
}
|
||||
|
||||
// LightChain encapsulates functions required to synchronise a light chain.
|
||||
|
|
|
|||
|
|
@ -1420,6 +1420,12 @@ func (w *whitelistFake) IsValidChain(remoteHeader *types.Header, fetchHeadersByN
|
|||
|
||||
func (w *whitelistFake) ProcessCheckpoint(endBlockNum uint64, endBlockHash common.Hash) {}
|
||||
|
||||
func (w *whitelistFake) GetCheckpointWhitelist() map[uint64]common.Hash {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *whitelistFake) PurgeCheckpointWhitelist() {}
|
||||
|
||||
// TestFakedSyncProgress66WhitelistMismatch tests if in case of whitelisted
|
||||
// checkpoint mismatch with opposite peer, the sync should fail.
|
||||
func TestFakedSyncProgress66WhitelistMismatch(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -82,12 +82,16 @@ func (w *Service) ProcessCheckpoint(endBlockNum uint64, endBlockHash common.Hash
|
|||
}
|
||||
}
|
||||
|
||||
// PurgeWhitelistMap purges data from checkpoint whitelist map
|
||||
func (w *Service) purgeWhitelistMap() error {
|
||||
for k := range w.checkpointWhitelist {
|
||||
delete(w.checkpointWhitelist, k)
|
||||
}
|
||||
return nil
|
||||
// GetCheckpointWhitelist returns the existing whitelisted
|
||||
// entries of checkpoint of the form block number -> block hash.
|
||||
func (w *Service) GetCheckpointWhitelist() map[uint64]common.Hash {
|
||||
return w.checkpointWhitelist
|
||||
}
|
||||
|
||||
// PurgeCheckpointWhitelist purges data from checkpoint whitelist map
|
||||
func (w *Service) PurgeCheckpointWhitelist() {
|
||||
w.checkpointWhitelist = make(map[uint64]common.Hash)
|
||||
w.checkpointOrder = make([]uint64, 0)
|
||||
}
|
||||
|
||||
// EnqueueWhitelistBlock enqueues blockNumber, blockHash to the checkpoint whitelist map
|
||||
|
|
|
|||
|
|
@ -2156,6 +2156,17 @@ func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
|
|||
api.b.SetHead(uint64(number))
|
||||
}
|
||||
|
||||
// GetCheckpointWhitelist retrieves the current checkpoint whitelist
|
||||
// entries (of the form block number -> block hash)
|
||||
func (api *PrivateDebugAPI) GetCheckpointWhitelist() map[uint64]common.Hash {
|
||||
return api.b.GetCheckpointWhitelist()
|
||||
}
|
||||
|
||||
// PurgeCheckpointWhitelist purges the current checkpoint whitelist entries
|
||||
func (api *PrivateDebugAPI) PurgeCheckpointWhitelist() {
|
||||
api.b.PurgeCheckpointWhitelist()
|
||||
}
|
||||
|
||||
// PublicNetAPI offers network related RPC methods
|
||||
type PublicNetAPI struct {
|
||||
net *p2p.Server
|
||||
|
|
|
|||
|
|
@ -99,6 +99,8 @@ type Backend interface {
|
|||
GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
|
||||
GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
|
||||
SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription
|
||||
GetCheckpointWhitelist() map[uint64]common.Hash
|
||||
PurgeCheckpointWhitelist()
|
||||
|
||||
ChainConfig() *params.ChainConfig
|
||||
Engine() consensus.Engine
|
||||
|
|
|
|||
|
|
@ -474,6 +474,16 @@ web3._extend({
|
|||
params: 2,
|
||||
inputFormatter:[web3._extend.formatters.inputBlockNumberFormatter, web3._extend.formatters.inputBlockNumberFormatter],
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'getCheckpointWhitelist',
|
||||
call: 'debug_getCheckpointWhitelist',
|
||||
params: 0,
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'purgeCheckpointWhitelist',
|
||||
call: 'debug_purgeCheckpointWhitelist',
|
||||
params: 0,
|
||||
}),
|
||||
],
|
||||
properties: []
|
||||
});
|
||||
|
|
|
|||
|
|
@ -337,17 +337,24 @@ func (b *LesApiBackend) StateAtTransaction(ctx context.Context, block *types.Blo
|
|||
//
|
||||
|
||||
func (b *LesApiBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
return nil, common.Hash{}, 0, 0, errors.New("Not implemented")
|
||||
return nil, common.Hash{}, 0, 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
return nil, common.Hash{}, 0, 0, errors.New("Not implemented")
|
||||
return nil, common.Hash{}, 0, 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) GetCheckpointWhitelist() map[uint64]common.Hash {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) PurgeCheckpointWhitelist() {
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue