diff --git a/consensus/XDPoS/engines/engine_v2/forensics.go b/consensus/XDPoS/engines/engine_v2/forensics.go index 5f674d216b..f305b59c1a 100644 --- a/consensus/XDPoS/engines/engine_v2/forensics.go +++ b/consensus/XDPoS/engines/engine_v2/forensics.go @@ -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[:], ":") +} diff --git a/consensus/XDPoS/engines/engine_v2/forensics_test.go b/consensus/XDPoS/engines/engine_v2/forensics_test.go index 85206587c6..8878bea461 100644 --- a/consensus/XDPoS/engines/engine_v2/forensics_test.go +++ b/consensus/XDPoS/engines/engine_v2/forensics_test.go @@ -143,4 +143,3 @@ func TestFindQCsInSameRound(t *testing.T) { } // TODO: Add test for FindAncestorBlockHash -// TODO: Add test for SendForensicProof diff --git a/consensus/tests/engine_v2_tests/forensics_test.go b/consensus/tests/engine_v2_tests/forensics_test.go index e546f4540b..bbae32f551 100644 --- a/consensus/tests/engine_v2_tests/forensics_test.go +++ b/consensus/tests/engine_v2_tests/forensics_test.go @@ -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()) diff --git a/core/types/forensics.go b/core/types/forensics.go index 76e6b0a9b5..9af6a5833d 100644 --- a/core/types/forensics.go +++ b/core/types/forensics.go @@ -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"`