light: return light client status on rpc /status (#7536)

*light: rpc /status returns status of light client ; code refactoring
 light: moved lightClientInfo into light.go, renamed String to ID
test/e2e: Return light client trusted height instead of SyncInfo trusted height
test/e2e/start.go: Not waiting for light client to catch up in tests. Removed querying of syncInfo in start if the node is a light node

* light: Removed call to primary /status. Added trustedPeriod to light info
* light/provider: added ID function to return IP of primary and witnesses
* light/provider/http/http_test: renamed String() to ID()
This commit is contained in:
Jasmina Malicevic
2022-01-20 14:53:20 +01:00
committed by GitHub
parent 4e5c2b5e8f
commit d68d25dcd5
15 changed files with 213 additions and 11 deletions
+2 -1
View File
@@ -100,7 +100,8 @@ func NewWithClientAndOptions(chainID string, client rpcclient.RemoteClient, opti
}
}
func (p *http) String() string {
// Identifies the provider with an IP in string format
func (p *http) ID() string {
return fmt.Sprintf("http{%s}", p.client.Remote())
}
+3 -4
View File
@@ -3,7 +3,6 @@ package http_test
import (
"context"
"errors"
"fmt"
"testing"
"time"
@@ -22,15 +21,15 @@ import (
func TestNewProvider(t *testing.T) {
c, err := lighthttp.New("chain-test", "192.168.0.1:26657")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://192.168.0.1:26657}")
require.Equal(t, c.ID(), "http{http://192.168.0.1:26657}")
c, err = lighthttp.New("chain-test", "http://153.200.0.1:26657")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1:26657}")
require.Equal(t, c.ID(), "http{http://153.200.0.1:26657}")
c, err = lighthttp.New("chain-test", "153.200.0.1")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1}")
require.Equal(t, c.ID(), "http{http://153.200.0.1}")
}
func TestProvider(t *testing.T) {
+14
View File
@@ -15,6 +15,20 @@ type Provider struct {
mock.Mock
}
// ID provides a mock function with given fields:
func (_m *Provider) ID() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// LightBlock provides a mock function with given fields: ctx, height
func (_m *Provider) LightBlock(ctx context.Context, height int64) (*types.LightBlock, error) {
ret := _m.Called(ctx, height)
+4
View File
@@ -25,4 +25,8 @@ type Provider interface {
// ReportEvidence reports an evidence of misbehavior.
ReportEvidence(context.Context, types.Evidence) error
// Returns the ID of a provider. For RPC providers it returns the IP address of the client
// For p2p providers it returns a combination of NodeID and IP address
ID() string
}