-
Notifications
You must be signed in to change notification settings - Fork 809
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 spvnode.sendTX() and spvnode.relay() #417
base: master
Are you sure you want to change the base?
Conversation
900da26
to
a54dd34
Compare
b3d9585
to
c63e666
Compare
c63e666
to
50badc1
Compare
All done |
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.
Tested OK.
Earlier a transaction relayed by us was only added to the filter if a peer relayed it back.
Sidenote: this cannot be easily tested without being able to configure wallet port (see #418)
What's the reasoning for no longer returning promises? |
Nope, I thought It would break the API. then you need to add |
When it returned Promise, it would work with other |
50badc1
to
6640b15
Compare
Done |
} | ||
|
||
/** | ||
* Broadcast a transaction. Silence errors. | ||
* @param {TX} tx | ||
* @returns {Promise} |
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.
you still need this returns in both methods.
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.
I can do it, but won't this make the spv node have a different API from the full node? Is there a reason for this difference?
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.
fullnode lacks this line in docs. Every async
method returns Promise
.
6640b15
to
2875f06
Compare
Now it should be ok? |
4fd1cd2
to
e426e43
Compare
This note contained some provisional bug fixes made to bcoin/lib/node/spvnode.js, along with the suggestions by the bcoin devs on how to correctly fix those bugs. Since PR bcoin-org/bcoin#417 has been published, this note is redundant.
The fullnode |
@braydonf maybe this comment is more relevant in #420, since the fullnode This is intentional. When As you said, the resolution of |
Right, so there is an |
You're referring to this: Line 284 in f00ed98
|
Yep, and the same exists in spvnode.js |
@nodar-chkuaselidze Can we merge either this or #697? Also #681 is ready and we need them for our application. |
* @param {TX} tx | ||
* @returns {Promise} | ||
*/ | ||
|
||
sendTX(tx) { | ||
return this.broadcast(tx); | ||
async sendTX(tx) { |
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.
To protect users from getting banned by sending an invalid tx, would it make sense to first check tx.verify()
before anything else?
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.
Fixed following the full node example:
Lines 785 to 788 in f585d86
const [valid, reason, score] = tx.checkSanity(); | |
if (!valid) | |
throw new VerifyError(tx, 'invalid', reason, score); |
Lines 297 to 303 in f585d86
} catch (err) { | |
if (err.type === 'VerifyError' && err.score === 0) { | |
this.error(err); | |
this.logger.warning('Verification failed for tx: %h.', tx.hash()); | |
this.logger.warning('Attempting to broadcast anyway...'); | |
this.broadcast(tx); | |
return; |
e426e43
to
ab5f9cb
Compare
75a5e7c
to
1f65e4a
Compare
Codecov Report
@@ Coverage Diff @@
## master #417 +/- ##
==========================================
- Coverage 61.94% 19.7% -42.25%
==========================================
Files 156 155 -1
Lines 26084 26071 -13
==========================================
- Hits 16157 5136 -11021
- Misses 9927 20935 +11008
Continue to review full report at Codecov.
|
Also rebased and added tests for TX emission |
@pinheadmz Can you clarify what changes you propose in this comment? |
Ok so since #631 has come up again, I gave this PR another review and I think it is a good solution to a long-standing issue. I rebased on master here: https://github.com/pinheadmz/bcoin/commits/spv-send-relay-2 and fixed a few typos (rename test to
Results:On |
a94d6d1
to
161d76d
Compare
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 for your work on this, @OrfeasLitos and your patience in review!
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.
Tested OK. Fixed minor nits.
@OrfeasLitos only minor nit. Please use standard commit messages e.g:
Apologies for having this linger for so long. |
Also, either squash the commits or move |
Co-authored-by: Christopher Jeffrey <chjjeffrey@gmail.com>
The definitions of these two functions were not implemented previously, they both just called this.broadcast(). Now sendTX() broadcasts only if it wouldn't hurt its score and emits the tx only if it is watched; relay() calls sendTX() and silences errors, just like for the full node.
161d76d
to
431cfc4
Compare
431cfc4
to
518be85
Compare
The definitions of these two functions were not implemented previously, they both just called this.broadcast(). Now sendTX() adds the tx to the txFilter of the pool and emits the tx; relay() calls sendTX() and silences errors, just like for the full node.