From 0479a7f18c89d6d332568ae580292358cd06feb4 Mon Sep 17 00:00:00 2001 From: tokikuch Date: Thu, 21 Dec 2023 14:38:31 -0800 Subject: [PATCH] Do not call `node.GetChains()` if node is nil (#1588) In `NewSessionNodes`, the variable `node` can be `nil` if the node is unstaked between `sessionCtx` and `ctx`. In such a case, `node.GetChains()` causes a panic. This patch makes sure we don't call it if the `node` is `nil`. This is a regression from #1582. ## Description ### Summary generated by Reviewpad on 21 Dec 23 10:23 UTC This pull request fixes a regression introduced in #1582. The patch ensures that the function `node.GetChains()` is not called if the `node` is `nil`, preventing a panic in the `NewSessionNodes` function. --- x/pocketcore/types/session.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/pocketcore/types/session.go b/x/pocketcore/types/session.go index d2c4fde13..04c5d7750 100644 --- a/x/pocketcore/types/session.go +++ b/x/pocketcore/types/session.go @@ -150,10 +150,9 @@ func NewSessionNodes( // cross check the node from the `new` or `end` world state node = keeper.Validator(ctx, n) - lenNodeChains := int64(len(node.GetChains())) // if not found or jailed or is overstaked to chains if node == nil || - (isEnforceMaxChains && lenNodeChains > nodeMaxChains) || + (isEnforceMaxChains && int64(len(node.GetChains())) > nodeMaxChains) || node.IsJailed() || !NodeHasChain(chain, node) || sessionNodes.Contains(node.GetAddress()) {