-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement C-Go interface for HORNET integration #217
Comments
A simple Go program calling the dcurl APIs would look like this: package main
// #cgo LDFLAGS: -L ./build -ldcurl
/*
#include <stdbool.h>
extern bool dcurl_init();
extern bool dcurl_destroy();
*/
import "C"
func main() {
C.dcurl_init()
C.dcurl_destroy()
} To execute the program, we need to specify the LD_LIBRARY_PATH value with the path of |
HORNET is composed with multiple plugins. IMPORTANT:However, the benefit of the integration would be based on the PoW acceleration of FPGA and remote worker mostly. The PoW function of webapi plugin calls the Go client library iota.go. |
How to implement?
|
package main
/*
#cgo LDFLAGS: -L ./build -ldcurl
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
extern bool dcurl_init();
extern bool dcurl_destroy();
extern int8_t *dcurl_entry(int8_t *trytes, int mwm, int threads);
char*dcurl_wrapper(void* trytes, int mwm, int threads ){
return (char*) dcurl_entry((int8_t*) trytes, mwm, threads);
}
*/
import "C"
import (
"fmt"
"sync"
"unsafe"
"github.com/iotaledger/iota.go/curl"
"github.com/iotaledger/iota.go/guards"
. "github.com/iotaledger/iota.go/trinary"
"github.com/pkg/errors"
. "github.com/iotaledger/iota.go/consts"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func init() {
}
func DCURLProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
C.dcurl_init()
defer C.dcurl_destroy()
return dcurlProofOfWork(trytes, mwm, parallelism...)
}
var DCURLProofOfWorkMutex = sync.Mutex{}
func SyncDCURLProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
C.dcurl_init()
defer C.dcurl_destroy()
DCURLProofOfWorkMutex.Lock()
defer DCURLProofOfWorkMutex.Unlock()
nonce, err := dcurlProofOfWork(trytes, mwm, parallelism...)
if err != nil {
return "", err
}
return nonce, nil
}
func dcurlProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
if trytes == "" {
return "", errors.New("invalid trytes supplied to Proof-of-Work func")
}
tr := unsafe.Pointer(&MustTrytesToTrits(trytes)[0])
defer C.free(tr)
var numThread int
if len(parallelism) != 0 && parallelism[0] > 0 {
numThread = parallelism[0]
} else {
numThread = 1
}
result := C.dcurl_wrapper(tr, C.int(mwm), C.int(numThread))
return C.GoString(result), nil
}
func main() {
var _ = Describe("PoWC", func() {
Context("PoWC()", func() {
rawTx := "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999A9RGRKVGWMWMKOLVMDFWJUHNUNYWZTJADGGPZGXNLERLXYWJE9WQHWWBMCPZMVVMJUMWWBLZLNMLDCGDJ999999999999999999999999999999999999999999999999999999YGYQIVD99999999999999999999TXEFLKNPJRBYZPORHZU9CEMFIFVVQBUSTDGSJCZMBTZCDTTJVUFPTCCVHHORPMGCURKTH9VGJIXUQJVHK999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
It("computes a correct nonce", func() {
nonce, err := DCURLProofOfWork(rawTx, 10)
rawTx = rawTx[:len(rawTx)-NonceTrinarySize/3] + nonce
Expect(err).ToNot(HaveOccurred())
hashedTrytes := curl.MustHashTrytes(rawTx)
Expect(guards.IsTransactionHashWithMWM(hashedTrytes, 10)).To(BeTrue())
})
})
})
} This is an update to C-Go interface of dcurl.
It'll be split to 2 part:
|
The test is running correctly on the However, there are several things need to be mentioned.
|
In order to run the testing on
The reasons are:
@JulianaTa please make sure the root privilege problem is recorded in the document. |
HORNET is a lightweight alternative to IOTA's fullnode software IRI written in Go language.
In order to make it use the PoW acceleration of dcurl, the interface between C and Go language should be implemented.
For the interface implementation, please reference: cgo.
The text was updated successfully, but these errors were encountered: