mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 06:36:46 +00:00
Add TestIBDWithPruning (#1425)
* Add TestIBDWithPruning * Test block count * Fix a typo Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com> Co-authored-by: Mike Zak <feanorr@gmail.com>
This commit is contained in:
parent
2e0bc0f8c4
commit
abef96e3de
@ -36,6 +36,10 @@ func setConfig(t *testing.T, harness *appHarness) {
|
|||||||
harness.config.Listeners = []string{harness.p2pAddress}
|
harness.config.Listeners = []string{harness.p2pAddress}
|
||||||
harness.config.RPCListeners = []string{harness.rpcAddress}
|
harness.config.RPCListeners = []string{harness.rpcAddress}
|
||||||
harness.config.UTXOIndex = harness.utxoIndex
|
harness.config.UTXOIndex = harness.utxoIndex
|
||||||
|
|
||||||
|
if harness.overrideDAGParams != nil {
|
||||||
|
harness.config.ActiveNetParams = harness.overrideDAGParams
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func commonConfig() *config.Config {
|
func commonConfig() *config.Config {
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,3 +52,106 @@ func TestIBD(t *testing.T) {
|
|||||||
t.Errorf("Tips of syncer: '%s' and syncee '%s' are not equal", tip1Hash.SelectedTipHash, tip2Hash.SelectedTipHash)
|
t.Errorf("Tips of syncer: '%s' and syncee '%s' are not equal", tip1Hash.SelectedTipHash, tip2Hash.SelectedTipHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestIBDWithPruning checks the IBD from a node with
|
||||||
|
// already pruned blocks.
|
||||||
|
func TestIBDWithPruning(t *testing.T) {
|
||||||
|
const numBlocks = 100
|
||||||
|
|
||||||
|
overrideDAGParams := dagconfig.SimnetParams
|
||||||
|
|
||||||
|
// This is done to make a pruning depth of 6 blocks
|
||||||
|
overrideDAGParams.FinalityDuration = 2 * overrideDAGParams.TargetTimePerBlock
|
||||||
|
overrideDAGParams.K = 0
|
||||||
|
harnesses, teardown := setupHarnesses(t, []*harnessParams{
|
||||||
|
{
|
||||||
|
p2pAddress: p2pAddress1,
|
||||||
|
rpcAddress: rpcAddress1,
|
||||||
|
miningAddress: miningAddress1,
|
||||||
|
miningAddressPrivateKey: miningAddress1PrivateKey,
|
||||||
|
overrideDAGParams: &overrideDAGParams,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
p2pAddress: p2pAddress2,
|
||||||
|
rpcAddress: rpcAddress2,
|
||||||
|
miningAddress: miningAddress2,
|
||||||
|
miningAddressPrivateKey: miningAddress2PrivateKey,
|
||||||
|
overrideDAGParams: &overrideDAGParams,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
syncer, syncee := harnesses[0], harnesses[1]
|
||||||
|
|
||||||
|
// Let the syncee have two blocks that the syncer
|
||||||
|
// doesn't have to test a situation where
|
||||||
|
// the block locator will need more than one
|
||||||
|
// iteration to find the highest shared chain
|
||||||
|
// block.
|
||||||
|
const synceeOnlyBlocks = 2
|
||||||
|
for i := 0; i < synceeOnlyBlocks; i++ {
|
||||||
|
mineNextBlock(t, syncee)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < numBlocks-1; i++ {
|
||||||
|
mineNextBlock(t, syncer)
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(t, syncer, syncee)
|
||||||
|
|
||||||
|
// We expect this to trigger IBD
|
||||||
|
mineNextBlock(t, syncer)
|
||||||
|
|
||||||
|
syncerBlockCountResponse, err := syncer.rpcClient.GetBlockCount()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetBlockCount: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if syncerBlockCountResponse.BlockCount == syncerBlockCountResponse.HeaderCount {
|
||||||
|
t.Fatalf("Expected some pruned blocks but found none")
|
||||||
|
}
|
||||||
|
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
for range ticker.C {
|
||||||
|
if time.Since(start) > defaultTimeout {
|
||||||
|
t.Fatalf("Timeout waiting for IBD to finish.")
|
||||||
|
}
|
||||||
|
|
||||||
|
tip1Hash, err := syncer.rpcClient.GetSelectedTipHash()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error getting tip for syncer")
|
||||||
|
}
|
||||||
|
tip2Hash, err := syncee.rpcClient.GetSelectedTipHash()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error getting tip for syncee")
|
||||||
|
}
|
||||||
|
|
||||||
|
if tip1Hash.SelectedTipHash == tip2Hash.SelectedTipHash {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synceeBlockCountResponse, err := syncee.rpcClient.GetBlockCount()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetBlockCount: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if synceeBlockCountResponse.BlockCount != syncerBlockCountResponse.BlockCount+synceeOnlyBlocks+1 {
|
||||||
|
t.Fatalf("Because the syncee haven't pruned any of its old blocks, its expected "+
|
||||||
|
"block count is expected to be greater than the syncer by synceeOnlyBlocks(%d)+genesis, but instead "+
|
||||||
|
"we got syncer block count of %d and syncee block count of %d", synceeOnlyBlocks,
|
||||||
|
syncerBlockCountResponse.BlockCount,
|
||||||
|
synceeBlockCountResponse.BlockCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
if synceeBlockCountResponse.HeaderCount != syncerBlockCountResponse.HeaderCount+synceeOnlyBlocks {
|
||||||
|
t.Fatalf("Because the syncer haven't synced from the syncee, its expected "+
|
||||||
|
"block count is expected to be smaller by synceeOnlyBlocks(%d), but instead "+
|
||||||
|
"we got syncer headers count of %d and syncee headers count of %d", synceeOnlyBlocks,
|
||||||
|
syncerBlockCountResponse.HeaderCount,
|
||||||
|
synceeBlockCountResponse.HeaderCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ type appHarness struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
database database.Database
|
database database.Database
|
||||||
utxoIndex bool
|
utxoIndex bool
|
||||||
|
overrideDAGParams *dagconfig.Params
|
||||||
}
|
}
|
||||||
|
|
||||||
type harnessParams struct {
|
type harnessParams struct {
|
||||||
@ -30,6 +32,7 @@ type harnessParams struct {
|
|||||||
miningAddress string
|
miningAddress string
|
||||||
miningAddressPrivateKey string
|
miningAddressPrivateKey string
|
||||||
utxoIndex bool
|
utxoIndex bool
|
||||||
|
overrideDAGParams *dagconfig.Params
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupHarness creates a single appHarness with given parameters
|
// setupHarness creates a single appHarness with given parameters
|
||||||
@ -40,6 +43,7 @@ func setupHarness(t *testing.T, params *harnessParams) (harness *appHarness, tea
|
|||||||
miningAddress: params.miningAddress,
|
miningAddress: params.miningAddress,
|
||||||
miningAddressPrivateKey: params.miningAddressPrivateKey,
|
miningAddressPrivateKey: params.miningAddressPrivateKey,
|
||||||
utxoIndex: params.utxoIndex,
|
utxoIndex: params.utxoIndex,
|
||||||
|
overrideDAGParams: params.overrideDAGParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig(t, harness)
|
setConfig(t, harness)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user