Skip to content

Commit

Permalink
fix: add check for prevNetworkSectionHash
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksharmapoudel committed Jul 10, 2023
1 parent ec7b212 commit 5f46ecb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package icon

import (
"bytes"
"context"
"fmt"
"sort"
Expand Down Expand Up @@ -66,8 +67,9 @@ type IconChainProcessor struct {
}

type Verifier struct {
nextProofContext [][]byte
verifiedHeight int64
nextProofContext [][]byte
verifiedHeight int64
prevNetworkSectionHash []byte
}

func NewIconChainProcessor(log *zap.Logger, provider *IconProvider, metrics *processor.PrometheusMetrics) *IconChainProcessor {
Expand Down Expand Up @@ -459,6 +461,12 @@ func (icp *IconChainProcessor) verifyBlock(ctx context.Context, ibcHeader provid
return nil
}

Check warning on line 462 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L458-L462

Added lines #L458 - L462 were not covered by tests

// prevNetworkSectionHash would be nil for first block
if icp.verifier.prevNetworkSectionHash != nil &&
!bytes.Equal(icp.verifier.prevNetworkSectionHash, header.Header.PrevNetworkSectionHash) {
return fmt.Errorf("failed to match prevNetworkSectionHash")
}

Check warning on line 468 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L465-L468

Added lines #L465 - L468 were not covered by tests

sigs, err := icp.chainProvider.GetBTPProof(int64(header.MainHeight))
if err != nil {
return err
Expand All @@ -482,8 +490,10 @@ func (icp *IconChainProcessor) verifyBlock(ctx context.Context, ibcHeader provid
if !valid {
return fmt.Errorf("failed to Verify block")
}

Check warning on line 492 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L490-L492

Added lines #L490 - L492 were not covered by tests

icp.verifier.nextProofContext = header.Validators
icp.verifier.verifiedHeight = int64(header.Height())
icp.verifier.prevNetworkSectionHash = types.NewNetworkSection(header.Header).Hash()
return nil

Check warning on line 497 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L494-L497

Added lines #L494 - L497 were not covered by tests
}

Expand Down

0 comments on commit 5f46ecb

Please sign in to comment.