Repository navigation
Conversation
|
This pull request is merged. |
|
please make sure that the DCO is checked. |
|
Hi @pfi79, thanks for checking! Yes, the commit has been signed off with DCO ( |
That's how I see it now. I don't know why it shows that way. But this is a problem.
|
|
Thanks @pfi79! The commit is signed off ( |
make rebase |
493d8f6 to
2b0866b
Compare
When a peer starts up with many historical chaincode packages, lifecycleCache.InitializeLocalChaincodes() loads each installed package. Previously, handleChaincodeInstalledWhileLocked() unconditionally called c.chaincodeCustodian.NotifyInstalled(packageID), triggering eager builds for all historical versions even if they were never approved or committed on any channel. This commit updates handleChaincodeInstalledWhileLocked to invoke c.chaincodeCustodian.NotifyInstalled(packageID) only when initializing is false (i.e., explicit install via 'peer lifecycle chaincode install'). During startup initialization (initializing is true), builds are deferred until first actual launch via RuntimeLauncher.Launch(). Fixes hyperledger#5599 Signed-off-by: shubhamrai9122-creator <shubhamrai9122@gmail.com>
2b0866b to
38a2f57
Compare
|
Rebased onto main and force-pushed. The DCO check should run now. |
pfi79
left a comment
There was a problem hiding this comment.
To assess whether this change is needed, please consider the inline comments.
| Expect(fakeParser.ParseCallCount()).To(Equal(0)) | ||
| }) | ||
|
|
||
| It("does not enqueue build requests with the custodian during initialization", func() { |
There was a problem hiding this comment.
Major: The new test does not exercise the changed startup path
Scenario
This test runs InitializeLocalChaincodes() in a setup where the package ID is already present in localChaincodes (populated by the outer BeforeEach). In that case, handleChaincodeInstalledWhileLocked takes the ok == true path and never enters the modified if !ok { ... } branch. The test only asserts that fakeBuilder.BuildCallCount stays at 0, so it can pass even with the old behavior.
Why it matters
The review/CI signal suggests the reported startup-build regression is covered, but the changed behavior is not actually pinned by this test.
How to verify/fix
Add a test where the installed package ID is not present in localChaincodes before InitializeLocalChaincodes() runs. After initialization, start the custodian worker with a fake builder/launcher/build registry and assert that no build chore is enqueued. The test should fail on the old behavior and pass with this PR. It may also be useful to assert that no unexpected runnable/launch work is enqueued for an unreferenced historical package.
| } | ||
| c.localChaincodes[hashOfCCHash] = localChaincode | ||
| c.chaincodeCustodian.NotifyInstalled(packageID) | ||
| if !initializing { |
There was a problem hiding this comment.
Minor: The explicit-install eager-build contract is not covered by a regression test
Scenario
The PR and issue #5599 state that peer lifecycle chaincode install should still trigger an eager build, while startup initialization should defer it. The diff changes the initializing guard, but there is no test that verifies the HandleChaincodeInstalled / initializing == false path still enqueues a build for a newly installed package.
Why it matters
A future refactor could accidentally remove the eager build for explicit installs, changing operator-visible behavior without a failing test.
How to verify/fix
Add a test for HandleChaincodeInstalled with a package ID that is not yet in the local cache. Start the custodian worker with a fake builder/launcher/build registry and assert that Build is eventually called once for that package ID.
| if !initializing { | ||
| c.chaincodeCustodian.NotifyInstalled(packageID) | ||
| } | ||
| } |
There was a problem hiding this comment.
Major: The fix only partially covers the issue scope for startup-installed packages
Scenario
The change skips NotifyInstalled during startup initialization when a local chaincode entry is first discovered. However, when the installed package already has references to approved chaincode definitions, handleChaincodeInstalledWhileLocked still calls NotifyInstalledAndRunnable(...) for those references regardless of initializing. The runnable path goes through launcher.Launch, and RuntimeLauncher.Launch performs Runtime.Build(ccid) when needed.
Why it matters
Issue #5599 is phrased as avoiding builds for all previously installed packages on peer startup. This PR helps the historical unused-package case, but approved+installed chaincodes may still be built/launched during startup. That makes the actual benefit narrower than the issue title/body may suggest.
How to verify/fix
Clarify the intended scope in the PR/issue: is the goal only to avoid building unreferenced historical packages, or to defer all installed-package builds until first real invoke? If full scope is intended, add coverage for approved+installed chaincodes during startup initialization and adjust the startup path so it does not enqueue launch/build work before first use.
Make the InitializeLocalChaincodes test start from an empty local cache so it exercises the new-entry branch, and assert that neither a build nor a launch is enqueued. Add a HandleChaincodeInstalled test asserting that an explicit install still builds the package eagerly. Signed-off-by: shubhamrai9122-creator <shubhamrai9122@gmail.com>
|
Thanks for the detailed review @pfi79!
|

Description
Fixes #5599
Currently, when the Fabric peer starts up,
lifecycleCache.InitializeLocalChaincodes()loads all chaincode packages previously installed on the peer. For each installed package,handleChaincodeInstalledWhileLocked()unconditionally calledc.chaincodeCustodian.NotifyInstalled(packageID). On peers that have accumulated many historical chaincode packages/versions across iterations, this causes the custodian to eagerly enqueue builds for every historical version during startup, consuming significant disk space and CPU even if those versions are no longer committed or approved on any channel.Solution
core/chaincode/lifecycle/cache.go, inhandleChaincodeInstalledWhileLocked(): only enqueuec.chaincodeCustodian.NotifyInstalled(packageID)when!initializing.initializing == true(peer startup viaInitializeLocalChaincodes()), the eager build enqueue is skipped. The chaincode image is instead built lazily when first launched viaRuntimeLauncher.Launch().initializing == false(explicit install viapeer lifecycle chaincode install), the eager build continues to be triggered immediately, preserving current operator expectations.core/chaincode/lifecycle/cache_test.go:InitializeLocalChaincodesdoes not enqueue build or launch work for an installed package that is not yet in the local cache, andHandleChaincodeInstalledstill builds a newly installed package eagerly.Scope
This PR stops startup from building installed packages that no chaincode definition references (for example, older versions).
InitializeLocalChaincodes()runs before any channel is initialized, so no package is linked to a definition at that point. Approved+installed chaincodes are still built and launched when their channels initialize, throughupdate(), as before. Deferring those until first invoke would change behaviour for chaincodes in use and is left for a separate change.All 407 unit tests in
core/chaincode/lifecyclepass cleanly.