Skip to content

Commit

Permalink
fix occasional crash (#99)
Browse files Browse the repository at this point in the history
* fix occasional crash
* Update near.go
* fix build
  • Loading branch information
iavl authored Apr 18, 2024
1 parent ad8488f commit 8daf926
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gopkg/da-rpc/near.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@ func (config *Config) Submit(candidateHex string, data []byte) ([]byte, error) {
defer C.free(unsafe.Pointer(txBytes))

maybeFrameRef := C.submit_batch(config.Client, candidateHexPtr, (*C.uint8_t)(txBytes), C.size_t(len(data)))

err := GetDAError()
if err != nil {
return nil, err
}

log.Info("Submitting to NEAR",
"maybeFrameData", maybeFrameRef,
"candidate", candidateHex,
"namespace", config.Namespace,
"txLen", C.size_t(len(data)),
)
err := GetDAError()
if err != nil {
return nil, err
}


if maybeFrameRef.len > 1 {
// Set the tx data to a frame reference
frameData := C.GoBytes(unsafe.Pointer(maybeFrameRef.data), C.int(maybeFrameRef.len))
Expand Down Expand Up @@ -245,11 +247,18 @@ func To32Bytes(ptr unsafe.Pointer) []byte {
return bytes
}

func GetDAError() error {
func GetDAError() (err error) {
defer func() {
if rErr := recover(); rErr != nil {
err = fmt.Errorf("critical error from NEAR DA GetDAError: %v", rErr)
}
}()

errData := C.get_error()
defer C.free(unsafe.Pointer(errData))

if errData != nil {
defer C.free(unsafe.Pointer(errData))

errStr := C.GoString(errData)
return fmt.Errorf("NEAR DA client %s", errStr)
} else {
Expand Down

0 comments on commit 8daf926

Please sign in to comment.