fix only timeout round exists in next epoch (#772)

* fix only timeout round exists in next epoch

* bump version

---------

Co-authored-by: liam.lai <liam.lai@us>
This commit is contained in:
benjamin202410 2024-12-23 23:09:45 -08:00 committed by GitHub
parent b2a41afb87
commit 332380c889
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 1 deletions

View file

@ -109,7 +109,19 @@ 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())
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)
}
tcEpoch := x.config.V2.SwitchBlock.Uint64()/x.config.Epoch + uint64(timeoutCert.Round)/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, err := x.GetBlockByEpochNumber(chain, tcEpoch)
if err != nil {
log.Error("[verifyTC] Error when getting epoch block info by tc round", "error", err)

View file

@ -103,6 +103,55 @@ func TestSkipVerifySyncInfoIfBothQcTcNotQualified(t *testing.T) {
assert.Nil(t, err)
}
func TestVerifySyncInfoIfTCRoundIsAtNextEpoch(t *testing.T) {
blockchain, _, _, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
// Make the Highest QC in syncInfo point to an old block to simulate it's no longer qualified
parentBlock := blockchain.GetBlockByNumber(903)
var extraField types.ExtraFields_v2
err := utils.DecodeBytesExtraFields(parentBlock.Extra(), &extraField)
if err != nil {
t.Fatal("Fail to decode extra data", err)
}
highestTC := &types.TimeoutCert{
Round: types.Round(899),
Signatures: []types.Signature{},
}
timeoutForSign := &types.TimeoutForSign{
Round: types.Round(900),
GapNumber: 450,
}
// Sign from acc 1, 2, 3 and voter
acc1SignedHash := SignHashByPK(acc1Key, types.TimeoutSigHash(timeoutForSign).Bytes())
acc2SignedHash := SignHashByPK(acc2Key, types.TimeoutSigHash(timeoutForSign).Bytes())
acc3SignedHash := SignHashByPK(acc3Key, types.TimeoutSigHash(timeoutForSign).Bytes())
voterSignedHash := SignHashByPK(voterKey, types.TimeoutSigHash(timeoutForSign).Bytes())
var signatures []types.Signature
signatures = append(signatures, acc1SignedHash, acc2SignedHash, acc3SignedHash, voterSignedHash)
syncInfoTC := &types.TimeoutCert{
Round: timeoutForSign.Round,
Signatures: signatures,
GapNumber: timeoutForSign.GapNumber,
}
syncInfoMsg := &types.SyncInfo{
HighestQuorumCert: extraField.QuorumCert,
HighestTimeoutCert: syncInfoTC,
}
engineV2.SetPropertiesFaker(syncInfoMsg.HighestQuorumCert, highestTC)
verified, err := engineV2.VerifySyncInfoMessage(blockchain, syncInfoMsg)
assert.True(t, verified)
assert.Nil(t, err)
}
func TestVerifySyncInfoIfTcUseDifferentEpoch(t *testing.T) {
config := params.TestXDPoSMockChainConfig
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 1349, config, nil)

View file

@ -23,7 +23,7 @@ import (
const (
VersionMajor = 2 // Major version component of the current release
VersionMinor = 4 // Minor version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionPatch = 6 // Patch version component of the current release
VersionMeta = "beta1" // Version metadata to append to the version string
)