aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-20 18:38:05 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:56 +0800
commitb9f9bad3443a91209a05b223886a889c4fab834a (patch)
treefa4a88f2e071e920f86c3bc0b0995f4595b4e368
parent8e1194d60b89df925b7d5b53395d0949df4bd4f8 (diff)
downloadgo-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar.gz
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar.bz2
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar.lz
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar.xz
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.tar.zst
go-tangerine-b9f9bad3443a91209a05b223886a889c4fab834a.zip
core: only verify the last tsig of header chain (#380)
-rw-r--r--core/headerchain.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/core/headerchain.go b/core/headerchain.go
index b6aa66b60..3db6caeeb 100644
--- a/core/headerchain.go
+++ b/core/headerchain.go
@@ -411,6 +411,11 @@ func (hc *HeaderChain) ValidateDexonHeaderChain(chain []*types.HeaderWithGovStat
}
}
+ // If the last TSig pass the verification, we don't need to verify others.
+ verifyTSig := false
+ if err := hc.verifyDexonHeader(chain[len(chain)-1].Header, gov, verifierCache, true); err != nil {
+ verifyTSig = true
+ }
// Iterate over the headers and ensure they all check out
for i, header := range chain {
// If the chain is terminating, stop processing blocks
@@ -426,7 +431,7 @@ func (hc *HeaderChain) ValidateDexonHeaderChain(chain []*types.HeaderWithGovStat
}
}
- if err := hc.verifyDexonHeader(header.Header, gov, verifierCache); err != nil {
+ if err := hc.verifyDexonHeader(header.Header, gov, verifierCache, verifyTSig); err != nil {
return i, err
}
@@ -467,7 +472,7 @@ func (hc *HeaderChain) VerifyDexonHeader(header *types.Header,
return consensus.ErrUnknownAncestor
}
- if err := hc.verifyDexonHeader(header, gov, verifierCache); err != nil {
+ if err := hc.verifyDexonHeader(header, gov, verifierCache, true); err != nil {
return err
}
@@ -494,7 +499,7 @@ func (hc *HeaderChain) VerifyDexonHeader(header *types.Header,
func (hc *HeaderChain) verifyDexonHeader(header *types.Header,
gov dexcon.GovernanceStateFetcher,
- verifierCache *dexCore.TSigVerifierCache) error {
+ verifierCache *dexCore.TSigVerifierCache, verifyTSig bool) error {
// If the header is a banned one, straight out abort
if BadHashes[header.Hash()] {
@@ -513,9 +518,11 @@ func (hc *HeaderChain) verifyDexonHeader(header *types.Header,
header.Number.Uint64(), err)
}
- if err := hc.verifyTSig(&coreBlock, verifierCache); err != nil {
- log.Debug("verify header sig fail, number=%d, err=%v",
- header.Number.Uint64(), err)
+ if verifyTSig {
+ if err := hc.verifyTSig(&coreBlock, verifierCache); err != nil {
+ log.Debug("verify header sig fail, number=%d, err=%v",
+ header.Number.Uint64(), err)
+ }
}
gs := gov.GetStateForConfigAtRound(header.Round)