Skip to content

fix(dot/sync, dot/rpc): implement HighestBlock #2195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,18 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore) (*Node, error) {
// check if rpc service is enabled
if enabled := cfg.RPC.isRPCEnabled() || cfg.RPC.isWSEnabled(); enabled {
var rpcSrvc *rpc.HTTPServer
rpcSrvc, err = createRPCService(cfg, ns, stateSrvc, coreSrvc, networkSrvc, bp, sysSrvc, fg)
cRPCParams := createRPCServiceParams{
cfg,
ns,
stateSrvc,
coreSrvc,
networkSrvc,
bp,
sysSrvc,
fg,
syncer,
}
rpcSrvc, err = createRPCService(cRPCParams)
if err != nil {
return nil, fmt.Errorf("failed to create rpc service: %s", err)
}
Expand Down
4 changes: 3 additions & 1 deletion dot/rpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type HTTPServerConfig struct {
RPCAPI modules.RPCAPI
SystemAPI modules.SystemAPI
SyncStateAPI modules.SyncStateAPI
SyncAPI modules.SyncAPI
NodeStorage *runtime.NodeStorage
RPC bool
RPCExternal bool
Expand Down Expand Up @@ -97,7 +98,8 @@ func (h *HTTPServer) RegisterModules(mods []string) {
switch mod {
case "system":
srvc = modules.NewSystemModule(h.serverConfig.NetworkAPI, h.serverConfig.SystemAPI,
h.serverConfig.CoreAPI, h.serverConfig.StorageAPI, h.serverConfig.TransactionQueueAPI, h.serverConfig.BlockAPI)
h.serverConfig.CoreAPI, h.serverConfig.StorageAPI, h.serverConfig.TransactionQueueAPI,
h.serverConfig.BlockAPI, h.serverConfig.SyncAPI)
case "author":
srvc = modules.NewAuthorModule(h.logger, h.serverConfig.CoreAPI, h.serverConfig.TransactionQueueAPI)
case "chain":
Expand Down
6 changes: 5 additions & 1 deletion dot/rpc/modules/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type NetworkAPI interface {
Stop() error
Start() error
IsStopped() bool
HighestBlock() int64
StartingBlock() int64
AddReservedPeers(addrs ...string) error
RemoveReservedPeers(addrs ...string) error
Expand Down Expand Up @@ -153,3 +152,8 @@ type RuntimeStorageAPI interface {
type SyncStateAPI interface {
GenSyncSpec(raw bool) (*genesis.Genesis, error)
}

//go:generate mockery --name SyncAPI --structname SyncAPI --case underscore --keeptree
type SyncAPI interface {
HighestBlock() int64
}
14 changes: 0 additions & 14 deletions dot/rpc/modules/mocks/network_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions dot/rpc/modules/mocks/sync_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dot/rpc/modules/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type SystemModule struct {
storageAPI StorageAPI
txStateAPI TransactionStateAPI
blockAPI BlockAPI
syncAPI SyncAPI
}

// EmptyRequest represents an RPC request with no fields
Expand Down Expand Up @@ -67,14 +68,16 @@ type SyncStateResponse struct {

// NewSystemModule creates a new API instance
func NewSystemModule(net NetworkAPI, sys SystemAPI, core CoreAPI,
storage StorageAPI, txAPI TransactionStateAPI, blockAPI BlockAPI) *SystemModule {
storage StorageAPI, txAPI TransactionStateAPI, blockAPI BlockAPI,
syncAPI SyncAPI) *SystemModule {
return &SystemModule{
networkAPI: net,
systemAPI: sys,
coreAPI: core,
storageAPI: storage,
txStateAPI: txAPI,
blockAPI: blockAPI,
syncAPI: syncAPI,
}
}

Expand Down Expand Up @@ -233,7 +236,7 @@ func (sm *SystemModule) SyncState(r *http.Request, req *EmptyRequest, res *SyncS

*res = SyncStateResponse{
CurrentBlock: uint32(h.Number.Int64()),
HighestBlock: uint32(sm.networkAPI.HighestBlock()),
HighestBlock: uint32(sm.syncAPI.HighestBlock()),
StartingBlock: uint32(sm.networkAPI.StartingBlock()),
}
return nil
Expand Down
Loading