|
@ -295,7 +295,7 @@ func (c *Client) checkTrustedHeaderUsingOptions(ctx context.Context, options Tru |
|
|
c.logger.Info("Client initialized with old header (trusted is more recent)", |
|
|
c.logger.Info("Client initialized with old header (trusted is more recent)", |
|
|
"old", options.Height, |
|
|
"old", options.Height, |
|
|
"trustedHeight", c.latestTrustedBlock.Height, |
|
|
"trustedHeight", c.latestTrustedBlock.Height, |
|
|
"trustedHash", hash2str(c.latestTrustedBlock.Hash())) |
|
|
|
|
|
|
|
|
"trustedHash", c.latestTrustedBlock.Hash()) |
|
|
|
|
|
|
|
|
action := fmt.Sprintf( |
|
|
action := fmt.Sprintf( |
|
|
"Rollback to %d (%X)? Note this will remove newer light blocks up to %d (%X)", |
|
|
"Rollback to %d (%X)? Note this will remove newer light blocks up to %d (%X)", |
|
@ -319,7 +319,7 @@ func (c *Client) checkTrustedHeaderUsingOptions(ctx context.Context, options Tru |
|
|
|
|
|
|
|
|
if !bytes.Equal(primaryHash, c.latestTrustedBlock.Hash()) { |
|
|
if !bytes.Equal(primaryHash, c.latestTrustedBlock.Hash()) { |
|
|
c.logger.Info("Prev. trusted header's hash (h1) doesn't match hash from primary provider (h2)", |
|
|
c.logger.Info("Prev. trusted header's hash (h1) doesn't match hash from primary provider (h2)", |
|
|
"h1", hash2str(c.latestTrustedBlock.Hash()), "h2", hash2str(primaryHash)) |
|
|
|
|
|
|
|
|
"h1", c.latestTrustedBlock.Hash(), "h2", primaryHash) |
|
|
|
|
|
|
|
|
action := fmt.Sprintf( |
|
|
action := fmt.Sprintf( |
|
|
"Prev. trusted header's hash %X doesn't match hash %X from primary provider. Remove all the stored light blocks?", |
|
|
"Prev. trusted header's hash %X doesn't match hash %X from primary provider. Remove all the stored light blocks?", |
|
@ -434,7 +434,7 @@ func (c *Client) Update(ctx context.Context, now time.Time) (*types.LightBlock, |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
c.logger.Info("Advanced to new state", "height", latestBlock.Height, "hash", hash2str(latestBlock.Hash())) |
|
|
|
|
|
|
|
|
c.logger.Info("Advanced to new state", "height", latestBlock.Height, "hash", latestBlock.Hash()) |
|
|
return latestBlock, nil |
|
|
return latestBlock, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -459,7 +459,7 @@ func (c *Client) VerifyLightBlockAtHeight(ctx context.Context, height int64, now |
|
|
// Check if the light block already verified.
|
|
|
// Check if the light block already verified.
|
|
|
h, err := c.TrustedLightBlock(height) |
|
|
h, err := c.TrustedLightBlock(height) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
c.logger.Info("Header has already been verified", "height", height, "hash", hash2str(h.Hash())) |
|
|
|
|
|
|
|
|
c.logger.Info("Header has already been verified", "height", height, "hash", h.Hash()) |
|
|
// Return already trusted light block
|
|
|
// Return already trusted light block
|
|
|
return h, nil |
|
|
return h, nil |
|
|
} |
|
|
} |
|
@ -517,7 +517,7 @@ func (c *Client) VerifyHeader(ctx context.Context, newHeader *types.Header, now |
|
|
return fmt.Errorf("existing trusted header %X does not match newHeader %X", l.Hash(), newHeader.Hash()) |
|
|
return fmt.Errorf("existing trusted header %X does not match newHeader %X", l.Hash(), newHeader.Hash()) |
|
|
} |
|
|
} |
|
|
c.logger.Info("Header has already been verified", |
|
|
c.logger.Info("Header has already been verified", |
|
|
"height", newHeader.Height, "hash", hash2str(newHeader.Hash())) |
|
|
|
|
|
|
|
|
"height", newHeader.Height, "hash", newHeader.Hash()) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -535,7 +535,7 @@ func (c *Client) VerifyHeader(ctx context.Context, newHeader *types.Header, now |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (c *Client) verifyLightBlock(ctx context.Context, newLightBlock *types.LightBlock, now time.Time) error { |
|
|
func (c *Client) verifyLightBlock(ctx context.Context, newLightBlock *types.LightBlock, now time.Time) error { |
|
|
c.logger.Info("VerifyHeader", "height", newLightBlock.Height, "hash", hash2str(newLightBlock.Hash())) |
|
|
|
|
|
|
|
|
c.logger.Info("VerifyHeader", "height", newLightBlock.Height, "hash", newLightBlock.Hash()) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
verifyFunc func(ctx context.Context, trusted *types.LightBlock, new *types.LightBlock, now time.Time) error |
|
|
verifyFunc func(ctx context.Context, trusted *types.LightBlock, new *types.LightBlock, now time.Time) error |
|
@ -616,9 +616,9 @@ func (c *Client) verifySequential( |
|
|
// 2) Verify them
|
|
|
// 2) Verify them
|
|
|
c.logger.Debug("Verify adjacent newLightBlock against verifiedBlock", |
|
|
c.logger.Debug("Verify adjacent newLightBlock against verifiedBlock", |
|
|
"trustedHeight", verifiedBlock.Height, |
|
|
"trustedHeight", verifiedBlock.Height, |
|
|
"trustedHash", hash2str(verifiedBlock.Hash()), |
|
|
|
|
|
|
|
|
"trustedHash", verifiedBlock.Hash(), |
|
|
"newHeight", interimBlock.Height, |
|
|
"newHeight", interimBlock.Height, |
|
|
"newHash", hash2str(interimBlock.Hash())) |
|
|
|
|
|
|
|
|
"newHash", interimBlock.Hash()) |
|
|
|
|
|
|
|
|
err = VerifyAdjacent(verifiedBlock.SignedHeader, interimBlock.SignedHeader, interimBlock.ValidatorSet, |
|
|
err = VerifyAdjacent(verifiedBlock.SignedHeader, interimBlock.SignedHeader, interimBlock.ValidatorSet, |
|
|
c.trustingPeriod, now, c.maxClockDrift) |
|
|
c.trustingPeriod, now, c.maxClockDrift) |
|
@ -707,9 +707,9 @@ func (c *Client) verifySkipping( |
|
|
for { |
|
|
for { |
|
|
c.logger.Debug("Verify non-adjacent newHeader against verifiedBlock", |
|
|
c.logger.Debug("Verify non-adjacent newHeader against verifiedBlock", |
|
|
"trustedHeight", verifiedBlock.Height, |
|
|
"trustedHeight", verifiedBlock.Height, |
|
|
"trustedHash", hash2str(verifiedBlock.Hash()), |
|
|
|
|
|
|
|
|
"trustedHash", verifiedBlock.Hash(), |
|
|
"newHeight", blockCache[depth].Height, |
|
|
"newHeight", blockCache[depth].Height, |
|
|
"newHash", hash2str(blockCache[depth].Hash())) |
|
|
|
|
|
|
|
|
"newHash", blockCache[depth].Hash()) |
|
|
|
|
|
|
|
|
err := Verify(verifiedBlock.SignedHeader, verifiedBlock.ValidatorSet, blockCache[depth].SignedHeader, |
|
|
err := Verify(verifiedBlock.SignedHeader, verifiedBlock.ValidatorSet, blockCache[depth].SignedHeader, |
|
|
blockCache[depth].ValidatorSet, c.trustingPeriod, now, c.maxClockDrift, c.trustLevel) |
|
|
blockCache[depth].ValidatorSet, c.trustingPeriod, now, c.maxClockDrift, c.trustLevel) |
|
@ -929,9 +929,9 @@ func (c *Client) backwards( |
|
|
interimHeader = interimBlock.Header |
|
|
interimHeader = interimBlock.Header |
|
|
c.logger.Debug("Verify newHeader against verifiedHeader", |
|
|
c.logger.Debug("Verify newHeader against verifiedHeader", |
|
|
"trustedHeight", verifiedHeader.Height, |
|
|
"trustedHeight", verifiedHeader.Height, |
|
|
"trustedHash", hash2str(verifiedHeader.Hash()), |
|
|
|
|
|
|
|
|
"trustedHash", verifiedHeader.Hash(), |
|
|
"newHeight", interimHeader.Height, |
|
|
"newHeight", interimHeader.Height, |
|
|
"newHash", hash2str(interimHeader.Hash())) |
|
|
|
|
|
|
|
|
"newHash", interimHeader.Hash()) |
|
|
if err := VerifyBackwards(interimHeader, verifiedHeader); err != nil { |
|
|
if err := VerifyBackwards(interimHeader, verifiedHeader); err != nil { |
|
|
c.logger.Error("primary sent invalid header -> replacing", "err", err) |
|
|
c.logger.Error("primary sent invalid header -> replacing", "err", err) |
|
|
if replaceErr := c.replacePrimaryProvider(); replaceErr != nil { |
|
|
if replaceErr := c.replacePrimaryProvider(); replaceErr != nil { |
|
@ -1048,7 +1048,3 @@ and remove witness. Otherwise, use the different primary`, e.WitnessIndex), "wit |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func hash2str(hash []byte) string { |
|
|
|
|
|
return fmt.Sprintf("%X", hash) |
|
|
|
|
|
} |
|
|
|