@ -617,7 +617,7 @@ func (c *Client) VerifyHeader(newHeader *types.SignedHeader, newVals *types.Vali
var err error
var err error
switch c . verificationMode {
switch c . verificationMode {
case sequential :
case sequential :
err = c . sequence ( newHeader , newVals , now )
err = c . sequence ( c . trustedHeader , c . trustedNextVals , newHeader , newVals , now )
case skipping :
case skipping :
err = c . bisection ( c . trustedHeader , c . trustedNextVals , newHeader , newVals , now )
err = c . bisection ( c . trustedHeader , c . trustedNextVals , newHeader , newVals , now )
default :
default :
@ -697,25 +697,30 @@ func (c *Client) cleanup(stopHeight int64) error {
}
}
// see VerifyHeader
// see VerifyHeader
func ( c * Client ) sequence ( newHeader * types . SignedHeader , newVals * types . ValidatorSet , now time . Time ) error {
func ( c * Client ) sequence (
trustedHeader * types . SignedHeader ,
trustedNextVals * types . ValidatorSet ,
newHeader * types . SignedHeader ,
newVals * types . ValidatorSet ,
now time . Time ) error {
// 1) Verify any intermediate headers.
// 1) Verify any intermediate headers.
var (
var (
interimHeader * types . SignedHeader
nextVals * types . ValidatorSet
err error
interimHeader * types . SignedHeader
i nterimN extVals * types . ValidatorSet
err error
)
)
for height := c . trustedHeader . Height + 1 ; height < newHeader . Height ; height ++ {
for height := trustedHeader . Height + 1 ; height < newHeader . Height ; height ++ {
interimHeader , err = c . signedHeaderFromPrimary ( height )
interimHeader , err = c . signedHeaderFromPrimary ( height )
if err != nil {
if err != nil {
return errors . Wrapf ( err , "failed to obtain the header #%d" , height )
return errors . Wrapf ( err , "failed to obtain the header #%d" , height )
}
}
c . logger . Debug ( "Verify newHeader against last Header" ,
c . logger . Debug ( "Verify newHeader against trusted Header" ,
"lastHeight" , c . trustedHeader . Height ,
"lastHeight" , c . trustedHeader . Height ,
"lastHash" , c . trustedHeader . Hash ( ) ,
"lastHash" , c . trustedHeader . Hash ( ) ,
"newHeight" , interimHeader . Height ,
"newHeight" , interimHeader . Height ,
"newHash" , interimHeader . Hash ( ) )
"newHash" , interimHeader . Hash ( ) )
err = Verify ( c . chainID , c . trustedHeader , c . trustedNextVals , interimHeader , c . trustedNextVals ,
err = Verify ( c . chainID , trustedHeader , trustedNextVals , interimHeader , trustedNextVals ,
c . trustingPeriod , now , c . trustLevel )
c . trustingPeriod , now , c . trustLevel )
if err != nil {
if err != nil {
return errors . Wrapf ( err , "failed to verify the header #%d" , height )
return errors . Wrapf ( err , "failed to verify the header #%d" , height )
@ -723,17 +728,18 @@ func (c *Client) sequence(newHeader *types.SignedHeader, newVals *types.Validato
// Update trusted header and vals.
// Update trusted header and vals.
if height == newHeader . Height - 1 {
if height == newHeader . Height - 1 {
nextVals = newVals
i nterimN extVals = newVals
} else {
} else {
nextVals , err = c . validatorSetFromPrimary ( height + 1 )
i nterimN extVals, err = c . validatorSetFromPrimary ( height + 1 )
if err != nil {
if err != nil {
return errors . Wrapf ( err , "failed to obtain the vals #%d" , height + 1 )
return errors . Wrapf ( err , "failed to obtain the vals #%d" , height + 1 )
}
}
}
}
err = c . updateTrustedHeaderAndVals ( interimHeader , nextVals )
err = c . updateTrustedHeaderAndVals ( interimHeader , i nterimN extVals)
if err != nil {
if err != nil {
return errors . Wrapf ( err , "failed to update trusted state #%d" , height )
return errors . Wrapf ( err , "failed to update trusted state #%d" , height )
}
}
trustedHeader , trustedNextVals = interimHeader , interimNextVals
}
}
// 2) Verify the new header.
// 2) Verify the new header.