mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
pass the forensics Id at root level (#107)
This commit is contained in:
parent
533fe250db
commit
cfb5c6ce39
3 changed files with 23 additions and 11 deletions
|
|
@ -166,7 +166,6 @@ 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(),
|
||||||
|
|
@ -188,6 +187,7 @@ func (f *Forensics) SendForensicProof(chain consensus.ChainReader, engine *XDPoS
|
||||||
}
|
}
|
||||||
|
|
||||||
forensicsProof := &types.ForensicProof{
|
forensicsProof := &types.ForensicProof{
|
||||||
|
Id: generateForensicsId(ancestorHash.Hex(), &lowerRoundQC, &higherRoundQC),
|
||||||
ForensicsType: "QC",
|
ForensicsType: "QC",
|
||||||
Content: string(content),
|
Content: string(content),
|
||||||
}
|
}
|
||||||
|
|
@ -325,8 +325,8 @@ func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBloc
|
||||||
lowerBlockNumHash := firstBlockInfo.Hash
|
lowerBlockNumHash := firstBlockInfo.Hash
|
||||||
higherBlockNumberHash := secondBlockInfo.Hash
|
higherBlockNumberHash := secondBlockInfo.Hash
|
||||||
|
|
||||||
var ancestorToLowerBlockNumHashPath []string
|
var lowerBlockNumToAncestorHashPath []string
|
||||||
var ancestorToHigherBlockNumHashPath []string
|
var higherBlockToAncestorNumHashPath []string
|
||||||
orderSwapped := false
|
orderSwapped := false
|
||||||
|
|
||||||
blockNumberDifference := big.NewInt(0).Sub(secondBlockInfo.Number, firstBlockInfo.Number).Int64()
|
blockNumberDifference := big.NewInt(0).Sub(secondBlockInfo.Number, firstBlockInfo.Number).Int64()
|
||||||
|
|
@ -336,17 +336,17 @@ func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBloc
|
||||||
blockNumberDifference = -blockNumberDifference // and make it positive
|
blockNumberDifference = -blockNumberDifference // and make it positive
|
||||||
orderSwapped = true
|
orderSwapped = true
|
||||||
}
|
}
|
||||||
ancestorToLowerBlockNumHashPath = append(ancestorToLowerBlockNumHashPath, lowerBlockNumHash.Hex())
|
lowerBlockNumToAncestorHashPath = append(lowerBlockNumToAncestorHashPath, lowerBlockNumHash.Hex())
|
||||||
ancestorToHigherBlockNumHashPath = append(ancestorToHigherBlockNumHashPath, higherBlockNumberHash.Hex())
|
higherBlockToAncestorNumHashPath = append(higherBlockToAncestorNumHashPath, higherBlockNumberHash.Hex())
|
||||||
|
|
||||||
// First, make their block number the same to start with
|
// First, make their block number the same to start with
|
||||||
for i := 0; i < int(blockNumberDifference); i++ {
|
for i := 0; i < int(blockNumberDifference); i++ {
|
||||||
ph := chain.GetHeaderByHash(higherBlockNumberHash)
|
ph := chain.GetHeaderByHash(higherBlockNumberHash)
|
||||||
if ph == nil {
|
if ph == nil {
|
||||||
return common.Hash{}, ancestorToLowerBlockNumHashPath, ancestorToHigherBlockNumHashPath, fmt.Errorf("unable to find parent block of hash %v", higherBlockNumberHash)
|
return common.Hash{}, lowerBlockNumToAncestorHashPath, higherBlockToAncestorNumHashPath, fmt.Errorf("unable to find parent block of hash %v", higherBlockNumberHash)
|
||||||
}
|
}
|
||||||
higherBlockNumberHash = ph.ParentHash
|
higherBlockNumberHash = ph.ParentHash
|
||||||
ancestorToHigherBlockNumHashPath = append(ancestorToHigherBlockNumHashPath, ph.ParentHash.Hex())
|
higherBlockToAncestorNumHashPath = append(higherBlockToAncestorNumHashPath, ph.ParentHash.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, they are on the same starting line, we try find the common ancestor
|
// Now, they are on the same starting line, we try find the common ancestor
|
||||||
|
|
@ -354,9 +354,13 @@ func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBloc
|
||||||
lowerBlockNumHash = chain.GetHeaderByHash(lowerBlockNumHash).ParentHash
|
lowerBlockNumHash = chain.GetHeaderByHash(lowerBlockNumHash).ParentHash
|
||||||
higherBlockNumberHash = chain.GetHeaderByHash(higherBlockNumberHash).ParentHash
|
higherBlockNumberHash = chain.GetHeaderByHash(higherBlockNumberHash).ParentHash
|
||||||
// Append the path
|
// Append the path
|
||||||
ancestorToLowerBlockNumHashPath = append(ancestorToLowerBlockNumHashPath, lowerBlockNumHash.Hex())
|
lowerBlockNumToAncestorHashPath = append(lowerBlockNumToAncestorHashPath, lowerBlockNumHash.Hex())
|
||||||
ancestorToHigherBlockNumHashPath = append(ancestorToHigherBlockNumHashPath, higherBlockNumberHash.Hex())
|
higherBlockToAncestorNumHashPath = append(higherBlockToAncestorNumHashPath, higherBlockNumberHash.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reverse the list order as it's from ancestor to X block path.
|
||||||
|
ancestorToLowerBlockNumHashPath := reverse(lowerBlockNumToAncestorHashPath)
|
||||||
|
ancestorToHigherBlockNumHashPath := reverse(higherBlockToAncestorNumHashPath)
|
||||||
// Swap back the order. We must return in the order that matches what we acceptted in the parameter of firstBlock & secondBlock
|
// Swap back the order. We must return in the order that matches what we acceptted in the parameter of firstBlock & secondBlock
|
||||||
if orderSwapped {
|
if orderSwapped {
|
||||||
return lowerBlockNumHash, ancestorToHigherBlockNumHashPath, ancestorToLowerBlockNumHashPath, nil
|
return lowerBlockNumHash, ancestorToHigherBlockNumHashPath, ancestorToLowerBlockNumHashPath, nil
|
||||||
|
|
@ -368,3 +372,11 @@ func generateForensicsId(divergingHash string, qc1 *types.QuorumCert, qc2 *types
|
||||||
keysList := []string{divergingHash, qc1.ProposedBlockInfo.Hash.Hex(), qc2.ProposedBlockInfo.Hash.Hex()}
|
keysList := []string{divergingHash, qc1.ProposedBlockInfo.Hash.Hex(), qc2.ProposedBlockInfo.Hash.Hex()}
|
||||||
return strings.Join(keysList[:], ":")
|
return strings.Join(keysList[:], ":")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reverse(ss []string) []string {
|
||||||
|
last := len(ss) - 1
|
||||||
|
for i := 0; i < len(ss)/2; i++ {
|
||||||
|
ss[i], ss[last-i] = ss[last-i], ss[i]
|
||||||
|
}
|
||||||
|
return ss
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ func TestForensicsAcrossEpoch(t *testing.T) {
|
||||||
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()
|
idToCompare := content.DivergingBlockHash + ":" + content.SmallerRoundInfo.QuorumCert.ProposedBlockInfo.Hash.Hex() + ":" + content.LargerRoundInfo.QuorumCert.ProposedBlockInfo.Hash.Hex()
|
||||||
assert.Equal(t, idToCompare, content.Id)
|
assert.Equal(t, idToCompare, forensics.ForensicsProof.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,7 +7,6 @@ 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"`
|
||||||
|
|
@ -16,6 +15,7 @@ type ForensicsContent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForensicProof struct {
|
type ForensicProof struct {
|
||||||
|
Id string `json:"id"`
|
||||||
ForensicsType string `json:"forensicsType"` // QC or VOTE
|
ForensicsType string `json:"forensicsType"` // QC or VOTE
|
||||||
Content string `json:"content"` // Json string of the forensics data
|
Content string `json:"content"` // Json string of the forensics data
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue