Skip to content

Commit

Permalink
add debug rpc endpoints for checkpoint whitelist service
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Jun 2, 2022
1 parent 2ba7c03 commit d4e7603
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 10 deletions.
8 changes: 8 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 2 additions & 0 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 10 additions & 6 deletions eth/downloader/whitelist/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
});
Expand Down
15 changes: 11 additions & 4 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

0 comments on commit d4e7603

Please sign in to comment.