forensics shall send unique id (#106)

This commit is contained in:
Jerome 2022-07-05 08:31:09 +10:00 committed by GitHub
parent 86ec908091
commit 533fe250db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"reflect"
"strings"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/consensus"
@ -165,6 +166,7 @@ func (f *Forensics) SendForensicProof(chain consensus.ChainReader, engine *XDPoS
}
content, err := json.Marshal(&types.ForensicsContent{
Id: generateForensicsId(ancestorHash.Hex(), &lowerRoundQC, &higherRoundQC),
DivergingBlockHash: ancestorHash.Hex(),
AcrossEpoch: accrossEpoches,
DivergingBlockNumber: ancestorBlock.Number.Uint64(),
@ -361,3 +363,8 @@ func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBloc
}
return lowerBlockNumHash, ancestorToLowerBlockNumHashPath, ancestorToHigherBlockNumHashPath, nil
}
func generateForensicsId(divergingHash string, qc1 *types.QuorumCert, qc2 *types.QuorumCert) string {
keysList := []string{divergingHash, qc1.ProposedBlockInfo.Hash.Hex(), qc2.ProposedBlockInfo.Hash.Hex()}
return strings.Join(keysList[:], ":")
}

View file

@ -143,4 +143,3 @@ func TestFindQCsInSameRound(t *testing.T) {
}
// TODO: Add test for FindAncestorBlockHash
// TODO: Add test for SendForensicProof

View file

@ -294,6 +294,8 @@ func TestForensicsAcrossEpoch(t *testing.T) {
content := &types.ForensicsContent{}
json.Unmarshal([]byte(forensics.ForensicsProof.Content), &content)
idToCompare := content.DivergingBlockHash + ":" + content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Hash.Hex() + ":" + content.LargerRoundInfo.QuorumCert.ProposedBlockInfo.Hash.Hex()
assert.Equal(t, idToCompare, content.Id)
assert.True(t, content.AcrossEpoch)
assert.Equal(t, types.Round(900), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Round)
assert.Equal(t, uint64(1800), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Number.Uint64())

View file

@ -7,6 +7,7 @@ type ForensicsInfo struct {
}
type ForensicsContent struct {
Id string `json:"id"`
DivergingBlockNumber uint64 `json:"divergingBlockNumber"`
DivergingBlockHash string `json:"divergingBlockHash"`
AcrossEpoch bool `json:"acrossEpoch"`