Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/edr/main' into rethnet/improveme…
Browse files Browse the repository at this point in the history
…nt/less-clones
  • Loading branch information
Wodann committed Nov 14, 2023
2 parents 21ed72b + 7d25b1b commit 8bfe51a
Show file tree
Hide file tree
Showing 102 changed files with 708 additions and 134 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/edr-npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
runs-on: ${{ matrix.settings.host }}
defaults:
run:
working-directory: ./crates/edr_evm_napi
working-directory: ./crates/edr_napi
steps:
- uses: actions/checkout@v3
- name: Setup node
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: "--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build/crates/edr_evm_napi"
options: "--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build/crates/edr_napi"
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
Expand All @@ -156,7 +156,7 @@ jobs:
name: bindings-${{ matrix.settings.target }}
# The upload artifact action doesn't respect the working directory setting. Unclear if this is a bug or not
# https://github.com/actions/upload-artifact/issues/294
path: ./crates/edr_evm_napi/${{ env.APP_NAME }}.*.node
path: ./crates/edr_napi/${{ env.APP_NAME }}.*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
Expand All @@ -176,7 +176,7 @@ jobs:
runs-on: ${{ matrix.settings.host }}
defaults:
run:
working-directory: ./crates/edr_evm_napi
working-directory: ./crates/edr_napi
steps:
- uses: actions/checkout@v3
- name: Setup node
Expand All @@ -191,7 +191,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: ./crates/edr_evm_napi/
path: ./crates/edr_napi/
- name: List packages
run: ls -R .
shell: bash
Expand Down Expand Up @@ -222,12 +222,12 @@ jobs:
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-unknown-linux-gnu
path: ./crates/edr_evm_napi/
path: ./crates/edr_napi/
- name: List packages
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build/crates/edr_evm_napi node:${{ matrix.node }}-slim yarn test
run: docker run --rm -v $(pwd):/build -w /build/crates/edr_napi node:${{ matrix.node }}-slim yarn test
test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -255,12 +255,12 @@ jobs:
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-unknown-linux-musl
path: ./crates/edr_evm_napi/
path: ./crates/edr_napi/
- name: List packages
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build/crates/edr_evm_napi node:${{ matrix.node }}-alpine yarn test
run: docker run --rm -v $(pwd):/build -w /build/crates/edr_napi node:${{ matrix.node }}-alpine yarn test
test-linux-aarch64-gnu-binding:
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
needs:
Expand All @@ -278,7 +278,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: bindings-aarch64-unknown-linux-gnu
path: ./crates/edr_evm_napi/
path: ./crates/edr_napi/
- name: List packages
run: ls -R .
shell: bash
Expand All @@ -296,7 +296,7 @@ jobs:
uses: addnab/docker-run-action@v3
with:
image: node:${{ matrix.node }}-slim
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build/crates/edr_evm_napi"
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build/crates/edr_napi"
run: |
set -e
yarn test
Expand All @@ -312,7 +312,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: bindings-aarch64-unknown-linux-musl
path: ./crates/edr_evm_napi/
path: ./crates/edr_napi/
- name: List packages
run: ls -R .
shell: bash
Expand All @@ -330,7 +330,7 @@ jobs:
uses: addnab/docker-run-action@v3
with:
image: node:lts-alpine
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build/crates/edr_evm_napi"
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build/crates/edr_napi"
run: |
set -e
yarn test
Expand Down Expand Up @@ -370,7 +370,7 @@ jobs:
if: ${{ needs.check_commit.outputs.match == 'true' }}
defaults:
run:
working-directory: ./crates/edr_evm_napi
working-directory: ./crates/edr_napi
steps:
- uses: actions/checkout@v3
- name: Setup node
Expand All @@ -384,7 +384,7 @@ jobs:
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: ./crates/edr_evm_napi/artifacts
path: ./crates/edr_napi/artifacts
- name: Move artifacts
run: yarn artifacts
- name: List packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hardhat-core-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
defaults:
run:
working-directory: crates/edr_evm_napi
working-directory: crates/edr_napi
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions book/src/02_development/03_local_release.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Local release

These are instructions for releasing the [EDR NPM package](../../crates/edr_evm_napi/package.json) locally for debugging purposes.
These are instructions for releasing the [EDR NPM package](../../crates/edr_napi/package.json) locally for debugging purposes.

1. Install and start [Verdaccio](./02_verdaccio.md).
2. Go to the [edr_evm_napi](../../crates/edr_evm_napi/) directory.
2. Go to the [edr_napi](../../crates/edr_napi/) directory.
3. Run `yarn build`.
4. Look for the NAPI binary that was built for your platform. It has the format `edr.<PLATFORM>.node`. For example on Apple Silicon Macs, it's called `edr.darwin-arm64.node`.
5. Move the NAPI binary to the appropriate platform-specifc package in the [npm](../../crates/edr_evm_napi/npm) directory. For example, on Apple Silicon Macs: `mv edr.darwin-arm64.node npm/darwin-arm64`.
6. Complete the Verdaccio [publish steps](./02_verdaccio.md#usage) in the [edr_evm_napi](../../crates/edr_evm_napi/) directory. You can ignore the warnings about not finding NAPI binaries for other platforms.
5. Move the NAPI binary to the appropriate platform-specifc package in the [npm](../../crates/edr_napi/npm) directory. For example, on Apple Silicon Macs: `mv edr.darwin-arm64.node npm/darwin-arm64`.
6. Complete the Verdaccio [publish steps](./02_verdaccio.md#usage) in the [edr_napi](../../crates/edr_napi/) directory. You can ignore the warnings about not finding NAPI binaries for other platforms.
4 changes: 2 additions & 2 deletions book/src/03_release.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release

Releasing the [EDR NPM package](../../crates/edr_evm_napi/package.json) is handled by the [EDR NPM release](../../.github/workflows/edr-npm-release.yml) GitHub Action workflow.
Releasing the [EDR NPM package](../../crates/edr_napi/package.json) is handled by the [EDR NPM release](../../.github/workflows/edr-npm-release.yml) GitHub Action workflow.

A new release is created automatically on commits to the `main` and `edr/main` branches that follow the following format: `edr-0.1.0` for releases or `edr-0.1.0-alpha.1` for pre-releases.

Prior to making such a commit, the version number in the [package.json](../../crates/edr_evm_napi/package.json) of the main package and the platform-specific packages in the [npm](../../crates/edr_evm_napi/npm) directory need to be manually adjusted.
Prior to making such a commit, the version number in the [package.json](../../crates/edr_napi/package.json) of the main package and the platform-specific packages in the [npm](../../crates/edr_napi/npm) directory need to be manually adjusted.
2 changes: 1 addition & 1 deletion crates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Make sure you have the following dependencies installed on your machine:
Use `npm` (or `yarn`) to build a release version:

```bash
cd crates/edr_evm_napi
cd crates/edr_napi
npm run build
# yarn build
```
Expand Down
6 changes: 6 additions & 0 deletions crates/edr_eth/src/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ impl From<Vec<AccessListItem>> for AccessList {
}
}

impl From<AccessList> for Vec<AccessListItem> {
fn from(src: AccessList) -> Vec<AccessListItem> {
src.0
}
}

/// Access list item
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(
Expand Down
21 changes: 13 additions & 8 deletions crates/edr_eth/src/remote/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ pub struct Transaction {
pub chain_id: Option<u64>,
/// integer of the transaction type, 0x0 for legacy transactions, 0x1 for
/// access list types, 0x2 for dynamic fees
#[serde(rename = "type", default, with = "crate::serde::u64")]
pub transaction_type: u64,
#[serde(
rename = "type",
default,
skip_serializing_if = "Option::is_none",
with = "crate::serde::optional_u64"
)]
pub transaction_type: Option<u64>,
/// access list
#[serde(default)]
pub access_list: Option<Vec<AccessListItem>>,
Expand Down Expand Up @@ -103,7 +108,7 @@ impl Transaction {

/// Returns whether the transaction is a legacy transaction.
pub fn is_legacy(&self) -> bool {
self.transaction_type == 0 && (self.v == 27 || self.v == 28)
self.transaction_type == Some(0) && (self.v == 27 || self.v == 28)
}
}

Expand Down Expand Up @@ -147,7 +152,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
};

let transaction = match value.transaction_type {
0 => {
Some(0) | None => {
if value.is_legacy() {
SignedTransaction::PreEip155Legacy(LegacySignedTransaction {
nonce: value.nonce,
Expand Down Expand Up @@ -180,7 +185,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
})
}
}
1 => SignedTransaction::Eip2930(Eip2930SignedTransaction {
Some(1) => SignedTransaction::Eip2930(Eip2930SignedTransaction {
odd_y_parity: value.odd_y_parity(),
chain_id: value
.chain_id
Expand All @@ -199,7 +204,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
s: value.s,
hash: OnceLock::from(value.hash),
}),
2 => SignedTransaction::Eip1559(Eip1559SignedTransaction {
Some(2) => SignedTransaction::Eip1559(Eip1559SignedTransaction {
odd_y_parity: value.odd_y_parity(),
chain_id: value
.chain_id
Expand All @@ -223,7 +228,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
s: value.s,
hash: OnceLock::from(value.hash),
}),
3 => SignedTransaction::Eip4844(Eip4844SignedTransaction {
Some(3) => SignedTransaction::Eip4844(Eip4844SignedTransaction {
odd_y_parity: value.odd_y_parity(),
chain_id: value
.chain_id
Expand Down Expand Up @@ -255,7 +260,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
s: value.s,
hash: OnceLock::from(value.hash),
}),
r#type => {
Some(r#type) => {
return Err(TransactionConversionError::UnsupportedType(r#type));
}
};
Expand Down
42 changes: 42 additions & 0 deletions crates/edr_eth/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ impl SignedTransaction {
}

/// Retrieves the max fee per gas of the transaction, if any.
pub fn max_fee_per_gas(&self) -> Option<U256> {
match self {
SignedTransaction::PreEip155Legacy(_)
| SignedTransaction::PostEip155Legacy(_)
| SignedTransaction::Eip2930(_) => None,
SignedTransaction::Eip1559(tx) => Some(tx.max_priority_fee_per_gas),
SignedTransaction::Eip4844(tx) => Some(tx.max_priority_fee_per_gas),
}
}

/// Retrieves the max priority fee per gas of the transaction, if any.
pub fn max_priority_fee_per_gas(&self) -> Option<U256> {
match self {
SignedTransaction::PreEip155Legacy(_)
Expand All @@ -104,6 +115,28 @@ impl SignedTransaction {
}
}

/// Retrieves the max fee per blob gas of the transaction, if any.
pub fn max_fee_per_blob_gas(&self) -> Option<U256> {
match self {
SignedTransaction::PreEip155Legacy(_)
| SignedTransaction::PostEip155Legacy(_)
| SignedTransaction::Eip2930(_)
| SignedTransaction::Eip1559(_) => None,
SignedTransaction::Eip4844(tx) => Some(tx.max_fee_per_blob_gas),
}
}

/// Retrieves the blob hashes of the transaction, if any.
pub fn blob_hashes(&self) -> Option<Vec<B256>> {
match self {
SignedTransaction::PreEip155Legacy(_)
| SignedTransaction::PostEip155Legacy(_)
| SignedTransaction::Eip2930(_)
| SignedTransaction::Eip1559(_) => None,
SignedTransaction::Eip4844(tx) => Some(tx.blob_hashes.clone()),
}
}

/// Upfront cost of the transaction
pub fn upfront_cost(&self) -> U256 {
self.max_cost().saturating_add(self.value())
Expand Down Expand Up @@ -208,6 +241,15 @@ impl SignedTransaction {
},
}
}

pub fn transaction_type(&self) -> u64 {
match self {
SignedTransaction::PreEip155Legacy(_) | SignedTransaction::PostEip155Legacy(_) => 0,
SignedTransaction::Eip2930(_) => 1,
SignedTransaction::Eip1559(_) => 2,
SignedTransaction::Eip4844(_) => 3,
}
}
}

impl rlp::Encodable for SignedTransaction {
Expand Down
5 changes: 5 additions & 0 deletions crates/edr_evm/src/transaction/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ impl PendingTransaction {
&self.caller
}

/// Returns the inner [`SignedTransaction`]
pub fn transaction(&self) -> &SignedTransaction {
&self.transaction
}

/// Returns the inner transaction and caller
pub fn into_inner(self) -> (SignedTransaction, Address) {
(self.transaction, self.caller)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "edr_evm_napi"
name = "edr_napi"
version = "0.2.0-dev"
edition = "2021"

Expand All @@ -17,6 +17,8 @@ napi-derive = "2.12.3"
edr_defaults = { version = "0.2.0-dev", path = "../edr_defaults" }
edr_evm = { version = "0.2.0-dev", path = "../edr_evm" }
edr_eth = { version = "0.2.0-dev", path = "../edr_eth" }
edr_provider = { version = "0.2.0-dev", path = "../edr_provider" }
edr_rpc_hardhat = {version = "0.2.0-dev", path = "../edr_rpc_hardhat" }
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] }
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
tracing-flame = { version = "0.2.0", default-features = false, features = ["smallvec"] }
Expand Down
File renamed without changes.
Loading

0 comments on commit 8bfe51a

Please sign in to comment.