-
Notifications
You must be signed in to change notification settings - Fork 415
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
Gas prediction implementation #514
Conversation
This reverts commit f48066b.
Method predict `Transaction.gasPrice` value.
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.
Almost all of these corrections are simple typos in the comments. I know English is not your first language, so these are not meant as a comment you or your abilities. Otherwise the code looks good so far, with only minor suggestion.
Not sure what you mean by this. Legacy transactions (and EIP-2930) only have If this function is only for getting |
case .maximum: | ||
// Checking that suggestedBaseFee are not lower than will be in the next block | ||
// because in tne maximum statistic we should guarantee that transaction would be included in it. | ||
return max(calcBaseFee(for: latestBlock), noAnomalyArray.max()!) |
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.
we should not use force unwrap
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.
Please pay attention that at line 51 its explicitly checks that array is not empty, therefore it's acceptable to use forse unwrap, since each function beyond returns nil only if arrays is empty.
|
||
extension Array { | ||
func cropAnomalyValues() -> Self { | ||
var tmpArr = self.dropFirst() |
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.
what makes the first and last values anomalous?
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 statistics the extreme outliers in a set are often looked at to be deviations from the norm, or anomalies. So by clipping them off, you can often get a more meaningful result. In this case the list is sorted,so first and last entries would contain the extreme outliers.
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're right about not enough encapsulation here. I've include sorting to this method
I still insist that on after London transactions should be used |
6ffc9e4
to
b069ed5
Compare
Except, not all chains are post-london. and not all transactions post-london are EIP-1559. My point is that code for a non-EIP-1159 transaction should be able to call
|
I read this two paragraph as contradicting each other, and i'm struggling to get your point. Let me explain my view more structured. My assumptions:
So if this is true, we'll have follow Oracle methods results matrix:
So as shown above in the fourth row, So as i see we're talking about doc comment to the legacy method, where i mention to a method user, that he should not use it in EIP-1559 blocks, since it'll be error prone, coz this method would return some valid values, but that values are useless within EIP-1559 transaction/block environment. I see your point as give user possibility to call |
Your table clears things up, and is the desired mode I have been asking for. However it goes against the mention of "Should be used only on pre EIP-1559 blocks." comment in your PR description that started this conversation. That mention suggests that the And to be clear, I was never suggesting that someone would use |
They are not contradictory. Perhaps you think that everything after the London fork is EIP-1159? If so that is not the case. The London fork only adds new transaction types, it does not remove or disallow the other types.
Pre-London we can only create legacy transactions. Post London we can create EIP-1159, EIP-2930, and legacy transactions. With only EIP-1159 using the new fee structure |
Perhaps true at the |
Now i see, so i'll change that comment than, to not use that method on transaction instead of block. |
- Add method `decodeHex` for `Arrays<T> where T: DecodableFromHex`. - Add feeHistory request. - Add public feeHistory API call - Move GasOracle from `Web3` scope to `web3.Eth` scope (watch out case of first "w") - Change Oracle struct to work with feeHistory API call. - Refactor `JSONRPCmethod` to make it more explicit. - Refactor `InfuraWebsockerMethod` with a styling.
- Rename decodeHex method to swift name convention. - Add FeeHistory struct initializer.
- Now it works with feeHistory JRON RPC Ethereum call - Now all method returns percentiles, which user set on object init.
- Implement generic decodeHex methods for T: DecodableFromHex, [T], [[T]]. - Make RPC API `feeHistory` call internal. - Reimplement `tipFeePercentiles` to return array of percentiles of last tips. - Reimplement `baseFeePercentiles` to return array of percentiles of last baseFee. - Rename `bothFeesPercentiles` to return tuple of arrays of percentiles of last both tips and baseFee. - `JSONRPCresponse` now can decode `Web3.Oracle.FeeHistory` - `JSONRPCparams` now can encode `[Double]` - Add `OracleTests` - `testPretictBaseFee` - `testPredictTip`
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.
Just some comments on the changes in Decodable (and by extension Encodable). I think those changes are best left to a separate PR, as they are not specifically needed to implement gasPrediction.
guard contains(key), | ||
try decodeNil(forKey: key) == false else { return nil } | ||
return try decode(type, forKey: key) | ||
/// - Parameter type: Array of a generic type `T` wich conforms to `DecodableFromHex` protocol |
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.
By removing the 'xxxIfPResent' variants you have removed the ability to distinguish between when an allowed optional was encountered, and when an actual decoding error occurred.
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.
Will it affect you that Array<Any>
comes to [T] where T: HexDecodable
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.
That should be fine. This comment was more about the xxxIfPresent
variants being removed, than this one specific case.
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 mean that they will have such types either. But anyway i've realized that changing type of any of these public methods are going against versioning rules, so i'll bring them back, but mark as deprecated (including xxxIfPresent
with Array<Any>
types), and my PR will just include new generic methods here, and some light refactoring in JSON RPC encoder enums
- Add `BlockNumber` enum to enable strong typing in block number management. - Full test coverage of GasOracle public methods. - Clean GasOracle class.
e3ec605
to
c584da6
Compare
Gas prediction
This PR implements base functionality of gas prediction.
What is it
The prediction calculates given percentiles (e.g. percent of how value is high against all dataset values) of a last n blocks data.
How to use it
It brings
Oracle
object that is encapsulating all prediction methods. To use it you need to create Oracle object as shown bellow:API
Oracle
object provides setup API are followAfter creation you’ll be able to get its prediction based on its settings. Also
Oracle
object have follow property to be setup within its lifecycle:block
: Block to start getting history backwardblockCount
: Count of blocks to include in datasetpercentiles
: Sets values by which dataset would be sliced.Oracle
object provides prediction API are followbaseFeePercentiles: [BigUInt]
- Soften baseFee amount.tipFeePercentiles: [BigUInt]
- Tip amount.bothFeesPercentiles: (baseFee: [BigUInt], tip: [BigUInt])?
- Summary fees amount.gasPriceLegacyPercentiles: [BigUInt]
- Legacy gasPrice amount.