mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-28 16:22:15 +00:00
Fixes from review
This commit is contained in:
parent
c3296f2e01
commit
538c410bcd
31
Gopkg.lock
generated
31
Gopkg.lock
generated
@ -7,12 +7,6 @@
|
|||||||
packages = ["quantile"]
|
packages = ["quantile"]
|
||||||
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
|
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/brejski/hid"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "06112dcfcc50a7e0e4fd06e17f9791e788fdaafc"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/btcsuite/btcd"
|
name = "github.com/btcsuite/btcd"
|
||||||
@ -290,17 +284,7 @@
|
|||||||
"leveldb/table",
|
"leveldb/table",
|
||||||
"leveldb/util"
|
"leveldb/util"
|
||||||
]
|
]
|
||||||
revision = "e2150783cd35f5b607daca48afd8c57ec54cc995"
|
revision = "0d5a0ceb10cf9ab89fdd744cc8c50a83134f6697"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/tendermint/abci"
|
|
||||||
packages = [
|
|
||||||
"example/code",
|
|
||||||
"example/kvstore",
|
|
||||||
"types"
|
|
||||||
]
|
|
||||||
revision = "198dccf0ddfd1bb176f87657e3286a05a6ed9540"
|
|
||||||
version = "v0.12.0"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -333,13 +317,8 @@
|
|||||||
"merkle/tmhash",
|
"merkle/tmhash",
|
||||||
"test"
|
"test"
|
||||||
]
|
]
|
||||||
revision = "fb7ec62b2925f48de159aeea73b254ae8c58a738"
|
revision = "49596e0a1f48866603813df843c9409fc19805c6"
|
||||||
version = "v0.9.0-rc1"
|
version = "v0.9.0"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/zondax/ledger-goclient"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "3e2146609cdb97894c064d59e9d00accd8c2b1dd"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -374,7 +353,7 @@
|
|||||||
"netutil",
|
"netutil",
|
||||||
"trace"
|
"trace"
|
||||||
]
|
]
|
||||||
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196"
|
revision = "afe8f62b1d6bbd81f31868121a50b06d8188e1f9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -444,6 +423,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "fcc5b0344f1e328b6abefa1a937d1161e14bbaef603e6f2065e6690531bc5de1"
|
inputs-digest = "c25289282b94abc7f0c390e592e5e1636b7f26cb4773863ac39cde7fdc7b5bdf"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
name = "github.com/tendermint/tmlibs"
|
name = "github.com/tendermint/tmlibs"
|
||||||
version = "0.9.0-rc1"
|
version = "~0.9.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
|
@ -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 it means that we are at genesis and hence should send InitChain.
|
||||||
if appBlockHeight == 0 {
|
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)
|
csParams := types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams)
|
||||||
req := abci.RequestInitChain{
|
req := abci.RequestInitChain{
|
||||||
Time: h.genDoc.GenesisTime.Unix(), // TODO
|
Time: h.genDoc.GenesisTime.Unix(), // TODO
|
||||||
|
@ -106,28 +106,23 @@ func (p *provider) getValidatorSet(chainID string, height int64) (valset *types.
|
|||||||
return nil, lerr.ErrMissingValidators(chainID, height)
|
return nil, lerr.ErrMissingValidators(chainID, height)
|
||||||
}
|
}
|
||||||
valset = types.NewValidatorSet(res.Validators)
|
valset = types.NewValidatorSet(res.Validators)
|
||||||
valset.TotalVotingPower() // to test deep equality.
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This does no validation.
|
// This does no validation.
|
||||||
func (p *provider) fillFullCommit(signedHeader types.SignedHeader) (fc lite.FullCommit, err error) {
|
func (p *provider) fillFullCommit(signedHeader types.SignedHeader) (fc lite.FullCommit, err error) {
|
||||||
fc.SignedHeader = signedHeader
|
|
||||||
|
|
||||||
// Get the validators.
|
// Get the validators.
|
||||||
valset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height)
|
valset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return lite.FullCommit{}, err
|
return lite.FullCommit{}, err
|
||||||
}
|
}
|
||||||
fc.Validators = valset
|
|
||||||
|
|
||||||
// Get the next validators.
|
// Get the next validators.
|
||||||
nextValset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height+1)
|
nextValset, err := p.getValidatorSet(signedHeader.ChainID, signedHeader.Height+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return lite.FullCommit{}, err
|
return lite.FullCommit{}, err
|
||||||
} else {
|
|
||||||
fc.NextValidators = nextValset
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fc, nil
|
return lite.NewFullCommit(signedHeader, valset, nextValset), nil
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func TestProvider(t *testing.T) {
|
|||||||
assert.True(sh < 5000)
|
assert.True(sh < 5000)
|
||||||
|
|
||||||
// let's check this is valid somehow
|
// let's check this is valid somehow
|
||||||
assert.Nil(fc.ValidateBasic(chainID))
|
assert.Nil(fc.ValidateFull(chainID))
|
||||||
|
|
||||||
// historical queries now work :)
|
// historical queries now work :)
|
||||||
lower := sh - 5
|
lower := sh - 5
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
// the validator set which signed the commit, and the next validator set. The
|
// 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
|
// 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,
|
// 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 {
|
type FullCommit struct {
|
||||||
SignedHeader types.SignedHeader `json:"signed_header"`
|
SignedHeader types.SignedHeader `json:"signed_header"`
|
||||||
Validators *types.ValidatorSet `json:"validator_set"`
|
Validators *types.ValidatorSet `json:"validator_set"`
|
||||||
@ -33,7 +33,7 @@ func NewFullCommit(signedHeader types.SignedHeader, valset, nextValset *types.Va
|
|||||||
// signed the SignedHeader.Commit.
|
// signed the SignedHeader.Commit.
|
||||||
// If > 2/3 did not sign the Commit from fc.Validators, it
|
// If > 2/3 did not sign the Commit from fc.Validators, it
|
||||||
// is not a valid commit!
|
// 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.
|
// Ensure that Validators exists and matches the header.
|
||||||
if fc.Validators.Size() == 0 {
|
if fc.Validators.Size() == 0 {
|
||||||
return errors.New("need FullCommit.Validators")
|
return errors.New("need FullCommit.Validators")
|
||||||
|
@ -101,21 +101,21 @@ func (ic *InquiringCertifier) Certify(shdr types.SignedHeader) error {
|
|||||||
return nil
|
return nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
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
|
// 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.
|
// 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.
|
// for height h, using repeated applications of bisection if necessary.
|
||||||
//
|
//
|
||||||
// Returns ErrCommitNotFound if source provider doesn't have the commit for h.
|
// 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
|
// Validate the full commit. This checks the cryptographic
|
||||||
// signatures of Commit against Validators.
|
// signatures of Commit against Validators.
|
||||||
if err := sfc.ValidateBasic(ic.chainID); err != nil {
|
if err := sfc.ValidateFull(ic.chainID); err != nil {
|
||||||
return FullCommit{}, err
|
return FullCommit{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,9 +169,9 @@ FOR_LOOP:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return FullCommit{}, err
|
return FullCommit{}, err
|
||||||
}
|
}
|
||||||
// Maybe we have nothing to do.
|
// We have nothing to do.
|
||||||
if tfc.Height() == h {
|
if tfc.Height() == h {
|
||||||
return FullCommit{}, nil
|
return tfc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to update to full commit with checks.
|
// Try to update to full commit with checks.
|
||||||
@ -179,24 +179,24 @@ FOR_LOOP:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
// All good!
|
// All good!
|
||||||
return sfc, nil
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user