Fixes from review

This commit is contained in:
Jae Kwon 2018-06-25 16:31:59 -07:00
parent c3296f2e01
commit 538c410bcd
7 changed files with 46 additions and 72 deletions

31
Gopkg.lock generated
View File

@ -7,12 +7,6 @@
packages = ["quantile"]
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
[[projects]]
branch = "master"
name = "github.com/brejski/hid"
packages = ["."]
revision = "06112dcfcc50a7e0e4fd06e17f9791e788fdaafc"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
@ -290,17 +284,7 @@
"leveldb/table",
"leveldb/util"
]
revision = "e2150783cd35f5b607daca48afd8c57ec54cc995"
[[projects]]
name = "github.com/tendermint/abci"
packages = [
"example/code",
"example/kvstore",
"types"
]
revision = "198dccf0ddfd1bb176f87657e3286a05a6ed9540"
version = "v0.12.0"
revision = "0d5a0ceb10cf9ab89fdd744cc8c50a83134f6697"
[[projects]]
branch = "master"
@ -333,13 +317,8 @@
"merkle/tmhash",
"test"
]
revision = "fb7ec62b2925f48de159aeea73b254ae8c58a738"
version = "v0.9.0-rc1"
[[projects]]
name = "github.com/zondax/ledger-goclient"
packages = ["."]
revision = "3e2146609cdb97894c064d59e9d00accd8c2b1dd"
revision = "49596e0a1f48866603813df843c9409fc19805c6"
version = "v0.9.0"
[[projects]]
branch = "master"
@ -374,7 +353,7 @@
"netutil",
"trace"
]
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196"
revision = "afe8f62b1d6bbd81f31868121a50b06d8188e1f9"
[[projects]]
branch = "master"
@ -444,6 +423,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "fcc5b0344f1e328b6abefa1a937d1161e14bbaef603e6f2065e6690531bc5de1"
inputs-digest = "c25289282b94abc7f0c390e592e5e1636b7f26cb4773863ac39cde7fdc7b5bdf"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -79,7 +79,7 @@
[[override]]
name = "github.com/tendermint/tmlibs"
version = "0.9.0-rc1"
version = "~0.9.0"
[[constraint]]
name = "google.golang.org/grpc"

View File

@ -266,7 +266,7 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight
// If appBlockHeight == 0 it means that we are at genesis and hence should send InitChain.
if appBlockHeight == 0 {
nextVals := types.TM2PB.Validators(state.Validators) // state.Validators would work too.
nextVals := types.TM2PB.Validators(state.NextValidators) // state.Validators would work too.
csParams := types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams)
req := abci.RequestInitChain{
Time: h.genDoc.GenesisTime.Unix(), // TODO

View File

@ -106,28 +106,23 @@ func (p *provider) getValidatorSet(chainID string, height int64) (valset *types.
return nil, lerr.ErrMissingValidators(chainID, height)
}
valset = types.NewValidatorSet(res.Validators)
valset.TotalVotingPower() // to test deep equality.
return
}
// This does no validation.
func (p *provider) fillFullCommit(signedHeader types.SignedHeader) (fc lite.FullCommit, err error) {
fc.SignedHeader = signedHeader
// Get the validators.
valset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height)
if err != nil {
return lite.FullCommit{}, err
}
fc.Validators = valset
// Get the next validators.
nextValset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height+1)
if err != nil {
return lite.FullCommit{}, err
} else {
fc.NextValidators = nextValset
}
return fc, nil
return lite.NewFullCommit(signedHeader, valset, nextValset), nil
}

View File

