mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-20 22:06:42 +00:00

* Avoid creating the chain iterator if high hash is actually low hash * Always use iterator in nextPruningPointAndCandidateByBlockHash * Initial failing test * Minimal failing test + some comments * go lint * Add simpler tests with two different errors * Missed some error checks * Minor * A workaround patch for preventing the missing utxo child diff bug * Make sure we fully resolve virtual * Move ResolveVirtualWithMaxParam to test consensus * Mark virtual not updated and loop in batches * Refactor: remove VirtualChangeSet from functions return values * Remove workaround comments * If block has no body, virtual is still considered updated * Remove special error ErrReverseUTXODiffsUTXODiffChildNotFound Co-authored-by: Ori Newman <orinewman1@gmail.com>
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
"github.com/kaspanet/kaspad/infrastructure/db/database/ldb"
|
|
"github.com/kaspanet/kaspad/stability-tests/common"
|
|
"github.com/kaspanet/kaspad/stability-tests/common/mine"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const leveldbCacheSizeMiB = 256
|
|
|
|
func prepareBlocks() (blocks []*externalapi.DomainBlock, topBlock *externalapi.DomainBlock, err error) {
|
|
config := activeConfig()
|
|
testDatabaseDir, err := common.TempDir("minejson")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
db, err := ldb.NewLevelDB(testDatabaseDir, leveldbCacheSizeMiB)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
defer db.Close()
|
|
|
|
testConsensus, tearDownFunc, err := consensus.NewFactory().NewTestConsensus(&consensus.Config{Params: *config.ActiveNetParams}, "prepareBlocks")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
defer tearDownFunc(true)
|
|
|
|
virtualSelectedParent, err := testConsensus.GetVirtualSelectedParent()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
currentParentHash := virtualSelectedParent
|
|
|
|
blocksCount := config.OrphanChainLength + 1
|
|
blocks = make([]*externalapi.DomainBlock, 0, blocksCount)
|
|
|
|
for i := 0; i < blocksCount; i++ {
|
|
block, _, err := testConsensus.BuildBlockWithParents(
|
|
[]*externalapi.DomainHash{currentParentHash},
|
|
&externalapi.DomainCoinbaseData{ScriptPublicKey: &externalapi.ScriptPublicKey{}},
|
|
[]*externalapi.DomainTransaction{})
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "error in BuildBlockWithParents")
|
|
}
|
|
|
|
mine.SolveBlock(block)
|
|
err = testConsensus.ValidateAndInsertBlock(block, true)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "error in ValidateAndInsertBlock")
|
|
}
|
|
|
|
blocks = append(blocks, block)
|
|
currentParentHash = consensushashing.BlockHash(block)
|
|
}
|
|
|
|
return blocks[:len(blocks)-1], blocks[len(blocks)-1], nil
|
|
}
|