Skip to content

Commit

Permalink
increment failures of failed peer sync (#2013)
Browse files Browse the repository at this point in the history
* syncPeers: increment failures of failed peer sync

* update pact

Change-Id: I4ebc941a36bf16b5f09f39ad3e18ec7d06424fa1
  • Loading branch information
chessai authored Oct 26, 2024
1 parent d4a89ed commit 2854d0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/kadena-io/pact-5.git
tag: a8801ebc77882c12e3c798bdd1666d1a1a184c79
--sha256: 1a9dsh96g212hbwksbwc8wp5wcjbfsivdjqdqjnhdfvi8gfi7gqh
tag: f52bf31c2921e8426bcd4003736280b5bc335f55
--sha256: 1b3m5ay8jmj20b2jgd3j7z9ccncpyykazay3mgyp8q39rpjmg20a

source-repository-package
type: git
Expand Down
12 changes: 8 additions & 4 deletions src/P2P/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ syncFromPeer node info = do
return False
| otherwise -> do
logg node Warn $ "failed to sync peers from " <> showInfo info <> ": " <> showClientError e
-- chessdmund: The idea is that incrementSuccessiveFailures here could help eliminate redundant synchronisation attempts.
incrementSuccessiveFailures peerDb info
return False
Right p -> do
peers <- peerDbSnapshot peerDb
Expand Down Expand Up @@ -508,18 +510,20 @@ findNextPeer conf node = do
candidates <- awaitCandidates

-- random circular shift of a set
let shift i = uncurry (++)
let shift :: Int -> [a] -> [a]
shift i = uncurry (++)
. swap
. splitAt (fromIntegral i)
. splitAt i

let shiftR :: [a] -> IO [a]
shiftR s = do
i <- nodeRandomR node (0, max 1 (length s) - 1)
return $ shift i s

let (p0, p1) = L.partition (\p -> _peerEntryActiveSessionCount p > 0 && _peerEntrySuccessiveFailures p <= 1) candidates

-- this ix expensive but lazy and only forced if p0 is empty
p2 = L.groupBy ((==) `on` _peerEntrySuccessiveFailures) p1
-- this ix expensive but lazy and only forced if p0 is empty
let p2 = L.groupBy ((==) `on` _peerEntrySuccessiveFailures) p1


-- Choose the category to pick from
Expand Down

0 comments on commit 2854d0d

Please sign in to comment.