Skip to content

Commit

Permalink
More updates to include log output in result record
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Sep 5, 2024
1 parent ad2c523 commit 6d83b8e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
16 changes: 15 additions & 1 deletion convex-core/src/main/java/convex/core/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ public static Result create(CVMLong id, ACell value, ACell errorCode, AHashMap<K
return buildFromVector(Vectors.of(id,value,errorCode,EMPTY_LOG,info));
}

/**
* Create a Result
* @param id ID of Result message
* @param value Result Value
* @param errorCode Error Code (may be null for success)
* @param log Log entries created during transaction
* @param info Additional info
* @return Result instance
*/
public static Result create(CVMLong id, ACell value, ACell errorCode, AVector<AVector<ACell>> log,AHashMap<Keyword,ACell> info) {
return buildFromVector(Vectors.of(id,value,errorCode,log,info));
}

/**
* Create a Result
* @param id ID of Result message
Expand Down Expand Up @@ -308,6 +321,7 @@ public static Result fromContext(CVMLong id,ResultContext rc) {
Context ctx=rc.context;
Object result=ctx.getValue();
ACell errorCode=null;
AVector<AVector<ACell>> log = ctx.getLog();
AHashMap<Keyword,ACell> info=Maps.empty();
if (result instanceof AExceptional) {
AExceptional ex=(AExceptional)result;
Expand All @@ -327,7 +341,7 @@ public static Result fromContext(CVMLong id,ResultContext rc) {
if (rc.juiceUsed>0) info=info.assoc(Keywords.JUICE, CVMLong.create(rc.juiceUsed));
if (rc.source!=null) info=info.assoc(Keywords.SOURCE, rc.source);

return create(id,(ACell)result,errorCode,info);
return create(id,(ACell)result,errorCode,log,info);
}

public Result withExtraInfo(Map<Keyword,ACell> extInfo) {
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/lang/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ public Context appendLog(AVector<ACell> values) {
if (log==null) {
log=Vectors.empty();
}
AVector<ACell> entry = Vectors.of(addr,scope,values);
AVector<ACell> entry = Vectors.of(addr,scope,null,values);
log=log.conj(entry);

this.log=log;
Expand Down
5 changes: 3 additions & 2 deletions convex-core/src/main/java/convex/core/lang/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
*/
public class Log {

public static final int ENTRY_LENGTH = 3;
public static final int ENTRY_LENGTH = 4;

// Positions of fields in log entries
public static final int P_ADDRESS=0;
public static final int P_SCOPE=1;
public static final int P_VALUES=2;
public static final int P_LOCATION=2;
public static final int P_VALUES=3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ public void testMemoryAccounting() throws BadSignatureException {
BlockResult br2=s.applyBlock(sb2);
State s2=br2.getState();
assertEquals(memPool+Constants.MEMORY_POOL_GROWTH,s2.getGlobalMemoryPool().longValue());

}

@Test
public void testScheduleOps() throws BadSignatureException {
State s = TestState.STATE;
Expand Down
4 changes: 3 additions & 1 deletion convex-core/src/test/java/convex/core/lang/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,9 @@ public void testLog() {
assertNotNull(log);

assertEquals(1,log.count()); // one log entry only
assertEquals(v0,log.get(0).get(Log.P_VALUES));
AVector<ACell> entry=log.get(0);
assertEquals(Log.ENTRY_LENGTH,entry.size()); // should be two entries now
assertEquals(v0,entry.get(Log.P_VALUES));

// do second log in same context
AVector<ACell> v1=Vectors.of(3L, 4L);
Expand Down

0 comments on commit 6d83b8e

Please sign in to comment.