mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
Fix migrate resolve virtual percents (#2001)
* Fix migration virtual resolution percents * Don't sync consensus if pruning point is genesis * Don't add virtual to pruning point proof * Remove redundant check
This commit is contained in:
parent
90d9edb8e5
commit
3f840233d8
@ -14,7 +14,7 @@ import (
|
||||
|
||||
func (flow *handleIBDFlow) ibdWithHeadersProof(
|
||||
syncerHeaderSelectedTipHash, relayBlockHash *externalapi.DomainHash, highBlockDAAScore uint64) error {
|
||||
err := flow.Domain().InitStagingConsensus()
|
||||
err := flow.Domain().InitStagingConsensusWithoutGenesis()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func (d fakeDomain) StagingConsensus() externalapi.Consensus {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (d fakeDomain) InitStagingConsensus() error {
|
||||
func (d fakeDomain) InitStagingConsensusWithoutGenesis() error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
@ -264,9 +264,15 @@ func (ppm *pruningProofManager) buildPruningPointProof(stagingArea *model.Stagin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = queue.PushSlice(children)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, child := range children {
|
||||
if child.Equal(model.VirtualBlockHash) {
|
||||
continue
|
||||
}
|
||||
|
||||
err = queue.Push(child)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ type Domain interface {
|
||||
MiningManager() miningmanager.MiningManager
|
||||
Consensus() externalapi.Consensus
|
||||
StagingConsensus() externalapi.Consensus
|
||||
InitStagingConsensus() error
|
||||
InitStagingConsensusWithoutGenesis() error
|
||||
CommitStagingConsensus() error
|
||||
DeleteStagingConsensus() error
|
||||
}
|
||||
@ -49,7 +49,13 @@ func (d *domain) MiningManager() miningmanager.MiningManager {
|
||||
return d.miningManager
|
||||
}
|
||||
|
||||
func (d *domain) InitStagingConsensus() error {
|
||||
func (d *domain) InitStagingConsensusWithoutGenesis() error {
|
||||
cfg := *d.consensusConfig
|
||||
cfg.SkipAddingGenesis = true
|
||||
return d.initStagingConsensus(&cfg)
|
||||
}
|
||||
|
||||
func (d *domain) initStagingConsensus(cfg *consensus.Config) error {
|
||||
d.stagingConsensusLock.Lock()
|
||||
defer d.stagingConsensusLock.Unlock()
|
||||
|
||||
@ -79,10 +85,8 @@ func (d *domain) InitStagingConsensus() error {
|
||||
}
|
||||
|
||||
consensusFactory := consensus.NewFactory()
|
||||
cfg := *d.consensusConfig
|
||||
cfg.SkipAddingGenesis = true
|
||||
|
||||
consensusInstance, shouldMigrate, err := consensusFactory.NewConsensus(&cfg, d.db, inactivePrefix)
|
||||
consensusInstance, shouldMigrate, err := consensusFactory.NewConsensus(cfg, d.db, inactivePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ func TestCreateStagingConsensus(t *testing.T) {
|
||||
t.Fatalf("New: %+v", err)
|
||||
}
|
||||
|
||||
err = domainInstance.InitStagingConsensus()
|
||||
err = domainInstance.InitStagingConsensusWithoutGenesis()
|
||||
if err != nil {
|
||||
t.Fatalf("InitStagingConsensus: %+v", err)
|
||||
t.Fatalf("InitStagingConsensusWithoutGenesis: %+v", err)
|
||||
}
|
||||
|
||||
err = domainInstance.InitStagingConsensus()
|
||||
err = domainInstance.InitStagingConsensusWithoutGenesis()
|
||||
if !strings.Contains(err.Error(), "cannot create staging consensus when a staging consensus already exists") {
|
||||
t.Fatalf("unexpected error: %+v", err)
|
||||
}
|
||||
@ -114,9 +114,9 @@ func TestCreateStagingConsensus(t *testing.T) {
|
||||
|
||||
// Now we create a new staging consensus and check that it's deleted once we init a new domain. We also
|
||||
// validate that the main consensus persisted the data from the committed temp consensus.
|
||||
err = domainInstance.InitStagingConsensus()
|
||||
err = domainInstance.InitStagingConsensusWithoutGenesis()
|
||||
if err != nil {
|
||||
t.Fatalf("InitStagingConsensus: %+v", err)
|
||||
t.Fatalf("InitStagingConsensusWithoutGenesis: %+v", err)
|
||||
}
|
||||
|
||||
addGenesisToStagingConsensus()
|
||||
@ -139,9 +139,9 @@ func TestCreateStagingConsensus(t *testing.T) {
|
||||
t.Fatalf("a block from committed staging consensus was not persisted to the active consensus")
|
||||
}
|
||||
|
||||
err = domainInstance2.InitStagingConsensus()
|
||||
err = domainInstance2.InitStagingConsensusWithoutGenesis()
|
||||
if err != nil {
|
||||
t.Fatalf("InitStagingConsensus: %+v", err)
|
||||
t.Fatalf("InitStagingConsensusWithoutGenesis: %+v", err)
|
||||
}
|
||||
|
||||
blockInfo, err = domainInstance2.StagingConsensus().GetBlockInfo(blockHash)
|
||||
|
@ -7,14 +7,26 @@ import (
|
||||
|
||||
func (d *domain) migrate() error {
|
||||
log.Infof("Starting migration")
|
||||
err := d.InitStagingConsensus()
|
||||
pruningPoint, err := d.Consensus().PruningPoint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = syncConsensuses(d.Consensus(), d.StagingConsensus())
|
||||
if err != nil {
|
||||
return err
|
||||
if d.consensusConfig.Params.GenesisHash.Equal(pruningPoint) {
|
||||
err = d.initStagingConsensus(d.consensusConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = d.InitStagingConsensusWithoutGenesis()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = syncConsensuses(d.Consensus(), d.StagingConsensus())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = d.CommitStagingConsensus()
|
||||
@ -201,7 +213,11 @@ func syncConsensuses(syncer, syncee externalapi.Consensus) error {
|
||||
return err
|
||||
}
|
||||
|
||||
virtualDAAScoreStart := uint64(0)
|
||||
virtualDAAScoreStart, err := syncee.GetVirtualDAAScore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
percents = 0
|
||||
for i := 0; ; i++ {
|
||||
if i%10 == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user