Get right tc epoch (#773)

* get right tc epoch

* fix debug message

* merge test

* merge test

---------

Co-authored-by: liam.lai <liam.lai@us>
This commit is contained in:
benjamin202410 2024-12-24 01:53:40 -08:00 committed by GitHub
parent 332380c889
commit c8aae5e537
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View file

@ -42,10 +42,8 @@ jobs:
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[d-i].*") script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[d-i].*")
- name: J-N tests - name: J-N tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[j-n].*") script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[j-n].*")
- name: O-R tests - name: O-S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[o-r].*") script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[o-s].*")
- name: S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/s.*")
- name: T-Z tests - name: T-Z tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[t-z].*") script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[t-z].*")
steps: steps:

View file

@ -109,24 +109,33 @@ func (x *XDPoS_v2) verifyTC(chain consensus.ChainReader, timeoutCert *types.Time
log.Warn("[verifyQC] duplicated signature in QC", "duplicate", common.Bytes2Hex(d)) log.Warn("[verifyQC] duplicated signature in QC", "duplicate", common.Bytes2Hex(d))
} }
} }
latestBlockRound, err := x.GetRoundNumber(chain.CurrentHeader())
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, (chain.CurrentHeader()), (chain.CurrentHeader()).Hash())
if err != nil { if err != nil {
log.Error("[verifyTC] Error when getting current header round", "error", err) log.Error("[verifyTC] Error when getting epoch switch info", "error", err)
return fmt.Errorf("fail on verifyTC due to error when getting current header round, %s", err) return fmt.Errorf("fail on verifyTC due to failure in getting epoch switch info, %s", err)
} }
tcEpoch := x.config.V2.SwitchBlock.Uint64()/x.config.Epoch + uint64(timeoutCert.Round)/x.config.Epoch epochRound := epochSwitchInfo.EpochSwitchBlockInfo.Round
tempTCEpoch := x.config.V2.SwitchBlock.Uint64()/x.config.Epoch + uint64(epochRound)/x.config.Epoch
//tcEpoch maybe not existed if there is no QC round in this epoch, there is no epoch switch block generated, so it needs to use currentRound to find epochBlockInfo epochBlockInfo := &types.BlockInfo{
if latestBlockRound < timeoutCert.Round { Hash: epochSwitchInfo.EpochSwitchBlockInfo.Hash,
tcEpoch = x.config.V2.SwitchBlock.Uint64()/x.config.Epoch + uint64(latestBlockRound)/x.config.Epoch Round: epochRound,
Number: epochSwitchInfo.EpochSwitchBlockInfo.Number,
} }
log.Info("[verifyTC] Init epochInfo", "number", epochBlockInfo.Number, "round", epochRound, "tcRound", timeoutCert.Round, "tcEpoch", tempTCEpoch)
epochBlockInfo, err := x.GetBlockByEpochNumber(chain, tcEpoch) for epochBlockInfo.Round > timeoutCert.Round {
if err != nil { tempTCEpoch--
log.Error("[verifyTC] Error when getting epoch block info by tc round", "error", err) epochBlockInfo, err = x.GetBlockByEpochNumber(chain, tempTCEpoch)
return fmt.Errorf("fail on verifyTC due to failure in getting epoch block info tc round, %s", err) if err != nil {
log.Error("[verifyTC] Error when getting epoch block info by tc round", "error", err)
return fmt.Errorf("fail on verifyTC due to failure in getting epoch block info tc round, %s", err)
}
log.Debug("[verifyTC] Loop to get right epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutCert.Round, "tcEpoch", tempTCEpoch)
} }
tcEpoch := tempTCEpoch
log.Info("[verifyTC] Final TC epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutCert.Round, "tcEpoch", tcEpoch)
epochInfo, err := x.getEpochSwitchInfo(chain, nil, epochBlockInfo.Hash) epochInfo, err := x.getEpochSwitchInfo(chain, nil, epochBlockInfo.Hash)
if err != nil { if err != nil {