mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-18 22:14:35 +00:00
lite: add helper functions for initiating the light client (#4486)
* add new net client * hijack example test * lint fixes * reorganised file structure * renamed funcs and added documentation * implemented suggested changes * restored example tests * edited comments * Update lite2/setup.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * Update lite2/client.go * lite cmds use HTTP client * better naming * Delete go.sum * Delete go.mod * restore go mod * restore go.sum * fix double import Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Bot from GolangCI
Anton Kaliaev
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
c518a062a7
commit
ff786515b8
+2
-5
@@ -953,11 +953,8 @@ func (c *Client) autoUpdateRoutine() {
|
||||
}
|
||||
}
|
||||
|
||||
// Update attempts to advance the state making exponential steps (note:
|
||||
// when SequentialVerification is being used, the client will still be
|
||||
// downloading all intermediate headers).
|
||||
//
|
||||
// Exposed for testing.
|
||||
// Update attempts to advance the state by downloading the latest header and
|
||||
// comparing it with the existing one.
|
||||
func (c *Client) Update(now time.Time) error {
|
||||
lastTrustedHeight, err := c.LastTrustedHeight()
|
||||
if err != nil {
|
||||
|
||||
@@ -135,7 +135,7 @@ func ExampleClient_VerifyHeaderAtHeight() {
|
||||
Hash: header.Hash(),
|
||||
},
|
||||
primary,
|
||||
[]provider.Provider{primary}, // TODO: primary should not be used here
|
||||
[]provider.Provider{primary}, // NOTE: primary should not be used here
|
||||
dbs.New(db, chainID),
|
||||
UpdatePeriod(0),
|
||||
// Logger(log.TestingLogger()),
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package lite
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/lite2/provider"
|
||||
"github.com/tendermint/tendermint/lite2/provider/http"
|
||||
"github.com/tendermint/tendermint/lite2/store"
|
||||
)
|
||||
|
||||
// NewHTTPClient initiates an instance of a lite client using HTTP addresses
|
||||
// for both the primary provider and witnesses of the lite client. A trusted
|
||||
// header and hash must be passed to initialize the client.
|
||||
//
|
||||
// See all Option(s) for the additional configuration.
|
||||
// See NewClient.
|
||||
func NewHTTPClient(
|
||||
chainID string,
|
||||
trustOptions TrustOptions,
|
||||
primaryAddress string,
|
||||
witnessesAddresses []string,
|
||||
trustedStore store.Store,
|
||||
options ...Option) (*Client, error) {
|
||||
|
||||
providers, err := providersFromAddresses(append(witnessesAddresses, primaryAddress), chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewClient(
|
||||
chainID,
|
||||
trustOptions,
|
||||
providers[len(providers)-1],
|
||||
providers[:len(providers)-1],
|
||||
trustedStore,
|
||||
options...)
|
||||
}
|
||||
|
||||
// NewHTTPClientFromTrustedStore initiates an instance of a lite client using
|
||||
// HTTP addresses for both the primary provider and witnesses and uses a
|
||||
// trusted store as the root of trust.
|
||||
//
|
||||
// See all Option(s) for the additional configuration.
|
||||
// See NewClientFromTrustedStore.
|
||||
func NewHTTPClientFromTrustedStore(
|
||||
chainID string,
|
||||
trustingPeriod time.Duration,
|
||||
primaryAddress string,
|
||||
witnessesAddresses []string,
|
||||
trustedStore store.Store,
|
||||
options ...Option) (*Client, error) {
|
||||
|
||||
providers, err := providersFromAddresses(append(witnessesAddresses, primaryAddress), chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewClientFromTrustedStore(
|
||||
chainID,
|
||||
trustingPeriod,
|
||||
providers[len(providers)-1],
|
||||
providers[:len(providers)-1],
|
||||
trustedStore,
|
||||
options...)
|
||||
}
|
||||
|
||||
func providersFromAddresses(addrs []string, chainID string) ([]provider.Provider, error) {
|
||||
providers := make([]provider.Provider, len(addrs))
|
||||
for idx, address := range addrs {
|
||||
p, err := http.New(chainID, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
providers[idx] = p
|
||||
}
|
||||
return providers, nil
|
||||
}
|
||||
Reference in New Issue
Block a user