-
Notifications
You must be signed in to change notification settings - Fork 19
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(sidecar): gross tip revenue metric #339
Conversation
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've not seen the metric added anywhere in the sidecar code, is this PR still draft?
@@ -2,6 +2,9 @@ name: Bolt Sidecar CI | |||
|
|||
on: | |||
push: | |||
branches: | |||
- unstable | |||
- main |
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 main
branch is unused. Any specific reason for adding it?
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 might use it in the future
// If the tip is too large, we need to split it into multiple u64 parts | ||
if tip > u64::MAX as u128 { | ||
let mut parts = Vec::new(); | ||
while tip > u64::MAX as u128 { | ||
parts.push(u64::MAX); | ||
tip -= u64::MAX as u128; | ||
} | ||
|
||
parts.push(tip as u64); | ||
|
||
for part in parts { | ||
counter!(GROSS_TIP_REVENUE).increment(part); | ||
} | ||
} else { | ||
counter!(GROSS_TIP_REVENUE).increment(tip as u64); | ||
} |
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 my opinion this is a bit simpler/succint and doesn't distinguish between edge cases and regular cases which is nice.
// If the tip is too large, we need to split it into multiple u64 parts | |
if tip > u64::MAX as u128 { | |
let mut parts = Vec::new(); | |
while tip > u64::MAX as u128 { | |
parts.push(u64::MAX); | |
tip -= u64::MAX as u128; | |
} | |
parts.push(tip as u64); | |
for part in parts { | |
counter!(GROSS_TIP_REVENUE).increment(part); | |
} | |
} else { | |
counter!(GROSS_TIP_REVENUE).increment(tip as u64); | |
} | |
// Takes also into account tips larger than a u128 by splitting them into u64 parts | |
let mut parts = Vec::new(); | |
let u64_max = u64::MAX as u128; | |
while tip > 0 { | |
// We can only add a max tip of u64::MAX. | |
let min = tip.min(u64_max) as u64; | |
parts.push(min); | |
// Subtract the part we just added, if something is left then tip is going to be | |
// greater than zero. | |
tip = tip.saturating_sub(u64_max) | |
} | |
parts.push(tip as u64); | |
for part in parts { | |
counter!(GROSS_TIP_REVENUE).increment(part); | |
} |
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.
True, but this always does an allocation
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's fair, also because with an u64 you can express a tip up to 18.44 ETH :D
Yes mb, converted |
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!
Closes #245