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