mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-24 09:40:32 +00:00
Refs #1771 ADR: https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-044-lite-client-with-weak-subjectivity.md ## Commits: * add Verifier and VerifyCommitTrusting * add two more checks make trustLevel an option * float32 for trustLevel * check newHeader time * started writing lite Client * unify Verify methods * ensure h2.Header.bfttime < h1.Header.bfttime + tp * move trust checks into Verify function * add more comments * more docs * started writing tests * unbonding period failures * tests are green * export ErrNewHeaderTooFarIntoFuture * make golangci happy * test for non-adjusted headers * more precision * providers and stores * VerifyHeader and VerifyHeaderAtHeight funcs * fix compile errors * remove lastVerifiedHeight, persist new trusted header * sequential verification * remove TrustedStore option * started writing tests for light client * cover basic cases for linear verification * bisection tests PASS * rename BisectingVerification to SkippingVerification * refactor the code * add TrustedHeader method * consolidate sequential verification tests * consolidate skipping verification tests * rename trustedVals to trustedNextVals * start writing docs * ValidateTrustLevel func and ErrOldHeaderExpired error * AutoClient and example tests * fix errors * update doc * remove ErrNewHeaderTooFarIntoFuture This check is unnecessary given existing a) ErrOldHeaderExpired b) h2.Time > now checks. * return an error if we're at more recent height * add comments * add LastSignedHeaderHeight method to Store I think it's fine if Store tracks last height * copy over proxy from old lite package * make TrustedHeader return latest if height=0 * modify LastSignedHeaderHeight to return an error if no headers exist * copy over proxy impl * refactor proxy and start http lite client * Tx and BlockchainInfo methods * Block method * commit method * code compiles again * lite client compiles * extract updateLiteClientIfNeededTo func * move final parts * add placeholder for tests * force usage of lite http client in proxy * comment out query tests for now * explicitly mention tp: trusting period * verify nextVals in VerifyHeader * refactor bisection * move the NextValidatorsHash check into updateTrustedHeaderAndVals + update the comment * add ConsensusParams method to RPC client * add ConsensusParams to rpc/mock/client * change trustLevel type to a new cmn.Fraction type + update SkippingVerification comment * stress out trustLevel is only used for non-adjusted headers * fixes after Fede's review Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * compare newHeader with a header from an alternative provider * save pivot header Refs https://github.com/tendermint/tendermint/pull/3989#discussion_r349122824 * check header can still be trusted in TrustedHeader Refs https://github.com/tendermint/tendermint/pull/3989#discussion_r349101424 * lite: update Validators and Block endpoints - Block no longer contains BlockMeta - Validators now accept two additional params: page and perPage * make linter happy
123 lines
4.5 KiB
Go
123 lines
4.5 KiB
Go
package client
|
|
|
|
/*
|
|
The client package provides a general purpose interface (Client) for connecting
|
|
to a tendermint node, as well as higher-level functionality.
|
|
|
|
The main implementation for production code is client.HTTP, which
|
|
connects via http to the jsonrpc interface of the tendermint node.
|
|
|
|
For connecting to a node running in the same process (eg. when
|
|
compiling the abci app in the same process), you can use the client.Local
|
|
implementation.
|
|
|
|
For mocking out server responses during testing to see behavior for
|
|
arbitrary return values, use the mock package.
|
|
|
|
In addition to the Client interface, which should be used externally
|
|
for maximum flexibility and testability, and two implementations,
|
|
this package also provides helper functions that work on any Client
|
|
implementation.
|
|
*/
|
|
|
|
import (
|
|
"context"
|
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// Client wraps most important rpc calls a client would make if you want to
|
|
// listen for events, test if it also implements events.EventSwitch.
|
|
type Client interface {
|
|
cmn.Service
|
|
ABCIClient
|
|
EventsClient
|
|
HistoryClient
|
|
NetworkClient
|
|
SignClient
|
|
StatusClient
|
|
EvidenceClient
|
|
MempoolClient
|
|
}
|
|
|
|
// ABCIClient groups together the functionality that principally affects the
|
|
// ABCI app.
|
|
//
|
|
// In many cases this will be all we want, so we can accept an interface which
|
|
// is easier to mock.
|
|
type ABCIClient interface {
|
|
// Reading from abci app
|
|
ABCIInfo() (*ctypes.ResultABCIInfo, error)
|
|
ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
|
|
ABCIQueryWithOptions(path string, data cmn.HexBytes,
|
|
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
|
|
|
|
// Writing to abci app
|
|
BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
|
|
BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
|
BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
|
}
|
|
|
|
// SignClient groups together the functionality needed to get valid signatures
|
|
// and prove anything about the chain.
|
|
type SignClient interface {
|
|
Block(height *int64) (*ctypes.ResultBlock, error)
|
|
BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
|
|
Commit(height *int64) (*ctypes.ResultCommit, error)
|
|
Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error)
|
|
Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
|
|
TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
|
|
}
|
|
|
|
// HistoryClient provides access to data from genesis to now in large chunks.
|
|
type HistoryClient interface {
|
|
Genesis() (*ctypes.ResultGenesis, error)
|
|
BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
|
|
}
|
|
|
|
// StatusClient provides access to general chain info.
|
|
type StatusClient interface {
|
|
Status() (*ctypes.ResultStatus, error)
|
|
}
|
|
|
|
// NetworkClient is general info about the network state. May not be needed
|
|
// usually.
|
|
type NetworkClient interface {
|
|
NetInfo() (*ctypes.ResultNetInfo, error)
|
|
DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
|
|
ConsensusState() (*ctypes.ResultConsensusState, error)
|
|
ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
|
|
Health() (*ctypes.ResultHealth, error)
|
|
}
|
|
|
|
// EventsClient is reactive, you can subscribe to any message, given the proper
|
|
// string. see tendermint/types/events.go
|
|
type EventsClient interface {
|
|
// Subscribe subscribes given subscriber to query. Returns a channel with
|
|
// cap=1 onto which events are published. An error is returned if it fails to
|
|
// subscribe. outCapacity can be used optionally to set capacity for the
|
|
// channel. Channel is never closed to prevent accidental reads.
|
|
//
|
|
// ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe
|
|
// or UnsubscribeAll.
|
|
Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
|
|
// Unsubscribe unsubscribes given subscriber from query.
|
|
Unsubscribe(ctx context.Context, subscriber, query string) error
|
|
// UnsubscribeAll unsubscribes given subscriber from all the queries.
|
|
UnsubscribeAll(ctx context.Context, subscriber string) error
|
|
}
|
|
|
|
// MempoolClient shows us data about current mempool state.
|
|
type MempoolClient interface {
|
|
UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
|
|
NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
|
|
}
|
|
|
|
// EvidenceClient is used for submitting an evidence of the malicious
|
|
// behaviour.
|
|
type EvidenceClient interface {
|
|
BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
|
|
}
|