You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.1 KiB

lite2: light client with weak subjectivity (#3989) 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
5 years ago
  1. package lite
  2. //func TestExample_Client(t *testing.T) {
  3. // const (
  4. // chainID = "my-awesome-chain"
  5. // )
  6. // dbDir, err := ioutil.TempDir("", "lite-client-example")
  7. // if err != nil {
  8. // t.Fatal(err)
  9. // }
  10. // defer os.RemoveAll(dbDir)
  11. // // TODO: fetch the "trusted" header from a node
  12. // header := (*types.SignedHeader)(nil)
  13. // /////////////////////////////////////////////////////////////////////////////
  14. // db, err := dbm.NewGoLevelDB("lite-client-db", dbDir)
  15. // if err != nil {
  16. // // return err
  17. // t.Fatal(err)
  18. // }
  19. // c, err := NewClient(
  20. // chainID,
  21. // TrustOptions{
  22. // Period: 504 * time.Hour, // 21 days
  23. // Height: 100,
  24. // Hash: header.Hash(),
  25. // },
  26. // httpp.New(chainID, "tcp://localhost:26657"),
  27. // dbs.New(db, chainID),
  28. // )
  29. // err = c.VerifyHeaderAtHeight(101, time.Now())
  30. // if err != nil {
  31. // fmt.Println("retry?")
  32. // }
  33. // h, err := c.TrustedHeader(101)
  34. // if err != nil {
  35. // fmt.Println("retry?")
  36. // }
  37. // fmt.Println("got header", h)
  38. // // verify some data
  39. //}
  40. //func TestExample_AutoClient(t *testing.T) {
  41. // const (
  42. // chainID = "my-awesome-chain"
  43. // )
  44. // dbDir, err := ioutil.TempDir("", "lite-client-example")
  45. // if err != nil {
  46. // t.Fatal(err)
  47. // }
  48. // defer os.RemoveAll(dbDir)
  49. // // TODO: fetch the "trusted" header from a node
  50. // header := (*types.SignedHeader)(nil)
  51. // /////////////////////////////////////////////////////////////////////////////
  52. // db, err := dbm.NewGoLevelDB("lite-client-db", dbDir)
  53. // if err != nil {
  54. // // return err
  55. // t.Fatal(err)
  56. // }
  57. // base, err := NewClient(
  58. // chainID,
  59. // TrustOptions{
  60. // Period: 504 * time.Hour, // 21 days
  61. // Height: 100,
  62. // Hash: header.Hash(),
  63. // },
  64. // httpp.New(chainID, "tcp://localhost:26657"),
  65. // dbs.New(db, chainID),
  66. // )
  67. // c := NewAutoClient(base, 1*time.Second)
  68. // defer c.Stop()
  69. // select {
  70. // case h := <-c.TrustedHeaders():
  71. // fmt.Println("got header", h)
  72. // // verify some data
  73. // case err := <-c.Err():
  74. // switch errors.Cause(err).(type) {
  75. // case ErrOldHeaderExpired:
  76. // // reobtain trust height and hash
  77. // default:
  78. // // try with another full node
  79. // fmt.Println("got error", err)
  80. // }
  81. // }
  82. //}