smartcontract/cli: improve resource verify (flex-algo, duplicate usage, out-of-range loopback IPs, code labels)#3739
Merged
Merged
Conversation
…licate usages verify_segment_routing_ids now walks Interface.flex_algo_node_segments in addition to the base node_segment_idx, so per-topology segment IDs allocated by interface-create and assign_node_segments are recognized as in-use instead of appearing under "Allocated but not used." A value with multiple owners is now emitted as a single DuplicateUsage that lists every owner (collapsing N-way collisions into one entry) and is suppressed from the "Used but not allocated" section, where it was previously double-reported.
…lBlock verify Interface and link processors honor a caller-supplied ip_net/tunnel_net and skip the DeviceTunnelBlock allocator on that path — most commonly for user-tunnel-endpoint Vpnv4 loopbacks that land on a globally routable IP outside the block. Those IPs are not in the allocator's bitmap, so verify_device_tunnel_block was falsely flagging them as UsedButNotAllocated. Filter loopback and link IPs through the block's base_net before counting them as in-use, mirroring how verify_multicast_publisher_block handles legacy out-of-range dz_ips.
…vice/link codes Build a pubkey -> code map from devices and links during verify_resources, expose it on VerifyResourceResult, and prefix every pubkey emitted in the 'Used but not allocated', 'Duplicate usage', and 'Orphaned resource extensions' sections with its code. Unknown pubkeys (e.g. Users, or extensions associated with a deleted device) print as before.
martinsander00
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
verify_segment_routing_idsnow walksInterface.flex_algo_node_segmentsalongside the basenode_segment_idx, so per-topology segment IDs allocated by interface-create and theassign_node_segmentsbackfill are counted as in-use instead of appearing under "Allocated but not used."verify_device_tunnel_blockfilters loopback and link IPs through the block'sbase_netbefore counting them as in-use. Caller-supplied IPs (most commonly globally routable user-tunnel-endpoint loopbacks) skip the allocator onchain and were being falsely flagged as "Used but not allocated."DuplicateUsagethat lists every owner (collapsing N-way collisions into one entry) and is suppressed from the "Used but not allocated" section, where it was previously double-reported.code— e.g.Device interface Loopback0 dz1 (ABC...)andLink xams-mad (XYZ...)— in the "Used but not allocated", "Duplicate usage", and "Orphaned resource extensions" sections.smartcontract/programs/CLAUDE.mdthat any newResourceExtensionallocation/deallocation must update the correspondingverify_*function in the CLI so the verifier stays in sync with onchain state.Diff Breakdown
The net production-code change is small (an enum-variant refactor, two helper rewrites, two
base_net.containsfilters, and a pubkey-label map); the bulk of additions are tests that lock down the new behavior.Key files (click to expand)
smartcontract/cli/src/resource/verify.rs— flex-algo segments folded intoverify_segment_routing_ids;verify_device_tunnel_blockskips loopback/link IPs outside the block'sbase_net;DuplicateUsageenum now carriesaccounts: Vec<(Pubkey, String)>;insert_usageis append-only andcheck_discrepanciesemits one combined duplicate per value and skips those values when reportingUsedButNotAllocated;VerifyResourceResultgains apubkey_labels: HashMap<Pubkey, String>populated from device/link codes, and the display layer printscode (pubkey)everywhere; 6 new tests + helperssmartcontract/programs/CLAUDE.md— new "Resource Allocation" rule pointing processor authors atverify_*insmartcontract/cli/src/resource/verify.rsTesting Verification
UsedButNotAllocated, (4) triple collision collapses into a singleDuplicateUsagewithaccounts.len() == 3, (5) loopback IP outsideDeviceTunnelBlock.base_net(user-tunnel-endpoint case) is not reported, (6) device codes are rendered alongside pubkeys in the output.resource::verifytests continue to pass.