mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 14:25:19 +00:00
e2e: integrate light clients (bp #6196)
integrate light clients (#6196) fix e2e app test (#6223) fix light client generator (#6236)
This commit is contained in:
@@ -891,6 +891,8 @@ func (c *Client) cleanupAfter(height int64) error {
|
||||
}
|
||||
|
||||
func (c *Client) updateTrustedLightBlock(l *types.LightBlock) error {
|
||||
c.logger.Debug("updating trusted light block", "light_block", l)
|
||||
|
||||
if err := c.trustedStore.SaveLightBlock(l); err != nil {
|
||||
return fmt.Errorf("failed to save trusted header: %w", err)
|
||||
}
|
||||
@@ -1033,10 +1035,12 @@ and remove witness. Otherwise, use the different primary`, e.WitnessIndex), "wit
|
||||
// respond or couldn't find the block, then we ignore it and move on to
|
||||
// the next witness.
|
||||
if _, ok := e.Reason.(provider.ErrBadLightBlock); ok {
|
||||
c.logger.Info("Witness sent us invalid header / vals -> removing it", "witness", c.witnesses[e.WitnessIndex])
|
||||
c.logger.Info("Witness sent us invalid header / vals -> removing it",
|
||||
"witness", c.witnesses[e.WitnessIndex], "err", err)
|
||||
witnessesToRemove = append(witnessesToRemove, e.WitnessIndex)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// we need to make sure that we remove witnesses by index in the reverse
|
||||
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lrpc "github.com/tendermint/tendermint/light/rpc"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
||||
)
|
||||
|
||||
@@ -21,6 +23,28 @@ type Proxy struct {
|
||||
Listener net.Listener
|
||||
}
|
||||
|
||||
// NewProxy creates the struct used to run an HTTP server for serving light
|
||||
// client rpc requests.
|
||||
func NewProxy(
|
||||
lightClient *light.Client,
|
||||
listenAddr, providerAddr string,
|
||||
config *rpcserver.Config,
|
||||
logger log.Logger,
|
||||
opts ...lrpc.Option,
|
||||
) (*Proxy, error) {
|
||||
rpcClient, err := rpchttp.NewWithTimeout(providerAddr, "/websocket", uint(config.WriteTimeout.Seconds()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create http client for %s: %w", providerAddr, err)
|
||||
}
|
||||
|
||||
return &Proxy{
|
||||
Addr: listenAddr,
|
||||
Config: config,
|
||||
Client: lrpc.NewClient(rpcClient, lightClient, opts...),
|
||||
Logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListenAndServe configures the rpcserver.WebsocketManager, sets up the RPC
|
||||
// routes to proxy via Client, and starts up an HTTP server on the TCP network
|
||||
// address p.Addr.
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@@ -61,6 +62,27 @@ func KeyPathFn(fn KeyPathFunc) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultMerkleKeyPathFn creates a function used to generate merkle key paths
|
||||
// from a path string and a key. This is the default used by the cosmos SDK.
|
||||
// This merkle key paths are required when verifying /abci_query calls
|
||||
func DefaultMerkleKeyPathFn() KeyPathFunc {
|
||||
// regexp for extracting store name from /abci_query path
|
||||
storeNameRegexp := regexp.MustCompile(`\/store\/(.+)\/key`)
|
||||
|
||||
return func(path string, key []byte) (merkle.KeyPath, error) {
|
||||
matches := storeNameRegexp.FindStringSubmatch(path)
|
||||
if len(matches) != 2 {
|
||||
return nil, fmt.Errorf("can't find store name in %s using %s", path, storeNameRegexp)
|
||||
}
|
||||
storeName := matches[1]
|
||||
|
||||
kp := merkle.KeyPath{}
|
||||
kp = kp.AppendKey([]byte(storeName), merkle.KeyEncodingURL)
|
||||
kp = kp.AppendKey(key, merkle.KeyEncodingURL)
|
||||
return kp, nil
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient returns a new client.
|
||||
func NewClient(next rpcclient.Client, lc LightClient, opts ...Option) *Client {
|
||||
c := &Client{
|
||||
|
||||
Reference in New Issue
Block a user