mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
Fix notifyVirtualSelectedParentBlueScoreChanged to show the selected tip blue score instead of the virtual's (#1309)
* Fix notifyVirtualSelectedParentBlueScoreChanged to show the selected tip blue score instead of the virtual's * Fix ShouldMine() to fetch selected tip header
This commit is contained in:
parent
48278bd1c0
commit
02d5fb29cf
@ -65,14 +65,19 @@ func (f *FlowContext) ShouldMine() (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtualSelectedParentHeader, err := f.domain.Consensus().GetBlockHeader(virtualSelectedParent)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
now := mstime.Now().UnixMilliseconds()
|
now := mstime.Now().UnixMilliseconds()
|
||||||
if now-virtualSelectedParent.Header.TimeInMilliseconds < maxSelectedParentTimeDiffToAllowMiningInMilliSeconds {
|
if now-virtualSelectedParentHeader.TimeInMilliseconds < maxSelectedParentTimeDiffToAllowMiningInMilliSeconds {
|
||||||
log.Debugf("The selected tip timestamp is recent (%d), so ShouldMine returns true",
|
log.Debugf("The selected tip timestamp is recent (%d), so ShouldMine returns true",
|
||||||
virtualSelectedParent.Header.TimeInMilliseconds)
|
virtualSelectedParentHeader.TimeInMilliseconds)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("The selected tip timestamp is old (%d), so ShouldMine returns false",
|
log.Debugf("The selected tip timestamp is old (%d), so ShouldMine returns false",
|
||||||
virtualSelectedParent.Header.TimeInMilliseconds)
|
virtualSelectedParentHeader.TimeInMilliseconds)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -106,11 +106,17 @@ func (m *Manager) notifyVirtualSelectedParentBlueScoreChanged() error {
|
|||||||
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualSelectedParentBlueScoreChanged")
|
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualSelectedParentBlueScoreChanged")
|
||||||
defer onEnd()
|
defer onEnd()
|
||||||
|
|
||||||
virtualInfo, err := m.context.Domain.Consensus().GetVirtualInfo()
|
virtualSelectedParent, err := m.context.Domain.Consensus().GetVirtualSelectedParent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
notification := appmessage.NewVirtualSelectedParentBlueScoreChangedNotificationMessage(virtualInfo.BlueScore)
|
|
||||||
|
blockInfo, err := m.context.Domain.Consensus().GetBlockInfo(virtualSelectedParent)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
notification := appmessage.NewVirtualSelectedParentBlueScoreChangedNotificationMessage(blockInfo.BlueScore)
|
||||||
return m.context.NotificationManager.NotifyVirtualSelectedParentBlueScoreChanged(notification)
|
return m.context.NotificationManager.NotifyVirtualSelectedParentBlueScoreChanged(notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package rpchandlers
|
|||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,8 +13,7 @@ func HandleGetSelectedTipHash(context *rpccontext.Context, _ *router.Router, _ a
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response := appmessage.NewGetSelectedTipHashResponseMessage(
|
response := appmessage.NewGetSelectedTipHashResponseMessage(selectedTip.String())
|
||||||
consensushashing.BlockHash(selectedTip).String())
|
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ func (s *consensus) ValidateAndInsertPruningPoint(newPruningPoint *externalapi.D
|
|||||||
return s.blockProcessor.ValidateAndInsertPruningPoint(newPruningPoint, serializedUTXOSet)
|
return s.blockProcessor.ValidateAndInsertPruningPoint(newPruningPoint, serializedUTXOSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *consensus) GetVirtualSelectedParent() (*externalapi.DomainBlock, error) {
|
func (s *consensus) GetVirtualSelectedParent() (*externalapi.DomainHash, error) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ func (s *consensus) GetVirtualSelectedParent() (*externalapi.DomainBlock, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return s.blockStore.Block(s.databaseContext, virtualGHOSTDAGData.SelectedParent())
|
return virtualGHOSTDAGData.SelectedParent(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *consensus) Tips() ([]*externalapi.DomainHash, error) {
|
func (s *consensus) Tips() ([]*externalapi.DomainHash, error) {
|
||||||
|
@ -107,7 +107,7 @@ func TestFinality(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: Failed getting virtual selectedParent: %v", err)
|
t.Fatalf("TestFinality: Failed getting virtual selectedParent: %v", err)
|
||||||
}
|
}
|
||||||
if !consensushashing.BlockHash(selectedTip).Equal(sideChainTipHash) {
|
if !selectedTip.Equal(sideChainTipHash) {
|
||||||
t.Fatalf("Overtaking block in side-chain is not selectedTip")
|
t.Fatalf("Overtaking block in side-chain is not selectedTip")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ func TestFinality(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: Failed getting virtual selectedParent: %v", err)
|
t.Fatalf("TestFinality: Failed getting virtual selectedParent: %v", err)
|
||||||
}
|
}
|
||||||
selectedTipGhostDagData, err := consensus.GHOSTDAGDataStore().Get(consensus.DatabaseContext(), consensushashing.BlockHash(selectedTip))
|
selectedTipGhostDagData, err := consensus.GHOSTDAGDataStore().Get(consensus.DatabaseContext(), selectedTip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestFinality: Failed getting the ghost dag data of the selected tip: %v", err)
|
t.Fatalf("TestFinality: Failed getting the ghost dag data of the selected tip: %v", err)
|
||||||
}
|
}
|
||||||
@ -329,8 +329,8 @@ func TestBoundedMergeDepth(t *testing.T) {
|
|||||||
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !consensushashing.BlockHash(virtualSelectedParent).Equal(consensushashing.BlockHash(pointAtBlueKosherizing)) {
|
if !virtualSelectedParent.Equal(consensushashing.BlockHash(pointAtBlueKosherizing)) {
|
||||||
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", consensushashing.BlockHash(pointAtBlueKosherizing), consensushashing.BlockHash(virtualSelectedParent))
|
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", consensushashing.BlockHash(pointAtBlueKosherizing), virtualSelectedParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now let's make the kosherizing block red and try to merge again
|
// Now let's make the kosherizing block red and try to merge again
|
||||||
@ -346,8 +346,8 @@ func TestBoundedMergeDepth(t *testing.T) {
|
|||||||
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !consensushashing.BlockHash(virtualSelectedParent).Equal(tip) {
|
if !virtualSelectedParent.Equal(tip) {
|
||||||
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", tip, consensushashing.BlockHash(virtualSelectedParent))
|
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", tip, virtualSelectedParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
virtualGhotDagData, err = consensusReal.GHOSTDAGDataStore().Get(consensusReal.DatabaseContext(), model.VirtualBlockHash)
|
virtualGhotDagData, err = consensusReal.GHOSTDAGDataStore().Get(consensusReal.DatabaseContext(), model.VirtualBlockHash)
|
||||||
@ -382,8 +382,8 @@ func TestBoundedMergeDepth(t *testing.T) {
|
|||||||
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
t.Fatalf("TestBoundedMergeDepth: Failed getting the virtual selected parent %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !consensushashing.BlockHash(virtualSelectedParent).Equal(consensushashing.BlockHash(transitiveBlueKosherizing)) {
|
if !virtualSelectedParent.Equal(consensushashing.BlockHash(transitiveBlueKosherizing)) {
|
||||||
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", consensushashing.BlockHash(transitiveBlueKosherizing), consensushashing.BlockHash(virtualSelectedParent))
|
t.Fatalf("TestBoundedMergeDepth: Expected %s to be the selectedTip but found %s instead", consensushashing.BlockHash(transitiveBlueKosherizing), virtualSelectedParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lets validate the status of all the interesting blocks
|
// Lets validate the status of all the interesting blocks
|
||||||
|
@ -16,7 +16,7 @@ type Consensus interface {
|
|||||||
GetPruningPointUTXOSet(expectedPruningPointHash *DomainHash) ([]byte, error)
|
GetPruningPointUTXOSet(expectedPruningPointHash *DomainHash) ([]byte, error)
|
||||||
PruningPoint() (*DomainHash, error)
|
PruningPoint() (*DomainHash, error)
|
||||||
ValidateAndInsertPruningPoint(newPruningPoint *DomainBlock, serializedUTXOSet []byte) error
|
ValidateAndInsertPruningPoint(newPruningPoint *DomainBlock, serializedUTXOSet []byte) error
|
||||||
GetVirtualSelectedParent() (*DomainBlock, error)
|
GetVirtualSelectedParent() (*DomainHash, error)
|
||||||
CreateBlockLocator(lowHash, highHash *DomainHash, limit uint32) (BlockLocator, error)
|
CreateBlockLocator(lowHash, highHash *DomainHash, limit uint32) (BlockLocator, error)
|
||||||
FindNextBlockLocatorBoundaries(blockLocator BlockLocator) (lowHash, highHash *DomainHash, err error)
|
FindNextBlockLocatorBoundaries(blockLocator BlockLocator) (lowHash, highHash *DomainHash, err error)
|
||||||
GetSyncInfo() (*SyncInfo, error)
|
GetSyncInfo() (*SyncInfo, error)
|
||||||
|
@ -44,9 +44,9 @@ func TestVirtualSelectedParentBlueScore(t *testing.T) {
|
|||||||
for i := 0; i < blockAmountToMine; i++ {
|
for i := 0; i < blockAmountToMine; i++ {
|
||||||
mineNextBlock(t, kaspad)
|
mineNextBlock(t, kaspad)
|
||||||
notification := <-onVirtualSelectedParentBlueScoreChangedChan
|
notification := <-onVirtualSelectedParentBlueScoreChangedChan
|
||||||
if notification.VirtualSelectedParentBlueScore != 2+uint64(i) {
|
if notification.VirtualSelectedParentBlueScore != 1+uint64(i) {
|
||||||
t.Fatalf("Unexpected virtual selected parent blue score. Want: %d, got: %d",
|
t.Fatalf("Unexpected virtual selected parent blue score. Want: %d, got: %d",
|
||||||
2+uint64(i), notification.VirtualSelectedParentBlueScore)
|
1+uint64(i), notification.VirtualSelectedParentBlueScore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user