mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +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(
|
func (flow *handleIBDFlow) ibdWithHeadersProof(
|
||||||
syncerHeaderSelectedTipHash, relayBlockHash *externalapi.DomainHash, highBlockDAAScore uint64) error {
|
syncerHeaderSelectedTipHash, relayBlockHash *externalapi.DomainHash, highBlockDAAScore uint64) error {
|
||||||
err := flow.Domain().InitStagingConsensus()
|
err := flow.Domain().InitStagingConsensusWithoutGenesis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func (d fakeDomain) StagingConsensus() externalapi.Consensus {
|
|||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d fakeDomain) InitStagingConsensus() error {
|
func (d fakeDomain) InitStagingConsensusWithoutGenesis() error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,9 +264,15 @@ func (ppm *pruningProofManager) buildPruningPointProof(stagingArea *model.Stagin
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = queue.PushSlice(children)
|
for _, child := range children {
|
||||||
if err != nil {
|
if child.Equal(model.VirtualBlockHash) {
|
||||||
return nil, err
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = queue.Push(child)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ type Domain interface {
|
|||||||
MiningManager() miningmanager.MiningManager
|
MiningManager() miningmanager.MiningManager
|
||||||
Consensus() externalapi.Consensus
|
Consensus() externalapi.Consensus
|
||||||
StagingConsensus() externalapi.Consensus
|
StagingConsensus() externalapi.Consensus
|
||||||
InitStagingConsensus() error
|
InitStagingConsensusWithoutGenesis() error
|
||||||
CommitStagingConsensus() error
|
CommitStagingConsensus() error
|
||||||
DeleteStagingConsensus() error
|
DeleteStagingConsensus() error
|
||||||
}
|
}
|
||||||
@ -49,7 +49,13 @@ func (d *domain) MiningManager() miningmanager.MiningManager {
|
|||||||
return d.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()
|
d.stagingConsensusLock.Lock()
|
||||||
defer d.stagingConsensusLock.Unlock()
|
defer d.stagingConsensusLock.Unlock()
|
||||||
|
|
||||||
@ -79,10 +85,8 @@ func (d *domain) InitStagingConsensus() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
consensusFactory := consensus.NewFactory()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,12 @@ func TestCreateStagingConsensus(t *testing.T) {
|
|||||||
t.Fatalf("New: %+v", err)
|
t.Fatalf("New: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = domainInstance.InitStagingConsensus()
|
err = domainInstance.InitStagingConsensusWithoutGenesis()
|
||||||
if err != nil {
|
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") {
|
if !strings.Contains(err.Error(), "cannot create staging consensus when a staging consensus already exists") {
|
||||||
t.Fatalf("unexpected error: %+v", err)
|
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
|
// 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.
|
// validate that the main consensus persisted the data from the committed temp consensus.
|
||||||
err = domainInstance.InitStagingConsensus()
|
err = domainInstance.InitStagingConsensusWithoutGenesis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InitStagingConsensus: %+v", err)
|
t.Fatalf("InitStagingConsensusWithoutGenesis: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
addGenesisToStagingConsensus()
|
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")
|
t.Fatalf("a block from committed staging consensus was not persisted to the active consensus")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = domainInstance2.InitStagingConsensus()
|
err = domainInstance2.InitStagingConsensusWithoutGenesis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InitStagingConsensus: %+v", err)
|
t.Fatalf("InitStagingConsensusWithoutGenesis: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blockInfo, err = domainInstance2.StagingConsensus().GetBlockInfo(blockHash)
|
blockInfo, err = domainInstance2.StagingConsensus().GetBlockInfo(blockHash)
|
||||||
|
@ -7,14 +7,26 @@ import (
|
|||||||
|
|
||||||
func (d *domain) migrate() error {
|
func (d *domain) migrate() error {
|
||||||
log.Infof("Starting migration")
|
log.Infof("Starting migration")
|
||||||
err := d.InitStagingConsensus()
|
pruningPoint, err := d.Consensus().PruningPoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = syncConsensuses(d.Consensus(), d.StagingConsensus())
|
if d.consensusConfig.Params.GenesisHash.Equal(pruningPoint) {
|
||||||
if err != nil {
|
err = d.initStagingConsensus(d.consensusConfig)
|
||||||
return err
|
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()
|
err = d.CommitStagingConsensus()
|
||||||
@ -201,7 +213,11 @@ func syncConsensuses(syncer, syncee externalapi.Consensus) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
virtualDAAScoreStart := uint64(0)
|
virtualDAAScoreStart, err := syncee.GetVirtualDAAScore()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
percents = 0
|
percents = 0
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
if i%10 == 0 {
|
if i%10 == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user