Skip to content
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

Cache Keccak Hashes per SignedTx #2544

Merged
merged 9 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/ain-evm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl From<&LegacyTransaction> for LegacyUnsignedTransaction {
pub struct SignedTx {
pub transaction: TransactionV2,
pub sender: H160,
hash_cache: Cell<Option<H256>>,
prasannavl marked this conversation as resolved.
Show resolved Hide resolved
}

impl fmt::Debug for SignedTx {
Expand Down Expand Up @@ -179,6 +180,7 @@ impl TryFrom<TransactionV2> for SignedTx {
Ok(SignedTx {
transaction: src,
sender: public_key_to_address(&pubkey),
hash_cache: Cell::new(None),
})
prasannavl marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down Expand Up @@ -317,11 +319,16 @@ impl SignedTx {
}

pub fn hash(&self) -> H256 {
match &self.transaction {
TransactionV2::Legacy(tx) => tx.hash(),
TransactionV2::EIP2930(tx) => tx.hash(),
TransactionV2::EIP1559(tx) => tx.hash(),
let h = &self.hash_cache;
if h.get().is_none() {
let val = match &self.transaction {
TransactionV2::Legacy(tx) => tx.hash(),
TransactionV2::EIP2930(tx) => tx.hash(),
TransactionV2::EIP1559(tx) => tx.hash(),
};
h.set(Some(val));
}
h.get().unwrap()
prasannavl marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn get_tx_type(&self) -> U256 {
Expand All @@ -330,6 +337,7 @@ impl SignedTx {
}

use std::{
cell::Cell,
cmp::min,
convert::{TryFrom, TryInto},
fmt,
Expand Down
8 changes: 5 additions & 3 deletions test/functional/interface_http_cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def run_test(self):
self.test_json_rpc_port()
self.test_eth_json_rpc_port()


def test_json_rpc_port(self):
url = urllib.parse.urlparse(self.nodes[0].url)
authpair = url.username + ":" + url.password
Expand Down Expand Up @@ -71,7 +70,9 @@ def test_eth_json_rpc_port(self):
assert_equal(res.status, http.client.OK)
res.close()

def check_cors_headers(self, res, check_allow_methods=True, check_allow_headers=True):
def check_cors_headers(
self, res, check_allow_methods=True, check_allow_headers=True
):
assert_equal(res.getheader("Access-Control-Allow-Origin"), self.cors_origin)
assert_equal(res.getheader("Access-Control-Allow-Credentials"), "true")
if check_allow_methods:
Expand All @@ -80,7 +81,8 @@ def check_cors_headers(self, res, check_allow_methods=True, check_allow_headers=
)
if check_allow_headers:
assert_equal(
res.getheader("Access-Control-Allow-Headers"), "Content-Type, Authorization"
res.getheader("Access-Control-Allow-Headers"),
"Content-Type, Authorization",
)


Expand Down