Xahau / xahaud

Codebase for Xahaud - The consensus, RPC & blockchain app for the Xahau network.
https://xahau.network
ISC License
22 stars 11 forks source link

`rollback` behavior is wrong in jshook. (Version: 2024.5.24-dev+jshooks) #319

Closed tequdev closed 4 days ago

tequdev commented 1 month ago

rollback behavior seems to be wrong in jshook.

var Hook = (arg) => {
  rollback("rollback", -1);
  accept("accept.", 0);
  return 0;
};

=> accept

#include "hookapi.h"
int64_t hook(uint32_t reserved) {
  rollback(SBUF("rollback"), __LINE__);
  accept(SBUF("accept"), __LINE__);
  _g(1, 1);
  return 0;
}

=> rollback

RichardAH commented 1 month ago

This is caused by rollback/accept not actually exiting (although they do set the exit parameters.) Trying to trace an efficient and clean way to terminate early inside a quickjs CFunction... I think we might make a new quickjs internal exception type and throw it from the rollback and accept functions to unwind the quickjs stack correctly and clean everything up.

RichardAH commented 4 days ago

https://github.com/Xahau/xahaud/commit/e4c6add794550228a9d7fd22181e0539f121fb0d