Skip to content

Commit 591208c

Browse files
authored
Allowance interface tweaks (#80)
* feat: more allowance features * chore: version and readme * fix: clean up no-default and all-features * fix: docs * feat: cap gas on tx * fix: estimation midpoint * fix: estimation result * feat: misc tracing
1 parent 96605c9 commit 591208c

File tree

8 files changed

+305
-53
lines changed

8 files changed

+305
-53
lines changed

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.19.6"
3+
version = "0.19.7"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]
@@ -37,6 +37,7 @@ revm = { version = "19.5.0", default-features = false, features = ["std"] }
3737
zenith-types = { version = "0.14" }
3838

3939
dashmap = { version = "6.1.0", optional = true }
40+
tracing = "0.1.41"
4041

4142
[dev-dependencies]
4243
alloy-rlp = { version = "0.3", default-features = false }
@@ -55,6 +56,7 @@ tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }
5556

5657
[features]
5758
default = [
59+
"call",
5860
"concurrent-db",
5961
"estimate_gas",
6062
"revm/std",
@@ -64,6 +66,8 @@ default = [
6466
"revm/secp256k1",
6567
]
6668

69+
call = ["optional_eip3607", "optional_no_base_fee"]
70+
6771
concurrent-db = ["dep:dashmap"]
6872

6973
estimate_gas = ["optional_eip3607", "optional_no_base_fee"]

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ Trevm is useful for:
3030

3131
## Note on Trevm Versioning
3232

33-
Trevm generally uses [semantic versioning](https://semver.org/). However, we
34-
also strive to indicate the MAJOR version of revm in the MINOR version of
33+
Trevm generally uses [semantic versioning](https://semver.org/). While pre-1.0,
34+
we also strive to indicate the MAJOR version of revm in the MINOR version of
3535
trevm. For example, trevm `0.19.x` SHOULD BE compatible with revm `19.x.x`. In
3636
general, we will try to maintain compatibility with the latest revm version,
3737
and will not backport trevm fixes to older trevm or revm versions. It is
3838
generally not advised to use old revm versions, as the EVM is a living spec.
3939

40+
In order to maintain this relationship (that trevm MINOR == revm MAJOR) we will
41+
sometimes make breaking changes in patch versions. This is technically semver
42+
compliant pre-1.0, but will cause build breakage downstream for users of those
43+
features. We will take care to document breaking changes in patch releases
44+
via github release notes.
45+
4046
## Limitations
4147

4248
Trevm is a work in progress and is not feature complete. In particular, trevm

src/est.rs

+33-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ use std::ops::Range;
55
/// binary searching.
66
pub(crate) struct SearchRange(Range<u64>);
77

8+
impl core::fmt::Display for SearchRange {
9+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
10+
write!(f, "{}..{}", self.0.start, self.0.end)
11+
}
12+
}
13+
814
impl From<Range<u64>> for SearchRange {
915
fn from(value: Range<u64>) -> Self {
1016
Self(value)
@@ -25,7 +31,7 @@ impl SearchRange {
2531

2632
/// Calculate the midpoint of the search range.
2733
pub(crate) const fn midpoint(&self) -> u64 {
28-
(self.0.end - self.0.start) / 2
34+
(self.max() + self.min()) / 2
2935
}
3036

3137
/// Get the start of the search range.
@@ -38,6 +44,7 @@ impl SearchRange {
3844
self.0.start = min;
3945
}
4046

47+
/// Raise the minimum of the search range, if the candidate is higher.
4148
pub(crate) const fn maybe_raise_min(&mut self, candidate: u64) {
4249
if candidate > self.min() {
4350
self.set_min(candidate);
@@ -110,11 +117,33 @@ pub enum EstimationResult {
110117
},
111118
}
112119

113-
impl From<&ExecutionResult> for EstimationResult {
114-
fn from(value: &ExecutionResult) -> Self {
120+
impl core::fmt::Display for EstimationResult {
121+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
122+
match self {
123+
Self::Success { estimation, refund, gas_used, .. } => {
124+
write!(
125+
f,
126+
"Success {{ estimation: {}, refund: {}, gas_used: {}, .. }}",
127+
estimation, refund, gas_used
128+
)
129+
}
130+
Self::Revert { gas_used, .. } => {
131+
write!(f, "Revert {{ gas_used: {}, .. }}", gas_used)
132+
}
133+
Self::Halt { reason, gas_used } => {
134+
write!(f, "Halt {{ reason: {:?}, gas_used: {} }}", reason, gas_used)
135+
}
136+
}
137+
}
138+
}
139+
140+
impl EstimationResult {
141+
/// Initialize the estimation result from an execution result and the gas
142+
/// limit of the transaction that produced the estimation.
143+
pub fn from_limit_and_execution_result(limit: u64, value: &ExecutionResult) -> Self {
115144
match value {
116145
ExecutionResult::Success { gas_used, output, gas_refunded, .. } => Self::Success {
117-
estimation: *gas_used,
146+
estimation: limit,
118147
refund: *gas_refunded,
119148
gas_used: *gas_used,
120149
output: output.clone(),
@@ -127,9 +156,7 @@ impl From<&ExecutionResult> for EstimationResult {
127156
}
128157
}
129158
}
130-
}
131159

132-
impl EstimationResult {
133160
/// Create a successful estimation result with a gas estimation of 21000.
134161
pub const fn basic_transfer_success(estimation: u64) -> Self {
135162
Self::Success {

0 commit comments

Comments
 (0)