-
Notifications
You must be signed in to change notification settings - Fork 456
Assign and verify transaction fees in Transactions domain - Closes #3860 #3893
Conversation
f880031
to
97e2344
Compare
97e2344
to
c5f704f
Compare
…ture based on number of present keys
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.
Looks good. Just small suggestions.
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.
lgtm!
…it can be overriden by transaction
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.
Looks good, minor comments
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.
@pablitovicente Every thing seems good, but have some observation on the mechanism to validate the fee.
- Validating
this.fee
is exactly like validating any other attributes of transaction - So we don't need to create different validate functions for every other attribute
- To simplify for user there must be one and only one
validate
function for a transaction. We already have an issue open to simply and reduce the interfaces inBaseTransaction
, so don't tend to create more.
So what I would suggest:
- Move the logic of
validateFee
into thevalidate
of theBaseTransaction
- So actually instead of calling the validateFee, have that fee validation logic right there. Because its already validating all other attributes of transaction.
- For multi-signature transaction you should override the actual
validate
method and add your extended validation in it.
@MaciejBaj As discussed earlier as well, we need to keep the transaction interface simple and minimal. I would suggest not to introduce such new methods unless there is no other way to handle the scenario.
@nazarhussain I was the one who suggested @pablitovicente to use a new |
@pablitovicente As just discussed if there is technical limitations of calling |
Created #3912 to discuss this further @nazarhussain please review again. |
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.
@pablitovicente I tried out the analogy and found that you can access the static
attributes of child class
in the base class
. So the argument of not calling super.validate
to extend a validation seems not valid any more.
Here is a working example.
class BaseTransaction {
public fee:number;
public constructor(fee:number) {
this.fee = fee;
}
public validate() {
console.log(`${this.getStaticAttribute('name')} (${this.getStaticAttribute('TYPE')})`);
console.log('Transaction static fee: ', this.getStaticAttribute('FEE'));
console.log('Transaction fee: ', this.fee);
return this.fee === this.getStaticAttribute('FEE');
}
private getStaticAttribute(attr:string):any {
return (this.constructor as any)[attr];
}
}
class MyTransaction extends BaseTransaction{
static TYPE:string = '1';
static FEE:number = 123;
}
class MySecondTransaction extends MyTransaction{
static TYPE:string = '2';
static FEE:number = 456;
public validate() {
return super.validate();
}
}
const a = new MyTransaction(123);
console.log(a.validate());
const b = new MySecondTransaction(456);
console.log(b.validate());
const c = new MySecondTransaction(568);
console.log(c.validate());
And output of above code is:
TypeScript v3.3.3 linux/amd64
MyTransaction (1)
Transaction static fee: 123
Transaction fee: 123
true
MySecondTransaction (2)
Transaction static fee: 456
Transaction fee: 456
true
MySecondTransaction (2)
Transaction static fee: 456
Transaction fee: 568
false
So that example suggest we can go with single validate
method to handle all cases. Please refactor accordingly.
|
@nazarhussain can you please expand your example with the case of Multi-signatures where the fee is not static? |
@pablitovicente Original analogy was that since we can't access child But if the reasoning to have validateFee a separate method is to get dynamic fee based on transaction data rather the statically defined fee (current multi signature case), then whole situation changes. With that reference in mind, I would suggest following solutions.
The original issue refers to the following two points:
Both of these requirements can be achieved in above mentioned directions, defining fee as static value is not a hard-core requirement of the issue itself. Keeping the near future in mind having a static fee value is also no feasible. As for dynamic fee system we always have to calculate the fee. So the second direction would make more sense here. |
@nazarhussain the main issue here is Multisig is the only exception currently that need work arounds. I think I understand your suggestion but the original issue states "Transaction fees should be assignable as part of created transactions extending BaseTransaction interface, e.g. by creating a new @MaciejBaj @shuse2 @nazarhussain what you think about moving further refactoring to a separate issue where we can discuss further about general lisk-transaction architecture as is being proposed in this issue? |
|
But |
I agree! Eventually, we would aim for introducing the calculation of the fees based on the fee per byte -> not on other transaction properties as multisignature does. My suggestion would be to bring this assumption further and make multisignature overriding the |
As far there is no extra interface introduced in |
Not having the method forces us to use an @shuse2 @nazarhussain @lsilvs thoughts ? |
I still think having |
We discussed to continue conversation about the validation design for transactions in #3912 currently |
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.
After discussion we agreed that in coming release we will add validate methods for individual attributes e.g. validateId
, validateSignature
Or we will remove validateFee
and only keep the standard validate
method.
What was the problem?
Fee as not a property that could be defined in the transaction
How did I fix it?
FEE
How to test it?
Build should be green
Review checklist