mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 22:43:47 +00:00
fix: free rust traces that never make it to CCC (#844)
This commit is contained in:
parent
c00352023b
commit
aafca83598
6 changed files with 31 additions and 3 deletions
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 4 // Minor version component of the current release
|
VersionMinor = 4 // Minor version component of the current release
|
||||||
VersionPatch = 6 // Patch version component of the current release
|
VersionPatch = 7 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -223,3 +223,7 @@ func MakeRustTrace(trace *types.BlockTrace, buffer *bytes.Buffer) unsafe.Pointer
|
||||||
|
|
||||||
return C.parse_json_to_rust_trace(tracesStr)
|
return C.parse_json_to_rust_trace(tracesStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FreeRustTrace(ptr unsafe.Pointer) {
|
||||||
|
C.free_rust_trace(ptr)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,5 @@ char* apply_block(uint64_t id, void* block_trace);
|
||||||
char* get_tx_num(uint64_t id);
|
char* get_tx_num(uint64_t id);
|
||||||
char* set_light_mode(uint64_t id, bool light_mode);
|
char* set_light_mode(uint64_t id, bool light_mode);
|
||||||
void free_c_chars(char* ptr);
|
void free_c_chars(char* ptr);
|
||||||
void* parse_json_to_rust_trace(char* trace_json_ptr);
|
void* parse_json_to_rust_trace(char* trace_json_ptr);
|
||||||
|
void free_rust_trace(void* trace_ptr);
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,7 @@ pub mod utils {
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
|
use prover::BlockTrace;
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
@ -283,6 +284,13 @@ pub mod utils {
|
||||||
let _ = CString::from_raw(ptr);
|
let _ = CString::from_raw(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn free_rust_trace(trace_ptr: *mut BlockTrace) {
|
||||||
|
let _ = Box::from_raw(trace_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn c_char_to_str(c: *const c_char) -> Result<&'static str, Utf8Error> {
|
pub(crate) fn c_char_to_str(c: *const c_char) -> Result<&'static str, Utf8Error> {
|
||||||
let cstr = unsafe { CStr::from_ptr(c) };
|
let cstr = unsafe { CStr::from_ptr(c) };
|
||||||
|
|
|
||||||
|
|
@ -96,3 +96,6 @@ func MakeRustTrace(trace *types.BlockTrace, buffer *bytes.Buffer) unsafe.Pointer
|
||||||
goTraces[unsafe.Pointer(rustTrace)] = trace
|
goTraces[unsafe.Pointer(rustTrace)] = trace
|
||||||
return unsafe.Pointer(rustTrace)
|
return unsafe.Pointer(rustTrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FreeRustTrace(ptr unsafe.Pointer) {
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,10 @@ func (p *Pipeline) encodeStage(traces <-chan *BlockCandidate) <-chan *BlockCandi
|
||||||
encodeTimer.UpdateSince(encodeStart)
|
encodeTimer.UpdateSince(encodeStart)
|
||||||
|
|
||||||
stallStart := time.Now()
|
stallStart := time.Now()
|
||||||
sendCancellable(downstreamCh, trace, p.ctx.Done())
|
if sendCancellable(downstreamCh, trace, p.ctx.Done()) {
|
||||||
|
// failed to send the trace downstream, free it here.
|
||||||
|
circuitcapacitychecker.FreeRustTrace(trace.RustTrace)
|
||||||
|
}
|
||||||
encodeStallTimer.UpdateSince(stallStart)
|
encodeStallTimer.UpdateSince(stallStart)
|
||||||
case <-p.ctx.Done():
|
case <-p.ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
@ -395,6 +398,15 @@ func (p *Pipeline) cccStage(candidates <-chan *BlockCandidate, deadline time.Tim
|
||||||
close(resultCh)
|
close(resultCh)
|
||||||
deadlineTimer.Stop()
|
deadlineTimer.Stop()
|
||||||
lifetimeTimer.UpdateSince(p.start)
|
lifetimeTimer.UpdateSince(p.start)
|
||||||
|
// consume candidates and free all rust traces
|
||||||
|
for candidate := range candidates {
|
||||||
|
if candidate == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if candidate.RustTrace != nil {
|
||||||
|
circuitcapacitychecker.FreeRustTrace(candidate.RustTrace)
|
||||||
|
}
|
||||||
|
}
|
||||||
p.wg.Done()
|
p.wg.Done()
|
||||||
}()
|
}()
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue