Skip to content

Commit

Permalink
fixup! feat: add libdriver
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Dec 6, 2023
1 parent e26576c commit c3b1bde
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
12 changes: 5 additions & 7 deletions linux/libcmt/examples/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(void)
break;
}
cmt_rollup_emit_voucher(&rollup, advance.sender, advance.length, advance.data);
cmt_rollup_emit_report(&rollup, inspect.length, inspect.data);
cmt_rollup_emit_report(&rollup, advance.length, advance.data);
break;

case CMT_ROLLUP_INSPECT_STATE:
Expand All @@ -44,12 +44,10 @@ int main(void)
cmt_rollup_emit_report(&rollup, inspect.length, inspect.data);
break;

default:
finish.accept_previous_request = false;
break;
default: // <- end of inputs when testing
cmt_rollup_fini(&rollup);
return EXIT_SUCCESS;
}
}

cmt_rollup_fini(&rollup);
return 0;
return EXIT_SUCCESS;
}
6 changes: 3 additions & 3 deletions linux/libcmt/include/libcmt/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ cmt_rollup_emit_report(cmt_rollup_t *me
* - 0 success
* - -ENOBUFS no space left in @p me */
int
cmt_rollup_emit_report(cmt_rollup_t *me
,size_t n
,const void *data);
cmt_rollup_emit_exception(cmt_rollup_t *me
,size_t n
,const void *data);

/** read advance state
*
Expand Down
2 changes: 1 addition & 1 deletion linux/libcmt/src/merkle.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int cmt_merkle_push_back(cmt_merkle_t *me, uint8_t hash[CMT_KECCAK_LENGTH])
if (me->leaf_count == UINT64_MAX)
return -ENOBUFS;

unsigned n = ((uint64_t)ffsll(++me->leaf_count)-1u);
unsigned n = (uint64_t)ffsll(++me->leaf_count) - 1u;
for (unsigned i=0; i<n; ++i)
hash2(me->state[i], hash, hash);
memcpy(me->state[n], hash, CMT_KECCAK_LENGTH);
Expand Down
2 changes: 1 addition & 1 deletion linux/libcmt/src/mock/rollup-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int cmt_rollup_driver_write_report(struct cmt_rollup_driver *me, size_t n)
char filename[1024];
if (!me) return -EINVAL;
snprintf(filename, sizeof(filename), "input-%u-report-%u.bin",
me->input_seq, ++me->output_seq - 1);
me->input_seq, ++me->report_seq - 1);
return cmt_rollup_driver_mock_write(me, n, filename);
}

Expand Down
10 changes: 8 additions & 2 deletions linux/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,22 @@ int cmt_rollup_emit_notice(cmt_rollup_t *me, size_t length, const void *data)
int cmt_rollup_emit_report(cmt_rollup_t *me, size_t length, const void *data)
{
if (!me) return -EINVAL;
if (!data && length) return -EINVAL;
if (cmt_buf_length(me->tx) < length)
return -ENOBUFS;

memcpy(me->tx, data, length);
memcpy(me->tx->begin, data, length);
return cmt_rollup_driver_write_report(me->rollup_driver, length);
}

int cmt_rollup_emit_exception(cmt_rollup_t *me, size_t length, const void *data)
{
if (!me) return -EINVAL;
if (!data && length) return -EINVAL;
if (cmt_buf_length(me->tx) < length)
return -ENOBUFS;

memcpy(me->tx, data, length);
memcpy(me->tx->begin, data, length);
return cmt_rollup_driver_write_exception(me->rollup_driver, length);
}

Expand Down

0 comments on commit c3b1bde

Please sign in to comment.