mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1129] Fix NewBlockTemplate creating incesous blocks (#870)
* [NOD-1129] Implement TestIncestousNewBlockTemplate. * [NOD-1129] Add some debug logs to TestIncestousNewBlockTemplate. * [NOD-1129] Fix merge errors. * [NOD-1129] Narrow down on the failure. * [NOD-1129] Fix bad initial value for child.interval in reachabilityTreeNode.addChild. * [NOD-1129] Rewrite the test to be specific to reachability.
This commit is contained in:
parent
8a4ece1101
commit
1927e81202
@ -268,6 +268,12 @@ func (rtn *reachabilityTreeNode) addChild(child *reachabilityTreeNode, reindexRo
|
||||
rtn.children = append(rtn.children, child)
|
||||
child.parent = rtn
|
||||
|
||||
// Temporarily set the child's interval to be empty, at
|
||||
// the start of rtn's remaining interval. This is done
|
||||
// so that child-of-rtn checks (e.g.
|
||||
// findAncestorAmongChildren) will not fail for rtn.
|
||||
child.interval = newReachabilityInterval(remaining.start, remaining.start-1)
|
||||
|
||||
// Handle rtn not being a descendant of the reindex root.
|
||||
// Note that we check rtn here instead of child because
|
||||
// at this point we don't yet know child's interval.
|
||||
|
@ -1047,3 +1047,37 @@ func TestReindexIntervalsEarlierThanReindexRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTipsAfterReindexIntervalsEarlierThanReindexRoot(t *testing.T) {
|
||||
// Create a new database and DAG instance to run tests against.
|
||||
dag, teardownFunc, err := DAGSetup("TestTipsAfterReindexIntervalsEarlierThanReindexRoot", true, Config{
|
||||
DAGParams: &dagconfig.SimnetParams,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to setup DAG instance: %v", err)
|
||||
}
|
||||
defer teardownFunc()
|
||||
|
||||
// Set the reindex window to a low number to make this test run fast
|
||||
originalReachabilityReindexWindow := reachabilityReindexWindow
|
||||
reachabilityReindexWindow = 10
|
||||
defer func() {
|
||||
reachabilityReindexWindow = originalReachabilityReindexWindow
|
||||
}()
|
||||
|
||||
// Add a chain of reachabilityReindexWindow + 1 blocks above the genesis.
|
||||
// This will set the reindex root to the child of genesis
|
||||
chainTipHash := dag.Params.GenesisHash
|
||||
for i := uint64(0); i < reachabilityReindexWindow+1; i++ {
|
||||
block := PrepareAndProcessBlockForTest(t, dag, []*daghash.Hash{chainTipHash}, nil)
|
||||
chainTipHash = block.BlockHash()
|
||||
}
|
||||
|
||||
// Add another block above the genesis block. This will trigger an
|
||||
// earlier-than-reindex-root reindex
|
||||
sideBlock := PrepareAndProcessBlockForTest(t, dag, []*daghash.Hash{dag.Params.GenesisHash}, nil)
|
||||
|
||||
// Add a block whose parents are the chain tip and the side block.
|
||||
// We expect this not to fail
|
||||
PrepareAndProcessBlockForTest(t, dag, []*daghash.Hash{chainTipHash, sideBlock.BlockHash()}, nil)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/blockdag"
|
||||
"github.com/kaspanet/kaspad/domain/mining"
|
||||
"github.com/kaspanet/kaspad/domain/txscript"
|
||||
"github.com/kaspanet/kaspad/network/domainmessage"
|
||||
"github.com/kaspanet/kaspad/network/rpc/model"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
@ -72,18 +71,6 @@ func newGbtWorkState() *gbtWorkState {
|
||||
}
|
||||
}
|
||||
|
||||
// builderScript is a convenience function which is used for hard-coded scripts
|
||||
// built with the script builder. Any errors are converted to a panic since it
|
||||
// is only, and must only, be used with hard-coded, and therefore, known good,
|
||||
// scripts.
|
||||
func builderScript(builder *txscript.ScriptBuilder) []byte {
|
||||
script, err := builder.Script()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return script
|
||||
}
|
||||
|
||||
// handleGetBlockTemplate implements the getBlockTemplate command.
|
||||
func handleGetBlockTemplate(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
c := cmd.(*model.GetBlockTemplateCmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user