Skip to content

Commit 7cc0dec

Browse files
committed
Add constant controlling maximum parent lookup depth
1 parent 4b75ec2 commit 7cc0dec

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

convex-core/src/main/java/convex/core/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,10 @@ public class Constants {
224224

225225
public static final String DEFAULT_KEYSTORE_FILENAME = "~/.convex/keystore.pfx";
226226

227+
/**
228+
* Maximum depth of lookups via parent accounts
229+
*/
230+
public static final int LOOKUP_DEPTH = 16;
231+
227232

228233
}

convex-core/src/main/java/convex/core/lang/Context.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public AHashMap<ACell,ACell> lookupMeta(Symbol sym) {
576576
*/
577577
public AHashMap<ACell,ACell> lookupMeta(Address address,Symbol sym) {
578578
AccountStatus as=(address==null)?getAccountStatus():getAccountStatus(address);
579-
for (int i=0; i<16; i++) {
579+
for (int i=0; i<Constants.LOOKUP_DEPTH; i++) {
580580
if (as==null) return null;
581581
AHashMap<Symbol, ACell> env=as.getEnvironment();
582582
if (env.containsKey(sym)) {
@@ -599,7 +599,8 @@ public Context lookupDefiningAddress(Address address,Symbol sym) {
599599
Context ctx=this;
600600
Address addr=(address==null)?getAddress():address;
601601

602-
while (addr!=null) {
602+
for (int i=0; i<Constants.LOOKUP_DEPTH; i++) {
603+
if (addr==null) break;
603604
AccountStatus as=getAccountStatus(addr);
604605
if (as==null) return ctx.withResult(Juice.LOOKUP, null);
605606

@@ -672,7 +673,7 @@ public MapEntry<Symbol,ACell> lookupDynamicEntry(Address address,Symbol sym) {
672673

673674
private MapEntry<Symbol,ACell> lookupDynamicEntry(AccountStatus as,Symbol sym) {
674675
// Get environment for Address, or default to initial environment
675-
for (int i=0; i<16; i++) {
676+
for (int i=0; i<Constants.LOOKUP_DEPTH; i++) {
676677
if (as==null) return Core.ENVIRONMENT.getEntry(sym);
677678

678679
MapEntry<Symbol,ACell> result=as.getEnvironment().getEntry(sym);

0 commit comments

Comments
 (0)