mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-31 11:16:42 +00:00

* Use selectedParent instead of selectedTip for non-selectedTip blocks in restoreSingleBlockStatus * Cache the selectedParent for re-use in a resolveSingleBlockStatus chain * Implement and use reverseUTXOSet * Reverse blocks in correct order * Support resolveBlockStatus without separate stagingAreas for usage of testConsensus * Handle the case where the tip of the resolved block is not the next selectedTip * Unify isResolveTip * Some minor fixes and cleanup * Add full finality window re-org test to stability-slow * rename: useSeparateStagingAreasPerBlock -> useSeparateStagingAreaPerBlock * Better logs in resolveSingleBlockStatus * A few retouches to reverseUTXODiffs * TEMPORARY COMMIT: EXTRAT ALL DIFFFROMS TO SEPARATE METHODS * TEMPORARY COMMIT: REMOVE DIFFICULTY CHECKS IN DEVNET * Don't pre-allocate in utxo-algebra, since the numbers are not known ahead-of-time * Add some logs to reverseUTXODiffs * Revert "TEMPORARY COMMIT: REMOVE DIFFICULTY CHECKS IN DEVNET" This reverts commit c0af9dc6ade78a914c970e11bc63c34605565f57. * Revert "TEMPORARY COMMIT: EXTRAT ALL DIFFFROMS TO SEPARATE METHODS" This reverts commit 4fcca1b48c3a1183598833a355b9bfaf169edba1. * Remove redundant paranthesis * Revise some logs messages * Rename:oneBlockBeforeCurrentUTXOSet -> lastResolvedBlockUTXOSet * Don't break if the block was resolved as invalid * rename unverifiedBlocks to recentlyVerifiedBlcks in reverseUTXODiffs * Add errors.New to the panic, for a stack trace * Reverse the UTXODiffs after the main block has been commited * Use the correct value for previousUTXODiff * Add test for ReverseUTXODiff * Fix some names and comments * Update TestReverseUTXODiffs to use consensus.Config * Fix comments mentioning 'oneBlockBeforeTip'
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package consensus
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
)
|
|
|
|
// RenderDAGToDot is a helper function for debugging tests.
|
|
// It requires graphviz installed.
|
|
func (tc *testConsensus) RenderDAGToDot(filename string) error {
|
|
dotScript, _ := tc.convertToDot()
|
|
return renderDotScript(dotScript, filename)
|
|
}
|
|
|
|
func (tc *testConsensus) convertToDot() (string, error) {
|
|
var dotScriptBuilder strings.Builder
|
|
dotScriptBuilder.WriteString("digraph {\n\trankdir = TB; \n")
|
|
|
|
edges := []string{}
|
|
|
|
blocksIterator, err := tc.blockStore.AllBlockHashesIterator(tc.databaseContext)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer blocksIterator.Close()
|
|
|
|
stagingArea := model.NewStagingArea()
|
|
for ok := blocksIterator.First(); ok; ok = blocksIterator.Next() {
|
|
hash, err := blocksIterator.Get()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
dotScriptBuilder.WriteString(fmt.Sprintf("\t\"%s\";\n", hash))
|
|
|
|
parents, err := tc.dagTopologyManager.Parents(stagingArea, hash)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
for _, parentHash := range parents {
|
|
edges = append(edges, fmt.Sprintf("\t\"%s\" -> \"%s\";", hash, parentHash))
|
|
}
|
|
}
|
|
|
|
dotScriptBuilder.WriteString("\n")
|
|
|
|
dotScriptBuilder.WriteString(strings.Join(edges, "\n"))
|
|
|
|
dotScriptBuilder.WriteString("\n}")
|
|
|
|
return dotScriptBuilder.String(), nil
|
|
}
|
|
|
|
func renderDotScript(dotScript string, filename string) error {
|
|
command := exec.Command("dot", "-Tsvg")
|
|
stdin, err := command.StdinPipe()
|
|
if err != nil {
|
|
return fmt.Errorf("Error creating stdin pipe: %s", err)
|
|
}
|
|
spawn("renderDotScript", func() {
|
|
defer stdin.Close()
|
|
|
|
_, err = io.WriteString(stdin, dotScript)
|
|
if err != nil {
|
|
panic(fmt.Errorf("Error writing dotScript into stdin pipe: %s", err))
|
|
}
|
|
})
|
|
|
|
var stderr bytes.Buffer
|
|
command.Stderr = &stderr
|
|
svg, err := command.Output()
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting output of dot: %s\nstderr:\n%s", err, stderr.String())
|
|
}
|
|
|
|
return ioutil.WriteFile(filename, svg, 0600)
|
|
}
|