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