Skip to content

Commit

Permalink
Renamed voucher field: address -> destination
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Politzer committed Apr 5, 2023
1 parent 528354e commit de475c6
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed rollups-http-server when it receives an inspect with 0 bytes
- Updated linux-sources to v5.15.63-ctsi-2
- Update toolchain to 0.14.0
- Renamed voucher field: address -> destination

## [0.10.0] - 2023-02-15
### Changed
Expand Down
2 changes: 1 addition & 1 deletion linux/rollup/http/echo-dapp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn process_advance_request(
for _ in 0..config.test_config.vouchers {
let voucher_payload = request.payload.clone();
let voucher = Voucher {
address: request.metadata.msg_sender.clone(),
destination: request.metadata.msg_sender.clone(),
payload: voucher_payload,
};

Expand Down
2 changes: 1 addition & 1 deletion linux/rollup/http/rollup-http-client/src/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Notice {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Voucher {
pub address: String,
pub destination: String,
pub payload: String,
}

Expand Down
8 changes: 4 additions & 4 deletions linux/rollup/http/rollup-http-server/src/http_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ pub async fn run(
async fn voucher(mut voucher: Json<Voucher>, data: Data<Mutex<Context>>) -> HttpResponse {
log::debug!("received voucher request");
// Check if address is valid
if voucher.address.len() != (rollup::CARTESI_ROLLUP_ADDRESS_SIZE * 2 + 2) as usize
|| (!voucher.address.starts_with("0x"))
if voucher.destination.len() != (rollup::CARTESI_ROLLUP_ADDRESS_SIZE * 2 + 2) as usize
|| (!voucher.destination.starts_with("0x"))
{
log::error!(
"address not valid: '{}' len: {}",
voucher.address,
voucher.address.len()
voucher.destination,
voucher.destination.len()
);
return HttpResponse::BadRequest().body("Address not valid");
}
Expand Down
4 changes: 2 additions & 2 deletions linux/rollup/http/rollup-http-server/src/rollup/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ int rollup_read_inspect_state_request(int fd, struct rollup_finish *finish, stru
/* Outputs a new voucher.
* voucher_index is filled with new index from the driver
* Returns 0 on success, -1 on error */
int rollup_write_voucher(int fd, uint8_t address[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes,
int rollup_write_voucher(int fd, uint8_t destination[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes,
uint64_t *voucher_index) {
struct rollup_voucher v;
memset(&v, 0, sizeof(v));
memcpy(v.address, address, CARTESI_ROLLUP_ADDRESS_SIZE);
memcpy(v.destination, destination, CARTESI_ROLLUP_ADDRESS_SIZE);
v.payload = *bytes;
int res = ioctl(fd, IOCTL_ROLLUP_WRITE_VOUCHER, (unsigned long) &v);
if (res != 0) {
Expand Down
2 changes: 1 addition & 1 deletion linux/rollup/http/rollup-http-server/src/rollup/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int rollup_finish_request(int fd, struct rollup_finish *finish, bool accept);
int rollup_read_advance_state_request(int fd, struct rollup_finish *finish, struct rollup_bytes *bytes, struct rollup_input_metadata *metadata);
int rollup_read_inspect_state_request(int fd, struct rollup_finish *finish, struct rollup_bytes *query);
int rollup_write_voucher(int fd, uint8_t address[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes, uint64_t* voucher_index);
int rollup_write_voucher(int fd, uint8_t destination[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes, uint64_t* voucher_index);
int rollup_write_notice(int fd, struct rollup_bytes *bytes, uint64_t* notice_index);
int rollup_write_report(int fd, struct rollup_bytes *bytes);
int rollup_throw_exception(int fd, struct rollup_bytes *bytes);
8 changes: 4 additions & 4 deletions linux/rollup/http/rollup-http-server/src/rollup/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn bindgen_test_layout_rollup_finish() {
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct rollup_voucher {
pub address: [u8; 20usize],
pub destination: [u8; 20usize],
pub payload: rollup_bytes,
pub index: u64,
}
Expand All @@ -271,13 +271,13 @@ fn bindgen_test_layout_rollup_voucher() {
concat!("Alignment of ", stringify!(rollup_voucher))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<rollup_voucher>())).address as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rollup_voucher>())).destination as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(rollup_voucher),
"::",
stringify!(address)
stringify!(destination)
)
);
assert_eq!(
Expand Down Expand Up @@ -391,7 +391,7 @@ extern "C" {

pub fn rollup_write_voucher(
fd: ::std::os::raw::c_int,
address: *mut u8,
destination: *mut u8,
bytes: *mut rollup_bytes,
voucher_index: *mut u64,
) -> ::std::os::raw::c_int;
Expand Down
8 changes: 4 additions & 4 deletions linux/rollup/http/rollup-http-server/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct Notice {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Voucher {
pub address: String,
pub destination: String,
pub payload: String,
}

Expand Down Expand Up @@ -322,7 +322,7 @@ pub fn rollup_write_voucher(
length: binary_payload.len() as u64,
});

let mut address_c = match hex::decode(&voucher.address[2..]) {
let mut address_c = match hex::decode(&voucher.destination[2..]) {
Ok(res) => res,
Err(e) => {
return Err(Box::new(RollupError::new(&format!(
Expand Down Expand Up @@ -533,8 +533,8 @@ pub fn print_notice(notice: &Notice) {

pub fn print_voucher(voucher: &Voucher) {
let mut voucher_request_printout = String::new();
voucher_request_printout.push_str("voucher: {{ address: ");
format_address_printout(&voucher.address, &mut voucher_request_printout);
voucher_request_printout.push_str("voucher: {{ destination: ");
format_address_printout(&voucher.destination, &mut voucher_request_printout);
voucher_request_printout.push_str(&format!(
" length: {} payload: {} }}",
voucher.payload.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ async fn test_write_voucher(
let context = context_future.await;
println!("Writing voucher");
let test_voucher_01 = Voucher {
address: "0x1111111111111111111111111111111111111111".to_string(),
destination: "0x1111111111111111111111111111111111111111".to_string(),
payload: "0x".to_string() + &hex::encode("voucher test payload 01"),
};
let test_voucher_02 = Voucher {
address: "0x2222222222222222222222222222222222222222".to_string(),
destination: "0x2222222222222222222222222222222222222222".to_string(),
payload: "0x".to_string() + &hex::encode("voucher test payload 02"),
};
rollup_http_client::client::send_voucher(&context.address, test_voucher_01).await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ int rollup_read_inspect_state_request(int fd, struct rollup_finish *finish, stru
/* Outputs a new voucher to a file test_voucher_xx.txt in a text file
* voucher_index is filled with new index from the driver
* Returns 0 on success, -1 on error */
int rollup_write_voucher(int fd, uint8_t address[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes,
int rollup_write_voucher(int fd, uint8_t destination[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes,
uint64_t *voucher_index) {
char filename[32] = {0};
char address_c[CARTESI_ROLLUP_ADDRESS_SIZE + 1] = {0};
char destination_c[CARTESI_ROLLUP_ADDRESS_SIZE + 1] = {0};
voucher_index_counter = voucher_index_counter + 1;
sprintf(filename, "test_voucher_%d.txt", voucher_index_counter);
FILE *f = fopen(filename, "w");
if (f == NULL) {
return -1;
}
memcpy(address_c, address, CARTESI_ROLLUP_ADDRESS_SIZE);
memcpy(destination_c, destination, CARTESI_ROLLUP_ADDRESS_SIZE);
fprintf(f, "index: %d, payload_size: %d, payload: ", voucher_index_counter, bytes->length);
for (int i = 0; i < bytes->length; i++) {
fputc(bytes->data[i], f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct rollup_finish {
};

struct rollup_voucher {
uint8_t address[CARTESI_ROLLUP_ADDRESS_SIZE];
uint8_t destination[CARTESI_ROLLUP_ADDRESS_SIZE];
struct rollup_bytes payload;
uint64_t index;
};
Expand Down Expand Up @@ -136,4 +136,4 @@ int rollup_read_inspect_state_request(int fd, struct rollup_finish *finish, stru
int rollup_write_voucher(int fd, uint8_t address[CARTESI_ROLLUP_ADDRESS_SIZE], struct rollup_bytes *bytes, uint64_t* voucher_index);
int rollup_write_notice(int fd, struct rollup_bytes *bytes, uint64_t* notice_index);
int rollup_write_report(int fd, struct rollup_bytes *bytes);
int rollup_throw_exception(int fd, struct rollup_bytes *bytes);
int rollup_throw_exception(int fd, struct rollup_bytes *bytes);
8 changes: 4 additions & 4 deletions linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ static int write_notices(int fd, unsigned count, struct rollup_bytes *bytes, uns
return 0;
}

static int write_vouchers(int fd, unsigned count, struct rollup_bytes *bytes, uint8_t *address, unsigned verbose) {
static int write_vouchers(int fd, unsigned count, struct rollup_bytes *bytes, uint8_t *destination, unsigned verbose) {
struct rollup_voucher v;
memset(&v, 0, sizeof(v));
v.payload = *bytes;
memcpy(v.address, address, sizeof(v.address));
memcpy(v.destination, destination, sizeof(v.destination));
for (unsigned i = 0; i < count; i++) {
int res = ioctl(fd, IOCTL_ROLLUP_WRITE_VOUCHER, (unsigned long) &v);
if (res != 0) {
Expand Down Expand Up @@ -352,9 +352,9 @@ static void show_voucher(struct rollup_voucher *voucher) {
printf("voucher:\n"
"\tindex: %lu\n"
"\tlength: %lu\n"
"\taddress: ",
"\tdestination: ",
voucher->index, voucher->payload.length);
print_address(voucher->address);
print_address(voucher->destination);
}

static void show_notice(struct rollup_notice *notice) {
Expand Down
8 changes: 4 additions & 4 deletions linux/rollup/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ R"(Usage:
voucher
emit a voucher read from stdin as a JSON object in the format
{"address": <address>, "payload": <string>}
where field "address" contains a 20-byte EVM address in hex.
{"destination": <address>, "payload": <string>}
where field "destination" contains a 20-byte EVM address in hex.
if successful, prints to stdout a JSON object in the format
{"index": <number> }
where field "index" is the index allocated for the voucher
Expand Down Expand Up @@ -234,8 +234,8 @@ static int write_voucher(void) try {
memset(&v, 0, sizeof(v));
v.payload.data = reinterpret_cast<unsigned char *>(payload.data());
v.payload.length = payload.size();
auto address = unhex(ji["address"].get<std::string>());
memcpy(v.address, address.data(), std::min(address.size(), sizeof(v.address)));
auto destination = unhex(ji["destination"].get<std::string>());
memcpy(v.destination, destination.data(), std::min(destination.size(), sizeof(v.destination)));
file_desc_ioctl(unique_open(ROLLUP_DEVICE_NAME, O_RDWR), IOCTL_ROLLUP_WRITE_VOUCHER, &v);
nlohmann::json jo = {
{"index", v.index},
Expand Down

0 comments on commit de475c6

Please sign in to comment.