File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,10 +97,16 @@ library SubnetIDHelper {
9797
9898 /// @notice Computes the common parent of the current subnet and the one given as argument
9999 function commonParent (SubnetID calldata subnet1 , SubnetID calldata subnet2 ) public pure returns (SubnetID memory ) {
100+ // If the roots are not identical, exit early
100101 if (subnet1.root != subnet2.root) {
101102 return SubnetID ({root: 0 , route: new address [](0 )});
102103 }
103104
105+ // If both subnet addresses references the same subnet, return early
106+ if (equals (subnet1, subnet2)) {
107+ return subnet1;
108+ }
109+
104110 uint256 i;
105111 uint256 subnet1routeLength = subnet1.route.length ;
106112 uint256 subnet2routeLength = subnet2.route.length ;
@@ -113,6 +119,8 @@ library SubnetIDHelper {
113119 return SubnetID ({root: subnet1.root, route: new address [](0 )});
114120 }
115121
122+ // note: only works for subnets that differ at least in the leaf element,
123+ // since `i + 1 === min(subnet1routeLength, subnet2routeLength)`
116124 address [] memory route = new address [](i);
117125 for (uint256 j; j < i; ) {
118126 route[j] = subnet1.route[j];
You can’t perform that action at this time.
0 commit comments