From 2f255952b71e485559e74728afd9de120b619f83 Mon Sep 17 00:00:00 2001 From: Mike Zak Date: Mon, 13 Apr 2020 15:10:27 +0300 Subject: [PATCH 1/5] Updated to version v0.3.1 --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 2f4efd536..9e29056fe 100644 --- a/version/version.go +++ b/version/version.go @@ -11,7 +11,7 @@ const validCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs const ( appMajor uint = 0 appMinor uint = 3 - appPatch uint = 0 + appPatch uint = 1 ) // appBuild is defined as a variable so it can be overridden during the build From 3fd647b291780acfde87955b903cc83ccfe628bc Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Mon, 13 Apr 2020 15:49:46 +0300 Subject: [PATCH 2/5] [NOD-858] Don't switch sync peer if the syncing process hasn't yet started with the current sync peer (#700) * [NOD-858] Don't switch sync peer if the syncing process hasn't yet started with the current sync peer * [NOD-858] SetShouldSendBlockLocator(false) on OnBlockLocator * [NOD-858] Rename shouldSendBlockLocator->wasBlockLocatorRequested * [NOD-858] Move panic to shouldReplaceSyncPeer --- netsync/manager.go | 46 ++++++++++++++++++++++------------ peer/peer.go | 17 +++++++++++++ server/p2p/on_block_locator.go | 1 + 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/netsync/manager.go b/netsync/manager.go index bc1cefb20..d10e4e066 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -157,6 +157,7 @@ type SyncManager struct { msgChan chan interface{} wg sync.WaitGroup quit chan struct{} + syncPeerLock sync.Mutex // These fields should only be accessed from the messageHandler thread rejectedTxns map[daghash.TxID]struct{} @@ -170,6 +171,8 @@ type SyncManager struct { // download/sync the blockDAG from. When syncing is already running, it // simply returns. It also examines the candidates for any which are no longer // candidates and removes them as needed. +// +// This function MUST be called with the sync peer lock held. func (sm *SyncManager) startSync() { // Return now if we're already syncing. if sm.syncPeer != nil { @@ -189,6 +192,7 @@ func (sm *SyncManager) startSync() { // TODO(davec): Use a better algorithm to choose the sync peer. // For now, just pick the first available candidate. syncPeer = peer + break } // Start syncing from the sync peer if one was selected. @@ -294,8 +298,8 @@ func (sm *SyncManager) handleNewPeerMsg(peer *peerpkg.Peer) { } // Start syncing by choosing the best candidate if needed. - if isSyncCandidate && sm.syncPeer == nil { - sm.startSync() + if isSyncCandidate { + sm.restartSyncIfNeeded() } } @@ -337,7 +341,7 @@ func (sm *SyncManager) stopSyncFromPeer(peer *peerpkg.Peer) { // sync peer. if sm.syncPeer == peer { sm.syncPeer = nil - sm.startSync() + sm.restartSyncIfNeeded() } } @@ -427,24 +431,34 @@ func (sm *SyncManager) current() bool { // restartSyncIfNeeded finds a new sync candidate if we're not expecting any // blocks from the current one. func (sm *SyncManager) restartSyncIfNeeded() { - if sm.syncPeer != nil { - syncPeerState, exists := sm.peerStates[sm.syncPeer] - if exists { - isWaitingForBlocks := func() bool { - syncPeerState.requestQueueMtx.Lock() - defer syncPeerState.requestQueueMtx.Unlock() - return len(syncPeerState.requestedBlocks) != 0 || len(syncPeerState.requestQueues[wire.InvTypeSyncBlock].queue) != 0 - }() - if isWaitingForBlocks { - return - } - } + sm.syncPeerLock.Lock() + defer sm.syncPeerLock.Unlock() + + if !sm.shouldReplaceSyncPeer() { + return } sm.syncPeer = nil sm.startSync() } +func (sm *SyncManager) shouldReplaceSyncPeer() bool { + if sm.syncPeer == nil { + return true + } + + syncPeerState, exists := sm.peerStates[sm.syncPeer] + if !exists { + panic(errors.Errorf("no peer state for sync peer %s", sm.syncPeer)) + } + + syncPeerState.requestQueueMtx.Lock() + defer syncPeerState.requestQueueMtx.Unlock() + return len(syncPeerState.requestedBlocks) == 0 && + len(syncPeerState.requestQueues[wire.InvTypeSyncBlock].queue) == 0 && + !sm.syncPeer.WasBlockLocatorRequested() +} + // handleBlockMsg handles block messages from all peers. func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { peer := bmsg.peer @@ -905,7 +919,7 @@ func (sm *SyncManager) handleSelectedTipMsg(msg *selectedTipMsg) { return } peer.SetSelectedTipHash(selectedTipHash) - sm.startSync() + sm.restartSyncIfNeeded() } // messageHandler is the main handler for the sync manager. It must be run as a diff --git a/peer/peer.go b/peer/peer.go index 6074aa794..a9559d684 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -414,6 +414,8 @@ type Peer struct { prevGetBlockInvsLow *daghash.Hash prevGetBlockInvsHigh *daghash.Hash + wasBlockLocatorRequested bool + // These fields keep track of statistics for the peer and are protected // by the statsMtx mutex. statsMtx sync.RWMutex @@ -435,6 +437,20 @@ type Peer struct { quit chan struct{} } +// WasBlockLocatorRequested returns whether the node +// is expecting to get a block locator from this +// peer. +func (p *Peer) WasBlockLocatorRequested() bool { + return p.wasBlockLocatorRequested +} + +// SetWasBlockLocatorRequested sets whether the node +// is expecting to get a block locator from this +// peer. +func (p *Peer) SetWasBlockLocatorRequested(wasBlockLocatorRequested bool) { + p.wasBlockLocatorRequested = wasBlockLocatorRequested +} + // String returns the peer's address and directionality as a human-readable // string. // @@ -775,6 +791,7 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress, subnetworkID *subnetwor // // This function is safe for concurrent access. func (p *Peer) PushGetBlockLocatorMsg(highHash, lowHash *daghash.Hash) { + p.SetWasBlockLocatorRequested(true) msg := wire.NewMsgGetBlockLocator(highHash, lowHash) p.QueueMessage(msg, nil) } diff --git a/server/p2p/on_block_locator.go b/server/p2p/on_block_locator.go index d043ffbb8..6934b16e9 100644 --- a/server/p2p/on_block_locator.go +++ b/server/p2p/on_block_locator.go @@ -8,6 +8,7 @@ import ( // OnBlockLocator is invoked when a peer receives a locator kaspa // message. func (sp *Peer) OnBlockLocator(_ *peer.Peer, msg *wire.MsgBlockLocator) { + sp.SetWasBlockLocatorRequested(false) // Find the highest known shared block between the peers, and asks // the block and its future from the peer. If the block is not // found, create a lower resolution block locator and send it to From c88869778d7fd10360895a954e980f40bff061e8 Mon Sep 17 00:00:00 2001 From: Svarog Date: Thu, 16 Apr 2020 15:03:41 +0300 Subject: [PATCH 3/5] [NOD-869] Add a print after os.Exit(1) to see if it is ever called (#701) --- util/panics/panics.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/panics/panics.go b/util/panics/panics.go index 4f04e2e75..a99d3d5d0 100644 --- a/util/panics/panics.go +++ b/util/panics/panics.go @@ -24,6 +24,7 @@ func HandlePanic(log *logs.Logger, goroutineStackTrace []byte) { log.Criticalf("Goroutine stack trace: %s", goroutineStackTrace) } log.Criticalf("Stack trace: %s", debug.Stack()) + log.Backend().Close() close(panicHandlerDone) }() @@ -34,8 +35,9 @@ func HandlePanic(log *logs.Logger, goroutineStackTrace []byte) { fmt.Fprintln(os.Stderr, "Couldn't handle a fatal error. Exiting...") case <-panicHandlerDone: } - log.Criticalf("Exiting") + fmt.Print("Exiting...") os.Exit(1) + fmt.Print("After os.Exit(1)") } // GoroutineWrapperFunc returns a goroutine wrapper function that handles panics and writes them to the log. From 5f3fb0bf9f7f5cfc5df7efde171a0c4fae2c6edd Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Tue, 11 Aug 2020 12:04:54 +0300 Subject: [PATCH 4/5] [NOD-1238] Fix acceptance index never being initialized. (#859) --- app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/app.go b/app/app.go index 5f8ebed2d..a0b3fc970 100644 --- a/app/app.go +++ b/app/app.go @@ -168,6 +168,7 @@ func setupIndexes(cfg *config.Config) (blockdag.IndexManager, *indexers.Acceptan var acceptanceIndex *indexers.AcceptanceIndex if cfg.AcceptanceIndex { log.Info("acceptance index is enabled") + acceptanceIndex = indexers.NewAcceptanceIndex() indexes = append(indexes, acceptanceIndex) } From f6dfce81804d172a8624efabdc7597f72859497c Mon Sep 17 00:00:00 2001 From: alexandratran <12214231+alexandratran@users.noreply.github.com> Date: Thu, 26 Nov 2020 21:46:57 -0800 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2dbd6e811..7b504fce0 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ is used for this project. ## Documentation -The documentation is a work-in-progress. It is located in the [docs](https://github.com/kaspanet/kaspad/tree/master/docs) folder. +The documentation is a work-in-progress. ## License