-
Notifications
You must be signed in to change notification settings - Fork 0
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
batch open transaction support on full node #34
Conversation
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin <ridvan@namebase.io>
Pull Request Test Coverage Report for Build 384911669
💛 - Coveralls |
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin <ridvan@namebase.io>
i did struggle a little bit to understand the github flow and dependency management. but here is the main change i have for the batchOpen. I do have postman scripts and completed manual testing. |
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.
Good job with this PR, you got to touch a bunch of different parts of the Handshake wallet. Some overall comments:
- Your .eslinting seems to be different than what this repo wants. Check out the .eslintrc files here. Can ask me if you need help on this, I stopped commenting on deviations after a certain point
- Can you make this PR against
production-namebase
instead ofmaster
? Here's our branching strategy:
namebase | handshake-org
-----------+--------------
master | master
randomx | randomx
production | v2.2.0 // production points to a specific commit of hsd
production-namebase // has no analog in hsd; it has our custom changes
So anything custom we do is on production-namebase
, which is branched off of production
. You will need to rebase this branch off of production-namebase
which might lead to some rebase conflicts
|
||
const options = TransactionOptions.fromValidator(valid); | ||
const {mtx, errors, isAllError} = await req.wallet | ||
.createBatchOpen(names, force, options); |
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.
This indentation does not seem correct, what eslint rules are you using?
@@ -880,7 +880,7 @@ function typeToClass(type) { | |||
function stringToClass(type) { | |||
assert(typeof type === 'string'); | |||
|
|||
if (!hsTypes.hasOwnProperty(type)) | |||
if (!Object.prototype.hasOwnProperty.call(hsTypes, type)) |
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 think we want to avoid directly accessing prototypes, is your eslint config using some global rules defined elsewhere?
FWIW to avoid doing x.hasOwnProperty(y)
, you can do: Object.keys(x).includes(y)
for better safety
@@ -363,7 +363,7 @@ class AirdropKey extends bio.Struct { | |||
fromJSON(json) { | |||
assert(json && typeof json === 'object'); | |||
assert(typeof json.type === 'string'); | |||
assert(keyTypes.hasOwnProperty(json.type)); | |||
assert(Object.prototype.hasOwnProperty.call(keyTypes, json.type)); |
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.
Same comment
const {mtx, errors, isAllError} = await req.wallet | ||
.createBatchOpen(names, force, options); | ||
|
||
if (isAllError) { // no valid output in mtx |
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.
Personally I don't like how hsd
eslint rules want:
if (isAllError)
return res.json(500, { errors: errors });
I think this --^ is very prone to bugs and don't like it, I prefer what you wrote, but, it's the convention in this repo, so could you change this if statement to that format? This should happen automatically with the rest of the eslint fixes in this PR
* @returns {Boolean} | ||
*/ | ||
|
||
async isCovenantDoubleOpen(covenant) { |
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.
Few comments:
- It seems like this is copied from
isDoubleOpen(tx)
, correct? Could you rewriteisDoubleOpen(tx)
so that it uses thisisCovenantDoubleOpen(covenant)
function? - Reading this code actually makes me think that there is a bug with the original
isDoubleOpen
that you copied it from! In the original, wereturn false
from inside the for loop if the duplicate open is from an old auction. But that doesn't mean the whole transaction doesn't have a double open, just that covenant isn't! It shouldcontinue
and notreturn false
.
We can rewrite isDoubleOpen
as something like:
async isDoubleOpen(tx) {
const isDoubleOpenList = await Promise.all(
tx.outputs.map(({ covenant }) => isCovenantDoubleOpen(covenant))
);
// any covenant being a double open means the whole transaction includes a double open
return isDoubleOpenList.some(Boolean);
}
Which fixes the continue
bug.
- Reviewing this code also caused me to review
removeDoubleOpen(tx)
. Handshake used to have a bug that prevented valid double opens (when auction expires).isDoubleOpen
fixed that bug, butremoveDoubleOpen
never did! It seems you're not using thisremoveDoubleOpen
function anyway so no change necessary in this PR, just pointing it out.
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.
removeDoubleOpen will keep it in mind, i am refactoring as you have indicated. I didnt realize the "bug" you mentioned above tough, addressing that one as well.
* @returns {MTX} | ||
*/ | ||
|
||
async makeBatchOpen(names, force, acct) { |
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.
Can you rewrite all the other makeOpen
/createOpen
etc calls so that they are a special case of xxxBatchOpen
? I want to avoid having bug fixes in one not translate to bug fixes in the other. Perhaps something like:
async makeOpen(name, force, acct) {
const { mtx, errors, isAllError } = await makeBatchOpen([name], force, acct);
if (errors.length > 0) {
throw new Error(errors[0].error);
}
return mtx;
}
@@ -1559,6 +1559,87 @@ class Wallet extends EventEmitter { | |||
} | |||
} | |||
|
|||
/** | |||
* Make a batch open MTX. | |||
* @param {Array} names |
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.
Can you replace with string[]
or Array<string>
instead
|
||
for (const name of names) { | ||
if (!rules.verifyName(name)) { | ||
errors.push({name: name, error: 'Invalid name.'}); |
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.
The key error
makes this sound like a typed object, could you call it message
or errorMessage
?
it('should create a batch open transaction (multiple outputs) for valid names', async () => { | ||
// add funds to account, these are necessary to run test individually | ||
// const height = 2; | ||
// await mineBlocks(height, cbAddress); |
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.
Can we remove these comments?
assert.ok(mempool.length === 0); | ||
}); | ||
|
||
it('should reject a batch open transaction (multiple outputs) for invalid names', async () => { |
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.
Great test coverage!
Signed-off-by: rozaydin <ridvan@namebase.io>
Signed-off-by: rozaydin ridvan@namebase.io