From c8aae5e53752ca32e67ada9ed334220f18a7c27d Mon Sep 17 00:00:00 2001 From: benjamin202410 Date: Tue, 24 Dec 2024 01:53:40 -0800 Subject: [PATCH] Get right tc epoch (#773) * get right tc epoch * fix debug message * merge test * merge test --------- Co-authored-by: liam.lai --- .github/workflows/ci.yml | 6 ++-- consensus/XDPoS/engines/engine_v2/timeout.go | 33 +++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c41c2b2a65f..64dfde9142b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,10 +42,8 @@ jobs: script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[d-i].*") - name: J-N tests script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[j-n].*") - - name: O-R tests - script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[o-r].*") - - name: S tests - script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/s.*") + - name: O-S tests + script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[o-s].*") - name: T-Z tests script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDPoSChain/[t-z].*") steps: diff --git a/consensus/XDPoS/engines/engine_v2/timeout.go b/consensus/XDPoS/engines/engine_v2/timeout.go index 4a9c8d3017b0..875dd22c9c99 100644 --- a/consensus/XDPoS/engines/engine_v2/timeout.go +++ b/consensus/XDPoS/engines/engine_v2/timeout.go @@ -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)) } } - latestBlockRound, err := x.GetRoundNumber(chain.CurrentHeader()) + + epochSwitchInfo, err := x.getEpochSwitchInfo(chain, (chain.CurrentHeader()), (chain.CurrentHeader()).Hash()) if err != nil { - log.Error("[verifyTC] Error when getting current header round", "error", err) - return fmt.Errorf("fail on verifyTC due to error when getting current header round, %s", err) + log.Error("[verifyTC] Error when getting epoch switch info", "error", 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 - if latestBlockRound < timeoutCert.Round { - tcEpoch = x.config.V2.SwitchBlock.Uint64()/x.config.Epoch + uint64(latestBlockRound)/x.config.Epoch + epochBlockInfo := &types.BlockInfo{ + Hash: epochSwitchInfo.EpochSwitchBlockInfo.Hash, + Round: epochRound, + Number: epochSwitchInfo.EpochSwitchBlockInfo.Number, } - - epochBlockInfo, err := x.GetBlockByEpochNumber(chain, tcEpoch) - 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.Info("[verifyTC] Init epochInfo", "number", epochBlockInfo.Number, "round", epochRound, "tcRound", timeoutCert.Round, "tcEpoch", tempTCEpoch) + for epochBlockInfo.Round > timeoutCert.Round { + tempTCEpoch-- + epochBlockInfo, err = x.GetBlockByEpochNumber(chain, tempTCEpoch) + 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) if err != nil {