@ -51,7 +51,7 @@ func TestProvider(t *testing.T) {
assert.True(sh < 5000)
// let's check this is valid somehow
assert.Nil(fc.ValidateBasic(chainID))
assert.Nil(fc.ValidateFull(chainID))
// historical queries now work :)
lower := sh - 5

View File

@ -12,7 +12,7 @@ import (
// the validator set which signed the commit, and the next validator set. The
// next validator set (which is proven from the block header) allows us to
// revert to block-by-block updating of lite certifier's latest validator set,
// even in the face of arbitrarily power changes.
// even in the face of arbitrarily large power changes.
type FullCommit struct {
SignedHeader types.SignedHeader `json:"signed_header"`
Validators *types.ValidatorSet `json:"validator_set"`
@ -33,7 +33,7 @@ func NewFullCommit(signedHeader types.SignedHeader, valset, nextValset *types.Va
// signed the SignedHeader.Commit.
// If > 2/3 did not sign the Commit from fc.Validators, it
// is not a valid commit!
func (fc FullCommit) ValidateBasic(chainID string) error {
func (fc FullCommit) ValidateFull(chainID string) error {
// Ensure that Validators exists and matches the header.
if fc.Validators.Size() == 0 {
return errors.New("need FullCommit.Validators")

View File

@ -101,21 +101,21 @@ func (ic *InquiringCertifier) Certify(shdr types.SignedHeader) error {
return nil
} else if err != nil {
return err
} else {
// Create filled FullCommit.
nfc := FullCommit{
SignedHeader: shdr,
Validators: tfc.NextValidators,
NextValidators: nextValset,
}
// Validate the full commit. This checks the cryptographic
// signatures of Commit against Validators.
if err := nfc.ValidateBasic(ic.chainID); err != nil {
return err
}
// Trust it.
return ic.trusted.SaveFullCommit(nfc)
}
// Create filled FullCommit.
nfc := FullCommit{
SignedHeader: shdr,
Validators: tfc.NextValidators,
NextValidators: nextValset,
}
// Validate the full commit. This checks the cryptographic
// signatures of Commit against Validators.
if err := nfc.ValidateFull(ic.chainID); err != nil {
return err
}
// Trust it.
return ic.trusted.SaveFullCommit(nfc)
}
// verifyAndSave will verify if this is a valid source full commit given the
@ -139,7 +139,7 @@ func (ic *InquiringCertifier) verifyAndSave(tfc, sfc FullCommit) error {
}
// updateToHeight will use divide-and-conquer to find a path to h.
// Returns nil iff we successfully verify and persist a full commit
// Returns nil error iff we successfully verify and persist a full commit
// for height h, using repeated applications of bisection if necessary.
//
// Returns ErrCommitNotFound if source provider doesn't have the commit for h.
@ -153,7 +153,7 @@ func (ic *InquiringCertifier) updateToHeight(h int64) (FullCommit, error) {
// Validate the full commit. This checks the cryptographic
// signatures of Commit against Validators.
if err := sfc.ValidateBasic(ic.chainID); err != nil {
if err := sfc.ValidateFull(ic.chainID); err != nil {
return FullCommit{}, err
}
@ -169,9 +169,9 @@ FOR_LOOP:
if err != nil {
return FullCommit{}, err
}
// Maybe we have nothing to do.
// We have nothing to do.
if tfc.Height() == h {
return FullCommit{}, nil
return tfc, nil
}
// Try to update to full commit with checks.
@ -179,24 +179,24 @@ FOR_LOOP:
if err == nil {
// All good!
return sfc, nil
} else {
// Handle special case when err is ErrTooMuchChange.
if lerr.IsErrTooMuchChange(err) {
// Divide and conquer.
start, end := tfc.Height(), sfc.Height()
if !(start < end) {
panic("should not happen")
}
mid := (start + end) / 2
_, err = ic.updateToHeight(mid)
if err != nil {
return FullCommit{}, err
}
// If we made it to mid, we retry.
continue FOR_LOOP
}
return FullCommit{}, err
}
// Handle special case when err is ErrTooMuchChange.
if lerr.IsErrTooMuchChange(err) {
// Divide and conquer.
start, end := tfc.Height(), sfc.Height()
if !(start < end) {
panic("should not happen")
}
mid := (start + end) / 2
_, err = ic.updateToHeight(mid)
if err != nil {
return FullCommit{}, err
}
// If we made it to mid, we retry.
continue FOR_LOOP
}
return FullCommit{}, err
}
}