Commit c87d94bb authored by clabby's avatar clabby

@inphi nits

Co-Authored-By: default avatarinphi <mlaw2501@gmail.com>
parent 679eb237
......@@ -62,7 +62,7 @@ type Config struct {
Cancel context.CancelCauseFunc
// [OPTIONAL] The reth DB path to read receipts from
RethDBPath *string
RethDBPath string
}
type RPCConfig struct {
......
......@@ -71,11 +71,6 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
haltOption = ""
}
var rethDBPath *string
if rdb := ctx.String(flags.L1RethDBPath.Name); rdb != "" {
rethDBPath = &rdb
}
cfg := &node.Config{
L1: l1Endpoint,
L2: l2Endpoint,
......@@ -109,7 +104,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
ConfigPersistence: configPersistence,
Sync: *syncConfig,
RollupHalt: haltOption,
RethDBPath: rethDBPath,
RethDBPath: ctx.String(flags.L1RethDBPath.Name),
}
if err := cfg.LoadPersisted(log); err != nil {
......
......@@ -67,7 +67,7 @@ typedef struct ReceiptsResult {
* - All possible nil pointer dereferences are checked, and the function will return a
* failing [ReceiptsResult] if any are found.
*/
struct ReceiptsResult read_receipts(const uint8_t *block_hash,
struct ReceiptsResult rdb_read_receipts(const uint8_t *block_hash,
uintptr_t block_hash_len,
const char *db_path);
......@@ -77,7 +77,7 @@ struct ReceiptsResult read_receipts(const uint8_t *block_hash,
* # Safety
* - All possible nil pointer dereferences are checked.
*/
void free_string(char *string);
void rdb_free_string(char *string);
```
[rust-toolchain]: https://rustup.rs/
......@@ -11,7 +11,7 @@ mod receipts;
/// - All possible nil pointer dereferences are checked, and the function will return a
/// failing [ReceiptsResult] if any are found.
#[no_mangle]
pub unsafe extern "C" fn read_receipts(
pub unsafe extern "C" fn rdb_read_receipts(
block_hash: *const u8,
block_hash_len: usize,
db_path: *const c_char,
......@@ -24,7 +24,7 @@ pub unsafe extern "C" fn read_receipts(
/// # Safety
/// - All possible nil pointer dereferences are checked.
#[no_mangle]
pub unsafe extern "C" fn free_string(string: *mut c_char) {
pub unsafe extern "C" fn rdb_free_string(string: *mut c_char) {
// Convert the raw pointer back to a CString and let it go out of scope,
// which will deallocate the memory.
if !string.is_null() {
......
......@@ -64,7 +64,7 @@ type EthClientConfig struct {
MethodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
RethDBPath *string
RethDBPath string
}
func (c *EthClientConfig) Check() error {
......@@ -137,7 +137,7 @@ type EthClient struct {
methodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
rethDbPath *string
rethDbPath string
}
func (s *EthClient) PickReceiptsMethod(txCount uint64) ReceiptsFetchingMethod {
......
......@@ -390,13 +390,13 @@ type receiptsFetchingJob struct {
fetcher *IterativeBatchCall[common.Hash, *types.Receipt]
// [OPTIONAL] RethDB path to fetch receipts from
rethDbPath *string
rethDbPath string
result types.Receipts
}
func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBatchSize int, block eth.BlockID,
receiptHash common.Hash, txHashes []common.Hash, rethDb *string) *receiptsFetchingJob {
receiptHash common.Hash, txHashes []common.Hash, rethDb string) *receiptsFetchingJob {
return &receiptsFetchingJob{
requester: requester,
client: client,
......@@ -483,10 +483,10 @@ func (job *receiptsFetchingJob) runAltMethod(ctx context.Context, m ReceiptsFetc
case ErigonGetBlockReceiptsByBlockHash:
err = job.client.CallContext(ctx, &result, "erigon_getBlockReceiptsByBlockHash", job.block.Hash)
case RethGetBlockReceipts:
if job.rethDbPath == nil {
if job.rethDbPath == "" {
return fmt.Errorf("reth_db path not set")
}
res, err := FetchRethReceipts(*job.rethDbPath, &job.block.Hash)
res, err := FetchRethReceipts(job.rethDbPath, &job.block.Hash)
if err != nil {
return err
}
......
......@@ -24,8 +24,8 @@ typedef struct {
bool error;
} ReceiptsResult;
extern ReceiptsResult read_receipts(const uint8_t* block_hash, size_t block_hash_len, const char* db_path);
extern void free_string(char* string);
extern ReceiptsResult rdb_read_receipts(const uint8_t* block_hash, size_t block_hash_len, const char* db_path);
extern void rdb_free_string(char* string);
*/
import "C"
......@@ -45,12 +45,15 @@ func FetchRethReceipts(dbPath string, blockHash *common.Hash) (types.Receipts, e
defer C.free(unsafe.Pointer(cDbPath))
// Call the C function to fetch the receipts from the Reth Database
receiptsResult := C.read_receipts((*C.uint8_t)(cBlockHash), C.size_t(len(blockHash)), cDbPath)
receiptsResult := C.rdb_read_receipts((*C.uint8_t)(cBlockHash), C.size_t(len(blockHash)), cDbPath)
if receiptsResult.error {
return nil, fmt.Errorf("Error fetching receipts from Reth Database.")
}
// Free the memory allocated by the C code
defer C.rdb_free_string(receiptsResult.data)
// Convert the returned JSON string to Go string and parse it
receiptsJSON := C.GoStringN(receiptsResult.data, C.int(receiptsResult.data_len))
var receipts types.Receipts
......@@ -58,8 +61,5 @@ func FetchRethReceipts(dbPath string, blockHash *common.Hash) (types.Receipts, e
return nil, err
}
// Free the memory allocated by the C code
C.free_string(receiptsResult.data)
return receipts, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment