mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 21:56:50 +00:00

* Calculate GHOSTDAG, reachability etc for each level * Don't preallocate cache for dag stores except level 0 and reduce the number of connections in the integration test to 32 * Reduce the number of connections in the integration test to 16 * Increase page file * BuildPruningPointProof * BuildPruningPointProof * Add PruningProofManager * Implement ApplyPruningPointProof * Add prefix and fix blockAtDepth and fill headersByLevel * Some bug fixes * Include all relevant blocks for each level in the proof * Fix syncAndValidatePruningPointProof to return the right block hash * Fix block window * Fix isAncestorOfPruningPoint * Ban for rule errors on pruning proof * Find common ancestor for blockAtDepthMAtNextLevel * Use pruning proof in TestValidateAndInsertImportedPruningPoint * stage status and finality point for proof blocks * Uncomment golint * Change test timeouts * Calculate merge set for ApplyPruningPointProof * Increase test timeout * Add better caching for daa window store * Return to default timeout * Add ErrPruningProofMissesBlocksBelowPruningPoint * Add errDAAWindowBlockNotFound * Force connection loop next iteration on connection manager stop * Revert to Test64IncomingConnections * Remove BlockAtDepth from DAGTraversalManager * numBullies->16 * Set page file size to 8gb * Increase p2p max message size * Test64IncomingConnections->Test16IncomingConnections * Add comment for PruningProofM * Add comment in `func (c *ConnectionManager) Stop()` * Rename isAncestorOfPruningPoint->isAncestorOfSelectedTip * Revert page file to 16gb * Improve ExpectedHeaderPruningPoint perf * Fix comment * Revert "Improve ExpectedHeaderPruningPoint perf" This reverts commit bca1080e7140c78d510f51bbea858ae280c2f38e. * Don't test windows
118 lines
3.6 KiB
Go
118 lines
3.6 KiB
Go
package dagtraversalmanager_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
|
)
|
|
|
|
func TestLowestChainBlockAboveOrEqualToBlueScore(t *testing.T) {
|
|
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
|
consensusConfig.FinalityDuration = 10 * consensusConfig.TargetTimePerBlock
|
|
factory := consensus.NewFactory()
|
|
tc, tearDown, err := factory.NewTestConsensus(consensusConfig,
|
|
"TestLowestChainBlockAboveOrEqualToBlueScore")
|
|
if err != nil {
|
|
t.Fatalf("NewTestConsensus: %s", err)
|
|
}
|
|
defer tearDown(false)
|
|
|
|
stagingArea := model.NewStagingArea()
|
|
|
|
checkExpectedBlock := func(highHash *externalapi.DomainHash, blueScore uint64, expected *externalapi.DomainHash) {
|
|
blockHash, err := tc.DAGTraversalManager().LowestChainBlockAboveOrEqualToBlueScore(stagingArea, highHash, blueScore)
|
|
if err != nil {
|
|
t.Fatalf("LowestChainBlockAboveOrEqualToBlueScore: %+v", err)
|
|
}
|
|
|
|
if !blockHash.Equal(expected) {
|
|
t.Fatalf("Expected block %s but got %s", expected, blockHash)
|
|
}
|
|
}
|
|
|
|
checkBlueScore := func(blockHash *externalapi.DomainHash, expectedBlueScoe uint64) {
|
|
ghostdagData, err := tc.GHOSTDAGDataStore().Get(tc.DatabaseContext(), stagingArea, blockHash, false)
|
|
if err != nil {
|
|
t.Fatalf("GHOSTDAGDataStore().Get: %+v", err)
|
|
}
|
|
|
|
if ghostdagData.BlueScore() != expectedBlueScoe {
|
|
t.Fatalf("Expected blue score %d but got %d", expectedBlueScoe, ghostdagData.BlueScore())
|
|
}
|
|
}
|
|
|
|
chain := []*externalapi.DomainHash{consensusConfig.GenesisHash}
|
|
tipHash := consensusConfig.GenesisHash
|
|
for i := 0; i < 9; i++ {
|
|
var err error
|
|
tipHash, _, err = tc.AddBlock([]*externalapi.DomainHash{tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
chain = append(chain, tipHash)
|
|
}
|
|
|
|
sideChain1TipHash, _, err := tc.AddBlock([]*externalapi.DomainHash{consensusConfig.GenesisHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
tipHash, _, err = tc.AddBlock([]*externalapi.DomainHash{sideChain1TipHash, tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
chain = append(chain, tipHash)
|
|
blueScore11BlockHash := tipHash
|
|
checkBlueScore(blueScore11BlockHash, 11)
|
|
|
|
for i := 0; i < 5; i++ {
|
|
var err error
|
|
tipHash, _, err = tc.AddBlock([]*externalapi.DomainHash{tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
chain = append(chain, tipHash)
|
|
}
|
|
|
|
sideChain2TipHash, _, err := tc.AddBlock([]*externalapi.DomainHash{consensusConfig.GenesisHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
tipHash, _, err = tc.AddBlock([]*externalapi.DomainHash{sideChain2TipHash, tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
chain = append(chain, tipHash)
|
|
|
|
blueScore18BlockHash := tipHash
|
|
checkBlueScore(blueScore18BlockHash, 18)
|
|
|
|
for i := 0; i < 3; i++ {
|
|
var err error
|
|
tipHash, _, err = tc.AddBlock([]*externalapi.DomainHash{tipHash}, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("AddBlock: %+v", err)
|
|
}
|
|
|
|
chain = append(chain, tipHash)
|
|
}
|
|
|
|
// Check by exact blue score
|
|
checkExpectedBlock(tipHash, 0, consensusConfig.GenesisHash)
|
|
checkExpectedBlock(tipHash, 5, chain[5])
|
|
checkExpectedBlock(tipHash, 19, chain[len(chain)-3])
|
|
|
|
// Check by non exact blue score
|
|
checkExpectedBlock(tipHash, 17, blueScore18BlockHash)
|
|
checkExpectedBlock(tipHash, 10, blueScore11BlockHash)
|
|
})
|
|
}
|