-
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
feat: Implement C-GO interface of dcurl #228
Conversation
hashedTrytes := curl.MustHashTrytes(rawTx) | ||
|
||
t.Log("hashed Trytes:", hashedTrytes) | ||
if guards.IsTransactionHashWithMWM(hashedTrytes, 10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be 14, which is mwm
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Use the mwm variable with casting instead of an exact number now.
t.Log("Correctly hash with mwm") | ||
} else { | ||
t.Error("Wrong hash trytes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unify the log and error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Use "Correct hash with mwm" and "Wrong hash with mwm" now.
Fix commit message:
|
t.Log("Testing an 8 threads dcurl pow with 14 as mwm") | ||
nonce, err := DcurlProofOfWork(rawTx, mwm, 8) | ||
if err == nil { | ||
t.Log("dcurl PoW successed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
succeeded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated!
rawTx := "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999A9RGRKVGWMWMKOLVMDFWJUHNUNYWZTJADGGPZGXNLERLXYWJE9WQHWWBMCPZMVVMJUMWWBLZLNMLDCGDJ999999999999999999999999999999999999999999999999999999YGYQIVD99999999999999999999TXEFLKNPJRBYZPORHZU9CEMFIFVVQBUSTDGSJCZMBTZCDTTJVUFPTCCVHHORPMGCURKTH9VGJIXUQJVHK999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" | ||
|
||
mwm := 14 | ||
t.Log("Testing an 8 threads dcurl pow with 14 as mwm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to Use dcurl to calculate PoW with 8 threads enabled and MWM = 14
|
||
t.Log("hashed Trytes:", hashedTrytes) | ||
if guards.IsTransactionHashWithMWM(hashedTrytes, uint(mwm)) { | ||
t.Log("Correct hash wih mwm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with
"github.com/iotaledger/iota.go/guards" | ||
) | ||
|
||
func TestDcrulProofOfWork(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestDcurlProofOfWork
Can we use the directory name |
If possible, I prefer |
It could be dcurl/cgo/pow or dcurl/go/pow. The only thing invariant is the pow package should be consistent with its folder name. |
Let's move forward to |
These API are based on dynamic linking. User should always check LD_LIBRARY_PATH and LIBRARY_PATH before using it. The commit provides 2 versions of API for the usage in HORNET, one is implemented with mutex lock. And the result is different from original dcurl, it returns nonce rather than full 2673 trytes.
Here is a test for C-GO interface based on GOlang testing package. The reasons to implement a test in GOlang are format and type. We should be aware of the format difference between HORNET and dcurl, and the transfer between GOlang and C is tricky, too. Hence implement a test in GOlang can make sure it works correctly in these 2 aspect. It'll check with following steps. First, the PoW works with or without errors. Then, the length of nonce should be 27. Hashing will check if nonce is correctly encoded. Last, the hashed trytes should be correct with mwm
GO module is a dependency management system for GO. It makes dependency information explicit and easier to manage.
@@ -0,0 +1,78 @@ | |||
package pow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the filename be revised to cgo/pow/pow_dcurl.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I use pow_dcurl.go
.
Under the module name dcurl.go or github.com/DLTcollab/dcurl/cgo
now,
it should be clear that pow here is using dcurl.
Hence I thought the postfix could be redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In iota.go/pow
, they have different postfix for different pow implementations.
Let's move forward! |
gofmt
Here provides a C-GO interface for dcurl, in format of HORNET.
These API are based on dynamic linking.
We should add the path to
libdcurl.so
to LIBRARY_PATH and LD_LIBRARY_PATH.libdcurl.so
. It'll leads to compiling error for c code in cgo.The solution is add the
path/to/libdcurl.so
to LIBRARY_PATH.When compiling, compiler will find dcurl in LIBRARY_PATH.
Under the path of dcurl:
Cause
libdcurl.so
is in/build
after dcurl being built.Providing 2 versions of API for the usage in HORNET, one is implemented with mutex lock.
And, the result is different from original dcurl, it returns only nonce rather than full 2673 trytes.
The usage is exactly same as api in iota.go/pow.
API usage
parameters
Output
Test package using GO test
This test will test for API
DcurlProofOfWork()
, which simultaneously test core APIDcurlEntry()
.Under the path of dcurl:
Under the path of dcurl/cgo/pow.
Use
-v
for more information.Import dcurl/cgo/pow for other go files
go get
if yourgo files
(one you want to import dcurl/cgo/pow) is not managed by go module.github.com/JulianATA/dcurl/cgo/pow
now.github.com/DLTcollab/dcurl/cgo/pow
main.go
Close #217