mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
forensics shall send unique id (#106)
This commit is contained in:
parent
86ec908091
commit
533fe250db
4 changed files with 10 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus"
|
"github.com/XinFinOrg/XDPoSChain/consensus"
|
||||||
|
|
@ -165,6 +166,7 @@ func (f *Forensics) SendForensicProof(chain consensus.ChainReader, engine *XDPoS
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := json.Marshal(&types.ForensicsContent{
|
content, err := json.Marshal(&types.ForensicsContent{
|
||||||
|
Id: generateForensicsId(ancestorHash.Hex(), &lowerRoundQC, &higherRoundQC),
|
||||||
DivergingBlockHash: ancestorHash.Hex(),
|
DivergingBlockHash: ancestorHash.Hex(),
|
||||||
AcrossEpoch: accrossEpoches,
|
AcrossEpoch: accrossEpoches,
|
||||||
DivergingBlockNumber: ancestorBlock.Number.Uint64(),
|
DivergingBlockNumber: ancestorBlock.Number.Uint64(),
|
||||||
|
|
@ -361,3 +363,8 @@ func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBloc
|
||||||
}
|
}
|
||||||
return lowerBlockNumHash, ancestorToLowerBlockNumHashPath, ancestorToHigherBlockNumHashPath, nil
|
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[:], ":")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,4 +143,3 @@ func TestFindQCsInSameRound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add test for FindAncestorBlockHash
|
// TODO: Add test for FindAncestorBlockHash
|
||||||
// TODO: Add test for SendForensicProof
|
|
||||||
|
|
|
||||||
|
|
@ -294,6 +294,8 @@ func TestForensicsAcrossEpoch(t *testing.T) {
|
||||||
content := &types.ForensicsContent{}
|
content := &types.ForensicsContent{}
|
||||||
json.Unmarshal([]byte(forensics.ForensicsProof.Content), &content)
|
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.True(t, content.AcrossEpoch)
|
||||||
assert.Equal(t, types.Round(900), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Round)
|
assert.Equal(t, types.Round(900), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Round)
|
||||||
assert.Equal(t, uint64(1800), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Number.Uint64())
|
assert.Equal(t, uint64(1800), content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Number.Uint64())
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type ForensicsInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForensicsContent struct {
|
type ForensicsContent struct {
|
||||||
|
Id string `json:"id"`
|
||||||
DivergingBlockNumber uint64 `json:"divergingBlockNumber"`
|
DivergingBlockNumber uint64 `json:"divergingBlockNumber"`
|
||||||
DivergingBlockHash string `json:"divergingBlockHash"`
|
DivergingBlockHash string `json:"divergingBlockHash"`
|
||||||
AcrossEpoch bool `json:"acrossEpoch"`
|
AcrossEpoch bool `json:"acrossEpoch"`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue