Cleaned up naming of seed->commit
This commit is contained in:
+22
-22
@@ -29,7 +29,7 @@ var (
|
||||
|
||||
//nolint
|
||||
const (
|
||||
SeedFlag = "seed"
|
||||
CommitFlag = "commit"
|
||||
HashFlag = "valhash"
|
||||
GenesisFlag = "genesis"
|
||||
FlagTrustNode = "trust-node"
|
||||
@@ -52,7 +52,7 @@ var ResetCmd = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
InitCmd.Flags().Bool("force-reset", false, "Wipe clean an existing client store, except for keys")
|
||||
InitCmd.Flags().String(SeedFlag, "", "Seed file to import (optional)")
|
||||
InitCmd.Flags().String(CommitFlag, "", "Commit file to import (optional)")
|
||||
InitCmd.Flags().String(HashFlag, "", "Trusted validator hash (must match to accept)")
|
||||
InitCmd.Flags().String(GenesisFlag, "", "Genesis file with chainid and validators (optional)")
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func doInit(cmd *cobra.Command, root string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = initSeed()
|
||||
err = initTrust()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -275,27 +275,27 @@ func initConfigFile(cmd *cobra.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initSeed() (err error) {
|
||||
func initTrust() (err error) {
|
||||
// create a provider....
|
||||
trust, source := GetProviders()
|
||||
|
||||
// load a seed file, or get data from the provider
|
||||
var seed certifiers.FullCommit
|
||||
seedFile := viper.GetString(SeedFlag)
|
||||
if seedFile == "" {
|
||||
// load a commit file, or get data from the provider
|
||||
var fc certifiers.FullCommit
|
||||
commitFile := viper.GetString(CommitFlag)
|
||||
if commitFile == "" {
|
||||
fmt.Println("Loading validator set from tendermint rpc...")
|
||||
seed, err = source.LatestCommit()
|
||||
fc, err = source.LatestCommit()
|
||||
} else {
|
||||
fmt.Printf("Loading validators from file %s\n", seedFile)
|
||||
seed, err = files.LoadFullCommit(seedFile)
|
||||
fmt.Printf("Loading validators from file %s\n", commitFile)
|
||||
fc, err = files.LoadFullCommit(commitFile)
|
||||
}
|
||||
// can't load the seed? abort!
|
||||
// can't load the commit? abort!
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// make sure it is a proper seed
|
||||
err = seed.ValidateBasic(viper.GetString(ChainFlag))
|
||||
// make sure it is a proper commit
|
||||
err = fc.ValidateBasic(viper.GetString(ChainFlag))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -305,30 +305,30 @@ func initSeed() (err error) {
|
||||
if hash != "" {
|
||||
var hashb []byte
|
||||
hashb, err = hex.DecodeString(hash)
|
||||
if err == nil && !bytes.Equal(hashb, seed.ValidatorsHash()) {
|
||||
err = errors.Errorf("Seed hash doesn't match expectation: %X", seed.ValidatorsHash())
|
||||
if err == nil && !bytes.Equal(hashb, fc.ValidatorsHash()) {
|
||||
err = errors.Errorf("Validator hash doesn't match expectation: %X", fc.ValidatorsHash())
|
||||
}
|
||||
} else {
|
||||
err = validateHash(seed)
|
||||
err = validateHash(fc)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if accepted, store seed as current state
|
||||
trust.StoreCommit(seed)
|
||||
// if accepted, store commit as current state
|
||||
trust.StoreCommit(fc)
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateHash(seed certifiers.FullCommit) error {
|
||||
func validateHash(fc certifiers.FullCommit) error {
|
||||
// ask the user to verify the validator hash
|
||||
fmt.Println("\nImportant: if this is incorrect, all interaction with the chain will be insecure!")
|
||||
fmt.Printf(" Given validator hash valid: %X\n", seed.ValidatorsHash())
|
||||
fmt.Printf(" Given validator hash valid: %X\n", fc.ValidatorsHash())
|
||||
fmt.Println("Is this valid (y/n)?")
|
||||
valid := askForConfirmation()
|
||||
if !valid {
|
||||
return errors.New("Invalid validator hash, try init with proper seed later")
|
||||
return errors.New("Invalid validator hash, try init with proper commit later")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func txQueryCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
check, err := client.GetCertifiedCheckpoint(res.Height, node, cert)
|
||||
check, err := client.GetCertifiedCommit(res.Height, node, cert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+3
-3
@@ -38,15 +38,15 @@ func GetLocalProvider(dir string) certifiers.Provider {
|
||||
func GetCertifier(chainID string, trust certifiers.Provider,
|
||||
source certifiers.Provider) (*certifiers.Inquiring, error) {
|
||||
|
||||
// this gets the most recent verified seed
|
||||
seed, err := trust.LatestCommit()
|
||||
// this gets the most recent verified commit
|
||||
fc, err := trust.LatestCommit()
|
||||
if certerr.IsCommitNotFoundErr(err) {
|
||||
return nil, errors.New("Please run init first to establish a root of trust")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cert := certifiers.NewInquiring(chainID, seed, trust, source)
|
||||
cert := certifiers.NewInquiring(chainID, fc, trust, source)
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -47,8 +47,8 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
|
||||
}
|
||||
|
||||
// AppHash for height H is in header H+1
|
||||
var check *certifiers.Commit
|
||||
check, err = GetCertifiedCheckpoint(int(resp.Height+1), node, cert)
|
||||
var commit *certifiers.Commit
|
||||
commit, err = GetCertifiedCommit(int(resp.Height+1), node, cert)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
|
||||
}
|
||||
|
||||
// Validate the proof against the certified header to ensure data integrity.
|
||||
err = eproof.Verify(resp.Key, resp.Value, check.Header.AppHash)
|
||||
err = eproof.Verify(resp.Key, resp.Value, commit.Header.AppHash)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Couldn't verify proof")
|
||||
return
|
||||
@@ -79,7 +79,7 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
|
||||
return
|
||||
}
|
||||
// Validate the proof against the certified header to ensure data integrity.
|
||||
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
|
||||
err = aproof.Verify(resp.Key, nil, commit.Header.AppHash)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Couldn't verify proof")
|
||||
return
|
||||
@@ -92,9 +92,9 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
|
||||
return
|
||||
}
|
||||
|
||||
// GetCertifiedCheckpoint gets the signed header for a given height
|
||||
// GetCertifiedCommit gets the signed header for a given height
|
||||
// and certifies it. Returns error if unable to get a proven header.
|
||||
func GetCertifiedCheckpoint(h int, node client.Client,
|
||||
func GetCertifiedCommit(h int, node client.Client,
|
||||
cert certifiers.Certifier) (empty *certifiers.Commit, err error) {
|
||||
|
||||
// FIXME: cannot use cert.GetByHeight for now, as it also requires
|
||||
|
||||
@@ -141,8 +141,8 @@ func TestTxProofs(t *testing.T) {
|
||||
err = res.Proof.Validate(key)
|
||||
assert.NoError(err, "%+v", err)
|
||||
|
||||
check, err := GetCertifiedCheckpoint(int(br.Height), cl, cert)
|
||||
commit, err := GetCertifiedCommit(int(br.Height), cl, cert)
|
||||
require.Nil(err, "%+v", err)
|
||||
require.Equal(res.Proof.RootHash, check.Header.DataHash)
|
||||
require.Equal(res.Proof.RootHash, commit.Header.DataHash)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user